From d2359427474da7e7796047eeb31259e6fede4a60 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Tue, 28 Oct 2025 13:03:21 -0700 Subject: [PATCH 1/2] De-matrix Android triples Building for multiple ABIs at once is something the swift-build frontend does for macOS and should eventually do for other platforms. Don't "lift" the triple into a new matrix axis. This also renames the android_sdk_triple and android_ndk_version properties to plurals, since they support multiple versions. This is breaking, but the Android workflow is only a couple of days old, so this should be fine. --- .../scripts/install-and-build-with-sdk.sh | 35 +++++++++++-------- .github/workflows/swift_package_test.yml | 15 ++++---- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/scripts/install-and-build-with-sdk.sh b/.github/workflows/scripts/install-and-build-with-sdk.sh index e942ecf..c334744 100644 --- a/.github/workflows/scripts/install-and-build-with-sdk.sh +++ b/.github/workflows/scripts/install-and-build-with-sdk.sh @@ -25,6 +25,7 @@ BUILD_EMBEDDED_WASM=false SWIFT_VERSION_INPUT="" SWIFT_BUILD_FLAGS="" SWIFT_BUILD_COMMAND="swift build" +ANDROID_SDK_TRIPLES=() while [[ $# -gt 0 ]]; do case $1 in @@ -37,7 +38,7 @@ while [[ $# -gt 0 ]]; do shift ;; --android-sdk-triple=*) - ANDROID_SDK_TRIPLE="${1#*=}" + ANDROID_SDK_TRIPLES+=("${1#*=}") shift ;; --static) @@ -660,23 +661,27 @@ build() { local sdk_name="${ANDROID_SDK_TAG}${ANDROID_SDK_PATH_SEP}android${ANDROID_SDK_PATH_SUFFIX}" alias swift='$SWIFT_EXECUTABLE_FOR_ANDROID_SDK' - local build_command="$SWIFT_BUILD_COMMAND --swift-sdk ${ANDROID_SDK_TRIPLE:-$sdk_name}" - if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then - build_command="$build_command $SWIFT_BUILD_FLAGS" - fi - log "Running: $build_command" + # This can become a single invocation in the future when `swift build` supports multiple Android triples at once + for android_sdk_triple in "${ANDROID_SDK_TRIPLES[@]}" ; do + local build_command="$SWIFT_BUILD_COMMAND --swift-sdk ${android_sdk_triple}" + if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then + build_command="$build_command $SWIFT_BUILD_FLAGS" + fi - # clear the ANDROID_NDK_ROOT environment variable if it is set - # due to https://github.com/swiftlang/swift-driver/pull/1879 - # otherwise build error: missing required module 'SwiftAndroid' - export ANDROID_NDK_ROOT="" + log "Running: $build_command" - if eval "$build_command"; then - log "✅ Swift build with Android Swift SDK completed successfully" - else - fatal "Swift build with Android Swift SDK failed" - fi + # clear the ANDROID_NDK_ROOT environment variable if it is set + # due to https://github.com/swiftlang/swift-driver/pull/1879 + # otherwise build error: missing required module 'SwiftAndroid' + export ANDROID_NDK_ROOT="" + + if eval "$build_command"; then + log "✅ Swift build with Android Swift SDK completed successfully" + else + fatal "Swift build with Android Swift SDK failed" + fi + done fi if [[ "$INSTALL_STATIC_LINUX" == true ]]; then diff --git a/.github/workflows/swift_package_test.yml b/.github/workflows/swift_package_test.yml index 4b915fe..ac0c52a 100644 --- a/.github/workflows/swift_package_test.yml +++ b/.github/workflows/swift_package_test.yml @@ -139,13 +139,13 @@ on: type: string description: "Command to use when building the package with the Swift SDK for Android" default: "swift build" - android_sdk_triple: + android_sdk_triples: type: string - description: "The triple to use when building with the Swift SDK for Android" - default: "[\"x86_64-unknown-linux-android28\"]" - android_ndk_version: + description: "The triples to use when building with the Swift SDK for Android" + default: "[\"aarch64-unknown-linux-android28\", \"x86_64-unknown-linux-android28\"]" + android_ndk_versions: type: string - description: "The NDK version to use when building with the Swift SDK for Android" + description: "The NDK versions to use when building with the Swift SDK for Android" default: "[\"r27d\"]" windows_pre_build_command: type: string @@ -511,8 +511,7 @@ jobs: fail-fast: false matrix: swift_version: ${{ fromJson(inputs.android_sdk_versions) }} - sdk_triple: ${{ fromJson(inputs.android_sdk_triple) }} - ndk_version: ${{ fromJson(inputs.android_ndk_version) }} + ndk_version: ${{ fromJson(inputs.android_ndk_versions) }} os_version: ${{ fromJson(inputs.linux_os_versions) }} exclude: - ${{ fromJson(inputs.android_exclude_swift_versions) }} @@ -560,7 +559,7 @@ jobs: exit 1 fi curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \ - bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple="${{ matrix.sdk_triple }}" --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }} + bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }} --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }} windows-build: name: Windows (${{ matrix.swift_version }} - windows-2022) From 1eba3bf21d78e60b5d374a0be5601e439a421102 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Tue, 28 Oct 2025 14:27:39 -0700 Subject: [PATCH 2/2] Always use the current version of the Android script --- .github/workflows/swift_package_test.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/swift_package_test.yml b/.github/workflows/swift_package_test.yml index ac0c52a..c86c42d 100644 --- a/.github/workflows/swift_package_test.yml +++ b/.github/workflows/swift_package_test.yml @@ -528,6 +528,26 @@ jobs: - name: Checkout repository uses: actions/checkout@v1 if: ${{ matrix.os_version == 'amazonlinux2' }} + - name: Checkout swiftlang/github-workflows repository + if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }} + uses: actions/checkout@v4 + with: + repository: swiftlang/github-workflows + path: github-workflows + - name: Checkout swiftlang/github-workflows repository + if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }} + uses: actions/checkout@v1 + with: + repository: swiftlang/github-workflows + path: github-workflows + - name: Determine script-root path + id: script_path + run: | + if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then + echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT + else + echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT + fi - name: Provide token if: ${{ inputs.needs_token }} run: | @@ -558,7 +578,7 @@ jobs: echo "Unknown package manager (tried apt-get, dnf, yum)" >&2 exit 1 fi - curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \ + cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \ bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }} --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }} windows-build: