Skip to content

Commit a24771a

Browse files
authored
Fix the Android CI workflow by adding a post-install step the configure the SDK (#3424)
Fixes the Android CI workflow ### Motivation: The recently-added Android SDK workflow [fails](https://github.com/apple/swift-nio/actions/runs/18718487605/job/53384086329?pr=3418) (as mentioned at #3418 (comment)). The confusing error message is due to a post-install step that is needed to download and link the Android NDK into the Swift SDK's artifactbundle. This PR also adds a one-line fix to [Sources/NIOPerformanceTester/main.swift](main...swift-android-sdk:swift-nio:main#diff-de179adbbfacb89c9533f4efd21f7f641eedc0c8642d7d650cdfc9d9278a7a55) that gets it building for Android so the entire swift-nio package can be built. ### Modifications: Adds a post-install step to the SDK installation that is needed for the Swift SDK for Android. This is the same technique used by swiftlang/github-workflows#172, and is described as a necessary step in the [Android getting started guide](https://github.com/swiftlang/swift-org-website/blob/0dc655ce267e7b6bada2a2032cc7855c3b5e19d9/documentation/articles/swift-android-getting-started.md) ### Result: The "Android Swift SDK" CI check should now pass successfully. See an example at https://github.com/swift-android-sdk/swift-nio/actions/runs/18761057590/job/53525442382 ### Note: This PR will _not_ pass the Android check until it has been merged, because it relies on being able to down the the script https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh from `apple/swift-nio/main`, which will not include the Android fix until the PR is merged. But once it is merged, the Android SDK CI should start passing.
1 parent ec26755 commit a24771a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ jobs:
7575
name: Android Swift SDK
7676
# Workaround https://github.com/nektos/act/issues/1875
7777
uses: apple/swift-nio/.github/workflows/android_sdk.yml@main
78-
with:
79-
additional_command_arguments: "--target NIOCore"
8078

8179
macos-tests:
8280
name: macOS tests

.github/workflows/pull_request.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ jobs:
109109
name: Android Swift SDK
110110
# Workaround https://github.com/nektos/act/issues/1875
111111
uses: apple/swift-nio/.github/workflows/android_sdk.yml@main
112-
with:
113-
additional_command_arguments: "--target NIOCore"
114112

115113
release-builds:
116114
name: Release builds

Sources/NIOPerformanceTester/main.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ import NIOCore
2828
import NIOEmbedded
2929
import NIOFoundationCompat
3030
import NIOHTTP1
31+
#if os(Android)
32+
// workaround for error: reference to var 'stdout' is not concurrency-safe because it involves shared mutable state
33+
@preconcurrency import NIOPosix
34+
#else
3135
import NIOPosix
36+
#endif
3237
import NIOWebSocket
3338

3439
// Use unbuffered stdout to help detect exactly which test was running in the event of a crash.

scripts/install_swift_sdk.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ version="${INSTALL_SWIFT_VERSION:=""}"
2525
arch="${INSTALL_SWIFT_ARCH:="aarch64"}"
2626
os_image="${INSTALL_SWIFT_OS_IMAGE:="ubuntu22.04"}"
2727
sdk="${INSTALL_SWIFT_SDK:="static-sdk"}"
28+
android_ndk_version="${INSTALL_ANDROID_NDK:="r27d"}"
2829

2930
if [[ ! ( -n "$branch" && -z "$version" ) && ! ( -z "$branch" && -n "$version") ]]; then
3031
fatal "Exactly one of build or version must be defined."
@@ -127,3 +128,20 @@ swift --version
127128

128129
log "Installing Swift SDK"
129130
swift sdk install "$sdk_path"
131+
132+
log "Swift SDK Post-install"
133+
if [[ "$sdk" == "android-sdk" ]]; then
134+
# guess some common places where the swift-sdks folder lives
135+
cd ~/Library/org.swift.swiftpm || cd ~/.config/swiftpm || cd ~/.local/swiftpm || cd ~/.swiftpm || cd /root/.swiftpm || fatal "Cannot locate swiftpm config directory"
136+
137+
# download and link the NDK
138+
android_ndk_url="https://dl.google.com/android/repository/android-ndk-${android_ndk_version}-$(uname -s).zip"
139+
log "Android Native Development Kit URL: ${android_ndk_url}"
140+
"$CURL_BIN" -fsSL -o ndk.zip --retry 3 "${android_ndk_url}"
141+
unzip -q ndk.zip
142+
rm ndk.zip
143+
export ANDROID_NDK_HOME="${PWD}/android-ndk-${android_ndk_version}"
144+
bundledir=$(find . -type d -maxdepth 2 -name '*android*.artifactbundle' | head -n 1)
145+
"${bundledir}"/swift-android/scripts/setup-android-sdk.sh
146+
cd - || fatal "Cannot cd back to previous directory"
147+
fi

0 commit comments

Comments
 (0)