Skip to content

Commit 26548d7

Browse files
Improve Android SDK build configuration
- Change default build command to use 'swift build' instead of 'swift build --build-system native' (the 4/27 snapshot contains the requisite changes for Android) - Use the correct host toolchain for Android build/test - Add mention of the specific host SDK being used to build For Wasm, we want to wait until swiftlang/swift-build#1348 lands before unpinning. Co-authored-by: Marc Prud'hommeaux <mwp1@cornell.edu>
1 parent 3280fe0 commit 26548d7

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
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

@@ -122,7 +132,7 @@ STAGING_DIR="swift-android-test"
122132
rm -rf "${STAGING_DIR}"
123133
mkdir "${STAGING_DIR}"
124134

125-
BUILD_DIR=.build/"${ANDROID_SDK_TRIPLE}"/debug
135+
BUILD_DIR=$(swift build --show-bin-path --swift-sdk "${ANDROID_SDK_TRIPLE}")
126136

127137
find "${BUILD_DIR}" -name '*.xctest' -exec cp -av {} "${STAGING_DIR}" \;
128138
find "${BUILD_DIR}" -name '*.resources' -exec cp -av {} "${STAGING_DIR}" \;

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

Lines changed: 25 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

@@ -783,6 +803,8 @@ build() {
783803

784804
if [[ "$INSTALL_ANDROID" == true ]]; then
785805
log "Running Swift build with Android Swift SDK"
806+
log "Host toolchain for Android build: ${SWIFT_EXECUTABLE_FOR_ANDROID_SDK}"
807+
"$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" --version || true
786808

787809
local sdk_name="${ANDROID_SDK_TAG}${ANDROID_SDK_PATH_SEP}android"
788810

.github/workflows/swift_package_test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ on:
171171
android_sdk_build_command:
172172
type: string
173173
description: "Command to use when building the package with the Swift SDK for Android"
174-
# Temporarily use native build system on Android due to https://github.com/swiftlang/swift/issues/88282
175-
default: "swift build --build-system native"
174+
default: "swift build"
176175
android_sdk_triples:
177176
type: string
178177
description: "The triples to use when building with the Swift SDK for Android. The final triple in the list will be used for the emulator testing and should match the host architecture."
@@ -673,10 +672,8 @@ jobs:
673672
exclude:
674673
- ${{ fromJson(inputs.android_exclude_swift_versions) }}
675674
steps:
676-
- name: Swift version
677-
run: swift --version
678-
- name: Clang version
679-
run: clang --version
675+
- name: Remove Swift
676+
run: rm -f $(which swift || true)
680677
- name: Checkout repository
681678
uses: actions/checkout@v4
682679
- name: Checkout swiftlang/github-workflows repository

0 commit comments

Comments
 (0)