diff --git a/.github/workflows/scripts/android/android-emulator-tests.sh b/.github/workflows/scripts/android/android-emulator-tests.sh index 1cd32a30..559cd38e 100755 --- a/.github/workflows/scripts/android/android-emulator-tests.sh +++ b/.github/workflows/scripts/android/android-emulator-tests.sh @@ -21,8 +21,18 @@ ANDROID_PROFILE="Nexus 10" ANDROID_EMULATOR_TIMEOUT=300 SWIFTPM_HOME="${XDG_CONFIG_HOME}"/swiftpm +# Prefer the bundle name exported by install-and-build-with-sdk.sh so that we +# pick the SDK matching the requested swift_version (release, snapshot, or main), +# rather than whichever happens to sort last on disk. # e.g., "${SWIFTPM_HOME}"/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-12-11-a_android.artifactbundle/ -SWIFT_ANDROID_SDK_HOME=$(find "${SWIFTPM_HOME}"/swift-sdks -maxdepth 1 -name 'swift-*android.artifactbundle' | tail -n 1) +if [[ -n "${SWIFT_ANDROID_SDK_BUNDLE:-}" ]]; then + SWIFT_ANDROID_SDK_HOME="${SWIFTPM_HOME}/swift-sdks/${SWIFT_ANDROID_SDK_BUNDLE}" + if [[ ! -d "${SWIFT_ANDROID_SDK_HOME}" ]]; then + fatal "Android Swift SDK bundle not found at: ${SWIFT_ANDROID_SDK_HOME}" + fi +else + SWIFT_ANDROID_SDK_HOME=$(find "${SWIFTPM_HOME}"/swift-sdks -maxdepth 1 -name 'swift-*android.artifactbundle' | tail -n 1) +fi ANDROID_SDK_TRIPLE="x86_64-unknown-linux-android28" @@ -122,7 +132,7 @@ STAGING_DIR="swift-android-test" rm -rf "${STAGING_DIR}" mkdir "${STAGING_DIR}" -BUILD_DIR=.build/"${ANDROID_SDK_TRIPLE}"/debug +BUILD_DIR=$(swift build --show-bin-path --swift-sdk "${ANDROID_SDK_TRIPLE}") find "${BUILD_DIR}" -name '*.xctest' -exec cp -av {} "${STAGING_DIR}" \; find "${BUILD_DIR}" -name '*.resources' -exec cp -av {} "${STAGING_DIR}" \; diff --git a/.github/workflows/scripts/install-and-build-with-sdk.sh b/.github/workflows/scripts/install-and-build-with-sdk.sh index e18b6451..ec7b2701 100755 --- a/.github/workflows/scripts/install-and-build-with-sdk.sh +++ b/.github/workflows/scripts/install-and-build-with-sdk.sh @@ -412,6 +412,16 @@ if [[ "$INSTALL_ANDROID" == true && -z "$ANDROID_SDK_TAG" ]]; then fatal "ANDROID_SDK_TAG is not set but Android Swift SDK installation was requested" fi +# Export the resolved Android SDK tag so subsequent workflow steps +# (e.g. android-emulator-tests.sh) pick the same SDK we just installed +# rather than guessing via 'find ... | tail -n 1' +if [[ "$INSTALL_ANDROID" == true && -n "${GITHUB_ENV:-}" ]]; then + { + echo "SWIFT_ANDROID_SDK_TAG=${ANDROID_SDK_TAG}" + echo "SWIFT_ANDROID_SDK_BUNDLE=${ANDROID_SDK_TAG}_android.artifactbundle" + } >> "$GITHUB_ENV" +fi + if [[ "$INSTALL_STATIC_LINUX" == true && -z "$STATIC_LINUX_SDK_TAG" ]]; then fatal "STATIC_LINUX_SDK_TAG is not set but Static Linux Swift SDK installation was requested" fi @@ -687,8 +697,14 @@ install_android_sdk() { rm -f "${sdk_url}" - # now setup the link to the local ANDROID_NDK_HOME - swift sdk configure --show-configuration "$(swift sdk list | grep android | tail -n 1)" + # now setup the link to the local ANDROID_NDK_HOME, using the matched + # toolchain so its sdk subcommand and config files agree with what we just installed + local installed_sdk_name + installed_sdk_name=$("$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk list | grep "^${ANDROID_SDK_TAG}.*android" | tail -n 1) + if [[ -z "$installed_sdk_name" ]]; then + fatal "Could not find newly installed Android Swift SDK matching tag ${ANDROID_SDK_TAG}" + fi + "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk configure --show-configuration "$installed_sdk_name" # guess some common places where the swift-sdks file lives cd ~/Library/org.swift.swiftpm || cd ~/.config/swiftpm || cd ~/.local/swiftpm || cd ~/.swiftpm || cd /root/.swiftpm @@ -717,7 +733,11 @@ install_android_sdk() { fi fi - ./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh + # run the bundled setup script with the matched toolchain in front of PATH + # so any 'swift' it invokes resolves to the version that matches the SDK + local toolchain_bin_dir + toolchain_bin_dir="$(dirname "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK")" + PATH="${toolchain_bin_dir}:${PATH}" ./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh cd - } @@ -783,6 +803,8 @@ build() { if [[ "$INSTALL_ANDROID" == true ]]; then log "Running Swift build with Android Swift SDK" + log "Host toolchain for Android build: ${SWIFT_EXECUTABLE_FOR_ANDROID_SDK}" + "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" --version || true local sdk_name="${ANDROID_SDK_TAG}${ANDROID_SDK_PATH_SEP}android" diff --git a/.github/workflows/swift_package_test.yml b/.github/workflows/swift_package_test.yml index 6c29d825..438e7bc8 100644 --- a/.github/workflows/swift_package_test.yml +++ b/.github/workflows/swift_package_test.yml @@ -171,8 +171,7 @@ on: android_sdk_build_command: type: string description: "Command to use when building the package with the Swift SDK for Android" - # Temporarily use native build system on Android due to https://github.com/swiftlang/swift/issues/88282 - default: "swift build --build-system native" + default: "swift build" android_sdk_triples: type: string 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: exclude: - ${{ fromJson(inputs.android_exclude_swift_versions) }} steps: - - name: Swift version - run: swift --version - - name: Clang version - run: clang --version + - name: Remove Swift + run: rm -f $(which swift || true) - name: Checkout repository uses: actions/checkout@v4 - name: Checkout swiftlang/github-workflows repository