From 80901f20404ee93f6616416ee8923682307b9ab4 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 28 Apr 2025 16:28:54 -0400 Subject: [PATCH 01/20] Swift Android build 6.2 --- swift-ci/sdks/android/build | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/swift-ci/sdks/android/build b/swift-ci/sdks/android/build index e35bd431..107752c6 100755 --- a/swift-ci/sdks/android/build +++ b/swift-ci/sdks/android/build @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -ex # Swift Android SDK: Top-level Build Script # default architectures to build for @@ -13,12 +13,28 @@ mkdir -p ${SDKROOT} # Install a Swift host toolchain if it isn't already present SWIFT_ROOT=${SDKROOT}/host-toolchain HOST_OS=ubuntu$(lsb_release -sr) -SWIFT_VERSION=6.1 -SWIFT_TAG="swift-${SWIFT_VERSION}-RELEASE" -SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-release" + +#BUILD_VERSION='release' +#BUILD_VERSION='trunk' +BUILD_VERSION=${BUILD_VERSION:-'devel'} + +if [ "${BUILD_VERSION}" = 'release' ]; then + LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-6.1 | cut -d- -f2) + SWIFT_TAG="swift-${LATEST_TOOLCHAIN_VERSION}-RELEASE" + SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-release" +elif [ "${BUILD_VERSION}" = 'devel' ]; then + LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/tags | grep -m1 swift-6.2-DEV | cut -d- -f8-10) + SWIFT_TAG="swift-6.2-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a" + SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-branch" +else + LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/tags | grep -m1 swift-DEV | cut -d- -f7-9) + SWIFT_TAG="swift-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a" + SWIFT_BRANCH="development" +fi + SWIFT_BASE=$SWIFT_TAG-$HOST_OS -if [[ ! -d $SWIFT_ROOT ]]; then +if [[ ! -d "$SWIFT_ROOT/$SWIFT_BASE" ]]; then mkdir -p $SWIFT_ROOT pushd $SWIFT_ROOT @@ -75,7 +91,11 @@ if [[ ! -d ${PATCHDIR} ]]; then # swift-android-ci.patch is not needed, since it is only used for llbuild, etc. #git apply -C1 $PATCHDIR/swift-android-ci.patch #git apply -v $PATCHDIR/swift-android-ci-release.patch - git apply -v $PATCHDIR/swift-android-testing-release.patch + if [ "${BUILD_VERSION}" = 'release' ]; then + git apply -v $PATCHDIR/swift-android-testing-release.patch + else + git apply -v $PATCHDIR/swift-android-testing-except-release.patch + fi perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift # disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport) From a705d0943823630a6d72f3c756fc02e3a7da90f0 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 28 Apr 2025 17:15:47 -0400 Subject: [PATCH 02/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 7 ++++--- swift-ci/sdks/static-linux/build | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ed578bc6..60ff6459 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -40,9 +40,10 @@ jobs: # blank arch builds all (aarch64,x86_64,armv7) #arch: [''] # builds only x86_64 to speed up the validation - #arch: ['x86_64'] + arch: ['x86_64'] # build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs - arch: ['x86_64', ''] + #arch: ['x86_64', ''] + swift-version: ['release', 'devel', 'trunk'] runs-on: ubuntu-24.04 steps: - name: Checkout repository @@ -53,7 +54,7 @@ jobs: - name: Build Android SDK working-directory: swift-ci/sdks/android run: | - TARGET_ARCHS=${{ matrix.arch }} ./build + BUILD_VERSION=${{ matrix.swift-version }} TARGET_ARCHS=${{ matrix.arch }} ./build - name: Get artifact info id: info shell: bash diff --git a/swift-ci/sdks/static-linux/build b/swift-ci/sdks/static-linux/build index 6e984960..4c9d21ec 100755 --- a/swift-ci/sdks/static-linux/build +++ b/swift-ci/sdks/static-linux/build @@ -35,7 +35,9 @@ esac $DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX -t static-swift-linux . # Check-out the sources -scripts/fetch-source.sh --clone-with-ssh --source-dir source +# disabled --clone-with-ssh for fork CI which doesn't have the keys +scripts/fetch-source.sh --source-dir source +#scripts/fetch-source.sh --clone-with-ssh --source-dir source mkdir -p products From 39a36268dc250b3d017b68617c4a047f29d709b2 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 28 Apr 2025 19:21:53 -0400 Subject: [PATCH 03/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 6 +++++- swift-ci/sdks/static-linux/build | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 60ff6459..f80f5f2e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -8,6 +8,8 @@ env: jobs: build: name: Build Docker images + # disabled for CI testing + if: false runs-on: ubuntu-latest steps: - name: Checkout repository @@ -24,6 +26,8 @@ jobs: static-linux-build: name: Build Static Linux image + # disabled for CI testing + if: false runs-on: ubuntu-latest steps: - name: Checkout repository @@ -33,7 +37,7 @@ jobs: run: ./build android-build: - name: Build Android ${{ matrix.arch }} SDK + name: Build Android ${{ matrix.swift-version }} ${{ matrix.arch }} SDK strategy: fail-fast: false matrix: diff --git a/swift-ci/sdks/static-linux/build b/swift-ci/sdks/static-linux/build index 4c9d21ec..6e984960 100755 --- a/swift-ci/sdks/static-linux/build +++ b/swift-ci/sdks/static-linux/build @@ -35,9 +35,7 @@ esac $DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX -t static-swift-linux . # Check-out the sources -# disabled --clone-with-ssh for fork CI which doesn't have the keys -scripts/fetch-source.sh --source-dir source -#scripts/fetch-source.sh --clone-with-ssh --source-dir source +scripts/fetch-source.sh --clone-with-ssh --source-dir source mkdir -p products From e113f82ada79188a913fb32b8a5cf8f6e3ff6281 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 00:59:11 -0400 Subject: [PATCH 04/20] Start splitting NDK out from the rest of the SDK --- swift-ci/sdks/android/scripts/build.sh | 96 +++++++++++++++++++------- 1 file changed, 71 insertions(+), 25 deletions(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 843ff2db..452413b7 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -1,6 +1,10 @@ #!/bin/bash # Swift SDK for Android: Build Script -set -e +set -ex + +# temporary for splitting out NDK installation from the rest of the SDK +#NDK_LOCATION=${NDK_LOCATION:-"merged"} +NDK_LOCATION=${NDK_LOCATION:-"external"} # Docker sets TERM to xterm if using a pty; we probably want # xterm-256color, otherwise we only get eight colors @@ -212,14 +216,14 @@ header "Swift Android SDK build script" swift_dir=$(realpath $(dirname "$swiftc")/..) HOST=linux-x86_64 #HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-') -ndk_toolchain=$ndk_home/toolchains/llvm/prebuilt/$HOST +ndk_installation=$ndk_home/toolchains/llvm/prebuilt/$HOST echo "Swift found at ${swift_dir}" echo "Host toolchain found at ${host_toolchain}" ${host_toolchain}/bin/swift --version echo "Android NDK found at ${ndk_home}" -${ndk_toolchain}/bin/clang --version +${ndk_installation}/bin/clang --version echo "Building for ${archs}" echo "Sources are in ${source_dir}" echo "Build will happen in ${build_dir}" @@ -387,7 +391,7 @@ for arch in $archs; do # need to remove symlink that gets created in the NDK to the previous arch's build # or else we get errors like: # error: could not find module '_Builtin_float' for target 'x86_64-unknown-linux-android'; found: aarch64-unknown-linux-android, at: /home/runner/work/_temp/swift-android-sdk/ndk/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/swift/android/_Builtin_float.swiftmodule - rm -f $ndk_toolchain/sysroot/usr/lib/swift + rm -f $ndk_installation/sysroot/usr/lib/swift quiet_popd groupend done @@ -425,12 +429,27 @@ EOF mkdir -p $sdk_base quiet_pushd $sdk_base -#sysroot_path="ndk-sysroot" -#sysroot_path="android-27c-sysroot" -sysroot_path="sysroot" -cp -a ${ndk_toolchain}/sysroot ${sysroot_path} +cp -a ${build_dir}/sdk_root ${sdk_staging} + +if [ "${NDK_LOCATION}" = "external" ]; then + swift_res_root="swift-resources" + #ndk_sysroot=${ndk_installation}/sysroot + #ndk_sysroot=NONE + ndk_sysroot="ndk-sysroot" + cp -a ${ndk_installation}/sysroot ${ndk_sysroot} +else + #sysroot_path="ndk-sysroot" + #sysroot_path="android-27c-sysroot" + merged_sysroot_path="sysroot" + + swift_res_root=${merged_sysroot_path} + ndk_sysroot=${merged_sysroot_path} + cp -a ${ndk_installation}/sysroot ${ndk_sysroot} +fi + +mkdir -p ${swift_res_root} -cat > $sysroot_path/SDKSettings.json < $swift_res_root/SDKSettings.json < $sysroot_path/SDKSettings.json < swift-sdk.json <> swift-sdk.json < Date: Tue, 29 Apr 2025 01:00:02 -0400 Subject: [PATCH 05/20] Start splitting NDK out from the rest of the SDK --- .github/workflows/pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f80f5f2e..bf6dc546 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -44,9 +44,9 @@ jobs: # blank arch builds all (aarch64,x86_64,armv7) #arch: [''] # builds only x86_64 to speed up the validation - arch: ['x86_64'] + #arch: ['x86_64'] # build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs - #arch: ['x86_64', ''] + arch: ['x86_64', ''] swift-version: ['release', 'devel', 'trunk'] runs-on: ubuntu-24.04 steps: From bd3a0ea459f98c7ba87750728ed4ac50408db10e Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 07:19:18 -0400 Subject: [PATCH 06/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 38 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bf6dc546..f9345033 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -87,28 +87,30 @@ jobs: # swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT + tree ${ARTIFACT_BUILD}/ + # validate some required paths in the artifactbundle - pushd ${ARTIFACT_BUILD}/*/*/usr - ls lib/swift/android - ls lib/swift/android/* - ls lib/swift/android/*/swiftrt.o - ls lib/*-linux-android/*/crtbegin_dynamic.o + #pushd ${ARTIFACT_BUILD}/*/*/usr + #ls lib/swift/android + #ls lib/swift/android/* + #ls lib/swift/android/*/swiftrt.o + #ls lib/*-linux-android/*/crtbegin_dynamic.o - ls lib/swift_static-* - ls lib/swift_static-*/android - ls lib/swift_static-*/android/libFoundationEssentials.a + #ls lib/swift_static-* + #ls lib/swift_static-*/android + #ls lib/swift_static-*/android/libFoundationEssentials.a - ls lib/*-linux-android/libFoundationEssentials.so - ls lib/*-linux-android/libFoundationNetworking.so - ls lib/*-linux-android/libFoundationInternationalization.so - ls lib/*-linux-android/lib_FoundationICU.so - ls lib/*-linux-android/libFoundationXML.so - ls lib/*-linux-android/libTesting.so + #ls lib/*-linux-android/libFoundationEssentials.so + #ls lib/*-linux-android/libFoundationNetworking.so + #ls lib/*-linux-android/libFoundationInternationalization.so + #ls lib/*-linux-android/lib_FoundationICU.so + #ls lib/*-linux-android/libFoundationXML.so + #ls lib/*-linux-android/libTesting.so - ls lib/swift/clang/lib - ls lib/swift/clang/lib/linux - ls lib/swift/clang/lib/linux/*/libunwind.a - popd + #ls lib/swift/clang/lib + #ls lib/swift/clang/lib/linux + #ls lib/swift/clang/lib/linux/*/libunwind.a + #popd - name: Upload SDK artifactbundle uses: actions/upload-artifact@v4 with: From f38f3e61cc6626a029599cdfc1a8e9ac2ac9e6e6 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 10:14:59 -0400 Subject: [PATCH 07/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 6 +++--- swift-ci/sdks/android/scripts/build.sh | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f9345033..8ea6939c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -145,10 +145,10 @@ jobs: echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift echo 'import Android' >> Sources/DemoProject/DemoProject.swift - name: Test Demo Project on Android - uses: skiptools/swift-android-action@v2 + uses: skiptools/swift-android-action@main with: # only test for the complete arch SDK build to speed up CI - run-tests: ${{ matrix.arch == '' }} + #run-tests: ${{ matrix.arch == '' }} package-path: ${{ runner.temp }}/DemoProject installed-sdk: ${{ steps.info.outputs.sdk-id }} installed-swift: ${{ steps.info.outputs.swift-root }} @@ -159,7 +159,7 @@ jobs: repository: apple/swift-algorithms path: swift-algorithms - name: Test swift-algorithms - uses: skiptools/swift-android-action@v2 + uses: skiptools/swift-android-action@main with: run-tests: ${{ matrix.arch == '' }} package-path: swift-algorithms diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 452413b7..5360f9c3 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -500,14 +500,20 @@ if [ "${NDK_LOCATION}" = "external" ]; then # need to manually copy over swiftrt.o or else: # error: link command failed with exit code 1 (use -v to see invocation) # clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a_android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o' - SWIFTRT=${swift_res_root}/usr/lib/swift-x86_64/android/x86_64/swiftrt.o - # see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807 - mkdir -p ${ndk_sysroot}/usr/lib/swift/android/x86_64 - cp -v ${SWIFTRT} ${ndk_sysroot}/usr/lib/swift/android/x86_64/swiftrt.o + if [ "true" = "true" ]; then + SWIFTRT=android/x86_64/swiftrt.o + + mkdir -p ${ndk_sysroot}/usr/lib/swift/android/x86_64 + ln -srv ${swift_res_root}/usr/lib/swift-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift/${SWIFTRT} - mkdir -p ${ndk_sysroot}/usr/lib/swift_static/android/x86_64 - cp -v ${SWIFTRT} ${ndk_sysroot}/usr/lib/swift_static/android/x86_64/swiftrt.o + mkdir -p ${ndk_sysroot}/usr/lib/swift_static/android/x86_64 + #ln -srv ${swift_res_root}/usr/lib/swift_static-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift_static/${SWIFTRT} + else + # try brute copying swiftrt.o to EVERY directory to see if it gets picked up somehow + echo "Seeking workaround for swiftrt.o needing to be under sdkRoot" + #find ${swift_res_root} -type d -exec cp -av ${SWIFTRT} {} \; + fi else rm -r ${swift_res_root}/usr/{include,lib}/{i686,riscv64}-linux-android rm -r ${swift_res_root}/usr/lib/swift/clang/lib/linux/*{i[36]86,riscv64}* @@ -542,14 +548,17 @@ EOF else SWIFT_RES_DIR="swift" fi + SWIFT_STATIC_RES_DIR="swift_static-${arch}" cat >> swift-sdk.json < Date: Tue, 29 Apr 2025 11:47:22 -0400 Subject: [PATCH 08/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8ea6939c..8cde3793 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -87,7 +87,9 @@ jobs: # swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT - tree ${ARTIFACT_BUILD}/ + #tree ${ARTIFACT_BUILD}/ + # show an abridged tree + tree ${ARTIFACT_BUILD} --filesfirst --prune -P 'Android.swiftmodule' -P 'libswiftAndroid.*' -P 'libFoundation.*' -P 'swiftrt.o' -P 'swift*.json' -P 'info.json' -P 'api-level.h' -P 'android.modulemap' -P 'SwiftAndroidNDK.h' -P 'bridging.modulemap' # validate some required paths in the artifactbundle #pushd ${ARTIFACT_BUILD}/*/*/usr From da07685b82487c9ea2b4774c799f2e52cb35e4ef Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 14:15:32 -0400 Subject: [PATCH 09/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 5360f9c3..f8c25031 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -462,6 +462,7 @@ EOF mkdir -p $swift_res_root/usr/lib/swift/clang/lib cp -r $host_toolchain/lib/clang/*/include $swift_res_root/usr/lib/swift/clang + for arch in $archs; do quiet_pushd ${sdk_staging}/${arch}/usr rm -r bin @@ -503,12 +504,8 @@ if [ "${NDK_LOCATION}" = "external" ]; then # see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807 if [ "true" = "true" ]; then SWIFTRT=android/x86_64/swiftrt.o - mkdir -p ${ndk_sysroot}/usr/lib/swift/android/x86_64 ln -srv ${swift_res_root}/usr/lib/swift-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift/${SWIFTRT} - - mkdir -p ${ndk_sysroot}/usr/lib/swift_static/android/x86_64 - #ln -srv ${swift_res_root}/usr/lib/swift_static-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift_static/${SWIFTRT} else # try brute copying swiftrt.o to EVERY directory to see if it gets picked up somehow echo "Seeking workaround for swiftrt.o needing to be under sdkRoot" From 70938b781837dc720a4b035e1089edbbe485ac71 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 16:14:32 -0400 Subject: [PATCH 10/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index f8c25031..fd9a6fd8 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -192,7 +192,7 @@ if [[ $swift_version == swift-* ]]; then fi if [[ -z "$sdk_name" ]]; then - sdk_name=swift-${swift_version}_android-${android_sdk_version} + sdk_name=swift-${swift_version}-android-${android_sdk_version} fi libxml2_version=$(versionFromTag ${source_dir}/libxml2) @@ -500,9 +500,9 @@ done if [ "${NDK_LOCATION}" = "external" ]; then # need to manually copy over swiftrt.o or else: # error: link command failed with exit code 1 (use -v to see invocation) - # clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a_android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o' + # clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a-android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o' # see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807 - if [ "true" = "true" ]; then + if [ "${NDK_LOCATION}" = "external" ]; then SWIFTRT=android/x86_64/swiftrt.o mkdir -p ${ndk_sysroot}/usr/lib/swift/android/x86_64 ln -srv ${swift_res_root}/usr/lib/swift-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift/${SWIFTRT} From 829bce625ddb16c656a92e38429a415ae6c35cb9 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 17:03:26 -0400 Subject: [PATCH 11/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index fd9a6fd8..0ef12b60 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -218,7 +218,6 @@ HOST=linux-x86_64 #HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-') ndk_installation=$ndk_home/toolchains/llvm/prebuilt/$HOST - echo "Swift found at ${swift_dir}" echo "Host toolchain found at ${host_toolchain}" ${host_toolchain}/bin/swift --version From c6e8f24c91483a7801e7733b6674f36f2181d44c Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 19:51:19 -0400 Subject: [PATCH 12/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8cde3793..ae0d4e50 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -50,6 +50,24 @@ jobs: swift-version: ['release', 'devel', 'trunk'] runs-on: ubuntu-24.04 steps: + free-disk-space: + runs-on: ubuntu-latest + steps: + # need to free up some space or we can run out when building + - name: Free Disk Space + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: false + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true - name: Checkout repository uses: actions/checkout@v4 - name: Install Dependencies @@ -122,7 +140,9 @@ jobs: - name: Cleanup run: | # need to free up some space or else when installing we get: No space left on device + df -h rm -rf ${{ runner.temp }}/swift-android-sdk/{build,src} + df -h - name: Install artifactbundle shell: bash run: | From 38d2a536bf7d20a053c1b65ea5caa646bfdda823 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 20:27:09 -0400 Subject: [PATCH 13/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ae0d4e50..4f24bcc5 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -50,9 +50,6 @@ jobs: swift-version: ['release', 'devel', 'trunk'] runs-on: ubuntu-24.04 steps: - free-disk-space: - runs-on: ubuntu-latest - steps: # need to free up some space or we can run out when building - name: Free Disk Space uses: jlumbroso/free-disk-space@main From 6607e2cf6c32980de9ec079c43a44d0bb761da9c Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 21:06:05 -0400 Subject: [PATCH 14/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4f24bcc5..35c127a8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -50,21 +50,13 @@ jobs: swift-version: ['release', 'devel', 'trunk'] runs-on: ubuntu-24.04 steps: - # need to free up some space or we can run out when building - name: Free Disk Space - uses: jlumbroso/free-disk-space@main - with: - # this might remove tools that are actually needed, - # if set to "true" but frees about 6 GB - tool-cache: false - # all of these default to true, but feel free to set to - # "false" if necessary for your workflow - android: true - dotnet: true - haskell: true - large-packages: true - docker-images: true - swap-storage: true + run: | + df -h + sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL + sudo docker image prune --all --force + sudo docker builder prune -a + df -h - name: Checkout repository uses: actions/checkout@v4 - name: Install Dependencies From 5582607107c17e9d9e70eea5d1fceb51a33632a0 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 29 Apr 2025 23:00:34 -0400 Subject: [PATCH 15/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 35c127a8..54916422 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -51,8 +51,10 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Free Disk Space + if: false run: | df -h + # brings available space from 25G to 42G sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL sudo docker image prune --all --force sudo docker builder prune -a From e97f4c04beefc2fa89e6adfa400fa25b3dadc07f Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 30 Apr 2025 09:01:38 -0400 Subject: [PATCH 16/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 54916422..030cce4c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -51,11 +51,12 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Free Disk Space - if: false run: | df -h # brings available space from 25G to 42G - sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL + #sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL + sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL + df -h sudo docker image prune --all --force sudo docker builder prune -a df -h From 48e255ce8d25197996b3b844674081c713cdad63 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 30 Apr 2025 09:50:02 -0400 Subject: [PATCH 17/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 0ef12b60..fd9a6fd8 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -218,6 +218,7 @@ HOST=linux-x86_64 #HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-') ndk_installation=$ndk_home/toolchains/llvm/prebuilt/$HOST + echo "Swift found at ${swift_dir}" echo "Host toolchain found at ${host_toolchain}" ${host_toolchain}/bin/swift --version From 6ac3365b31e68bc0e5332ebe4005ca4c305f936e Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 30 Apr 2025 10:43:02 -0400 Subject: [PATCH 18/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index fd9a6fd8..b8736a76 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -218,7 +218,6 @@ HOST=linux-x86_64 #HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-') ndk_installation=$ndk_home/toolchains/llvm/prebuilt/$HOST - echo "Swift found at ${swift_dir}" echo "Host toolchain found at ${host_toolchain}" ${host_toolchain}/bin/swift --version @@ -503,9 +502,10 @@ if [ "${NDK_LOCATION}" = "external" ]; then # clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a-android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o' # see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807 if [ "${NDK_LOCATION}" = "external" ]; then - SWIFTRT=android/x86_64/swiftrt.o - mkdir -p ${ndk_sysroot}/usr/lib/swift/android/x86_64 - ln -srv ${swift_res_root}/usr/lib/swift-x86_64/${SWIFTRT} ${ndk_sysroot}/usr/lib/swift/${SWIFTRT} + for arch in $archs; do + mkdir -p ${ndk_sysroot}/usr/lib/swift/android/${arch} + ln -srv ${swift_res_root}/usr/lib/swift-${arch}/android/${arch}/swiftrt.o ${ndk_sysroot}/usr/lib/swift/android/${arch}/swiftrt.o + done else # try brute copying swiftrt.o to EVERY directory to see if it gets picked up somehow echo "Seeking workaround for swiftrt.o needing to be under sdkRoot" From 41e50a22c45c5abf4391079330da7480fc99ddff Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 30 Apr 2025 12:56:50 -0400 Subject: [PATCH 19/20] Swift Android build 6.2 --- swift-ci/sdks/android/scripts/build.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index b8736a76..89c480b9 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -487,9 +487,15 @@ for arch in $archs; do mv lib/swift_static lib/swift_static-$arch mv lib/lib*.a lib/swift_static-$arch/android - mkdir -p lib/swift/clang/lib - cp -a ${ndk_installation}/lib/clang/*/lib/linux lib/swift/clang/lib - ln -s ../swift/clang lib/swift_static-$arch/clang + ln -sv ../swift/clang lib/swift_static-$arch/clang + + # copy the clang libraries that we need to build for each architecture + aarch=${arch/armv7/arm} + mkdir -p lib/swift/clang/lib/linux/${aarch} + + # match clang version 21, 22, etc. + cp -av ${ndk_installation}/lib/clang/[0-9]*/lib/linux/libclang_rt.builtins-${aarch}-android.a lib/swift/clang/lib/linux/ + cp -av ${ndk_installation}/lib/clang/[0-9]*/lib/linux/${aarch}/libunwind.a lib/swift/clang/lib/linux/${aarch}/ quiet_popd # now sync the massaged sdk_root into the swift_res_root From d9755ebbe4744459611c1816eb90d2dab3941394 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Wed, 30 Apr 2025 16:50:18 -0400 Subject: [PATCH 20/20] Swift Android build 6.2 --- .github/workflows/pull_request.yml | 31 +++----------------------- swift-ci/sdks/android/build | 2 +- swift-ci/sdks/android/scripts/build.sh | 19 ++++------------ 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 030cce4c..582b2b9b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -53,10 +53,9 @@ jobs: - name: Free Disk Space run: | df -h - # brings available space from 25G to 42G - #sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL + # brings available space from 25G to 32G + # otherwise we sometimes run out of space during the build sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL - df -h sudo docker image prune --all --force sudo docker builder prune -a df -h @@ -97,32 +96,8 @@ jobs: # swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT - #tree ${ARTIFACT_BUILD}/ # show an abridged tree - tree ${ARTIFACT_BUILD} --filesfirst --prune -P 'Android.swiftmodule' -P 'libswiftAndroid.*' -P 'libFoundation.*' -P 'swiftrt.o' -P 'swift*.json' -P 'info.json' -P 'api-level.h' -P 'android.modulemap' -P 'SwiftAndroidNDK.h' -P 'bridging.modulemap' - - # validate some required paths in the artifactbundle - #pushd ${ARTIFACT_BUILD}/*/*/usr - #ls lib/swift/android - #ls lib/swift/android/* - #ls lib/swift/android/*/swiftrt.o - #ls lib/*-linux-android/*/crtbegin_dynamic.o - - #ls lib/swift_static-* - #ls lib/swift_static-*/android - #ls lib/swift_static-*/android/libFoundationEssentials.a - - #ls lib/*-linux-android/libFoundationEssentials.so - #ls lib/*-linux-android/libFoundationNetworking.so - #ls lib/*-linux-android/libFoundationInternationalization.so - #ls lib/*-linux-android/lib_FoundationICU.so - #ls lib/*-linux-android/libFoundationXML.so - #ls lib/*-linux-android/libTesting.so - - #ls lib/swift/clang/lib - #ls lib/swift/clang/lib/linux - #ls lib/swift/clang/lib/linux/*/libunwind.a - #popd + tree ${ARTIFACT_BUILD} --filesfirst --prune -P 'Android.swiftmodule' -P 'libswiftAndroid.*' -P 'libFoundation.*' -P 'swiftrt.o' -P 'swift*.json' -P 'info.json' -P 'api-level.h' -P 'android.modulemap' -P 'SwiftAndroidNDK.h' -P 'bridging.modulemap' -P 'linux' -P 'libclang*.a' -P 'libunwind.a' -P 'libclang_rt.builtins-*-android.a' - name: Upload SDK artifactbundle uses: actions/upload-artifact@v4 with: diff --git a/swift-ci/sdks/android/build b/swift-ci/sdks/android/build index 107752c6..20b9fce0 100755 --- a/swift-ci/sdks/android/build +++ b/swift-ci/sdks/android/build @@ -1,4 +1,4 @@ -#!/bin/bash -ex +#!/bin/bash -e # Swift Android SDK: Top-level Build Script # default architectures to build for diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 89c480b9..a592b2b4 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -432,15 +432,10 @@ cp -a ${build_dir}/sdk_root ${sdk_staging} if [ "${NDK_LOCATION}" = "external" ]; then swift_res_root="swift-resources" - #ndk_sysroot=${ndk_installation}/sysroot - #ndk_sysroot=NONE ndk_sysroot="ndk-sysroot" cp -a ${ndk_installation}/sysroot ${ndk_sysroot} else - #sysroot_path="ndk-sysroot" - #sysroot_path="android-27c-sysroot" merged_sysroot_path="sysroot" - swift_res_root=${merged_sysroot_path} ndk_sysroot=${merged_sysroot_path} cp -a ${ndk_installation}/sysroot ${ndk_sysroot} @@ -507,16 +502,10 @@ if [ "${NDK_LOCATION}" = "external" ]; then # error: link command failed with exit code 1 (use -v to see invocation) # clang: error: no such file or directory: '${HOME}/.swiftpm/swift-sdks/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a-android-0.1.artifactbundle/swift-android/ndk-sysroot/usr/lib/swift/android/x86_64/swiftrt.o' # see: https://github.com/swiftlang/swift-driver/pull/1822#issuecomment-2762811807 - if [ "${NDK_LOCATION}" = "external" ]; then - for arch in $archs; do - mkdir -p ${ndk_sysroot}/usr/lib/swift/android/${arch} - ln -srv ${swift_res_root}/usr/lib/swift-${arch}/android/${arch}/swiftrt.o ${ndk_sysroot}/usr/lib/swift/android/${arch}/swiftrt.o - done - else - # try brute copying swiftrt.o to EVERY directory to see if it gets picked up somehow - echo "Seeking workaround for swiftrt.o needing to be under sdkRoot" - #find ${swift_res_root} -type d -exec cp -av ${SWIFTRT} {} \; - fi + for arch in $archs; do + mkdir -p ${ndk_sysroot}/usr/lib/swift/android/${arch} + ln -srv ${swift_res_root}/usr/lib/swift-${arch}/android/${arch}/swiftrt.o ${ndk_sysroot}/usr/lib/swift/android/${arch}/swiftrt.o + done else rm -r ${swift_res_root}/usr/{include,lib}/{i686,riscv64}-linux-android rm -r ${swift_res_root}/usr/lib/swift/clang/lib/linux/*{i[36]86,riscv64}*