Skip to content

Commit 3a614d3

Browse files
committed
Use the correct host toolchain for Android build/test
1 parent 3280fe0 commit 3a614d3

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

.github/workflows/scripts/android/android-emulator-tests.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@ ANDROID_PROFILE="Nexus 10"
2121
ANDROID_EMULATOR_TIMEOUT=300
2222

2323
SWIFTPM_HOME="${XDG_CONFIG_HOME}"/swiftpm
24+
# Prefer the bundle name exported by install-and-build-with-sdk.sh so that we
25+
# pick the SDK matching the requested swift_version (release, snapshot, or main),
26+
# rather than whichever happens to sort last on disk.
2427
# e.g., "${SWIFTPM_HOME}"/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-12-11-a_android.artifactbundle/
25-
SWIFT_ANDROID_SDK_HOME=$(find "${SWIFTPM_HOME}"/swift-sdks -maxdepth 1 -name 'swift-*android.artifactbundle' | tail -n 1)
28+
if [[ -n "${SWIFT_ANDROID_SDK_BUNDLE:-}" ]]; then
29+
SWIFT_ANDROID_SDK_HOME="${SWIFTPM_HOME}/swift-sdks/${SWIFT_ANDROID_SDK_BUNDLE}"
30+
if [[ ! -d "${SWIFT_ANDROID_SDK_HOME}" ]]; then
31+
fatal "Android Swift SDK bundle not found at: ${SWIFT_ANDROID_SDK_HOME}"
32+
fi
33+
else
34+
SWIFT_ANDROID_SDK_HOME=$(find "${SWIFTPM_HOME}"/swift-sdks -maxdepth 1 -name 'swift-*android.artifactbundle' | tail -n 1)
35+
fi
2636

2737
ANDROID_SDK_TRIPLE="x86_64-unknown-linux-android28"
2838

.github/workflows/scripts/install-and-build-with-sdk.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ if [[ "$INSTALL_ANDROID" == true && -z "$ANDROID_SDK_TAG" ]]; then
412412
fatal "ANDROID_SDK_TAG is not set but Android Swift SDK installation was requested"
413413
fi
414414

415+
# Export the resolved Android SDK tag so subsequent workflow steps
416+
# (e.g. android-emulator-tests.sh) pick the same SDK we just installed
417+
# rather than guessing via 'find ... | tail -n 1'
418+
if [[ "$INSTALL_ANDROID" == true && -n "${GITHUB_ENV:-}" ]]; then
419+
{
420+
echo "SWIFT_ANDROID_SDK_TAG=${ANDROID_SDK_TAG}"
421+
echo "SWIFT_ANDROID_SDK_BUNDLE=${ANDROID_SDK_TAG}_android.artifactbundle"
422+
} >> "$GITHUB_ENV"
423+
fi
424+
415425
if [[ "$INSTALL_STATIC_LINUX" == true && -z "$STATIC_LINUX_SDK_TAG" ]]; then
416426
fatal "STATIC_LINUX_SDK_TAG is not set but Static Linux Swift SDK installation was requested"
417427
fi
@@ -687,8 +697,14 @@ install_android_sdk() {
687697

688698
rm -f "${sdk_url}"
689699

690-
# now setup the link to the local ANDROID_NDK_HOME
691-
swift sdk configure --show-configuration "$(swift sdk list | grep android | tail -n 1)"
700+
# now setup the link to the local ANDROID_NDK_HOME, using the matched
701+
# toolchain so its sdk subcommand and config files agree with what we just installed
702+
local installed_sdk_name
703+
installed_sdk_name=$("$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk list | grep "^${ANDROID_SDK_TAG}.*android" | tail -n 1)
704+
if [[ -z "$installed_sdk_name" ]]; then
705+
fatal "Could not find newly installed Android Swift SDK matching tag ${ANDROID_SDK_TAG}"
706+
fi
707+
"$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk configure --show-configuration "$installed_sdk_name"
692708

693709
# guess some common places where the swift-sdks file lives
694710
cd ~/Library/org.swift.swiftpm || cd ~/.config/swiftpm || cd ~/.local/swiftpm || cd ~/.swiftpm || cd /root/.swiftpm
@@ -717,7 +733,11 @@ install_android_sdk() {
717733
fi
718734
fi
719735

720-
./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh
736+
# run the bundled setup script with the matched toolchain in front of PATH
737+
# so any 'swift' it invokes resolves to the version that matches the SDK
738+
local toolchain_bin_dir
739+
toolchain_bin_dir="$(dirname "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK")"
740+
PATH="${toolchain_bin_dir}:${PATH}" ./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh
721741
cd -
722742
}
723743

0 commit comments

Comments
 (0)