From 5a565d02cf87e6760bc1061f0f1fac25e63d3346 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 1 Nov 2025 10:08:02 -0400 Subject: [PATCH] Android API 23 (#16) * Add Android workflow * Build Android image (#1) * Build Android image * Checkout without ssh * Retry build if it fails * Swift 6.1 Release Dockerfiles (#456) * Change binutils-gold package dependency on Debian 12 to binutils (#457) * Update installed packages after nightly platform expansion (#458) * update nightly-6.1 dependencies * update nightly-main dependencies * fix ubuntu images * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Fedora 41 Dockerfile (#464) * Build Android image * Build Android image * Swift 6.1 Release Dockerfiles (#456) * Change binutils-gold package dependency on Debian 12 to binutils (#457) * Build Android image * Build Android image * Build Android image * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Android SDK build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Androd build * Swift Android build * Swift Android build * Swift Android build * Swift Android build --------- Co-authored-by: Mishal Shah Co-authored-by: Chris McGee <87777443+cmcgee1024@users.noreply.github.com> Co-authored-by: Justice Adams <107649528+justice-adams-apple@users.noreply.github.com> Co-authored-by: Andrew Sukach <134116196+sookach@users.noreply.github.com> * Swift Android build 6.2 (#2) * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Start splitting NDK out from the rest of the SDK * Start splitting NDK out from the rest of the SDK * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 * Swift Android build 6.2 (#3) * Swift Android build 6.2 * Swift Android build 6.2 * Add post-install script to SDK bundle * Add post-install script to SDK bundle * Add post-install script to SDK bundle * Add post-install script to SDK bundle * Build SDK in Docker container (#4) * Add static libraries to post-install script * Add post-install script to SDK bundle * Add post-install script to SDK bundle * Update submodules * Checkout patches repo instead of using a git submodule * Update libcurl to 8.13.0 * Remove resources that we no longer use * Update libcurl to 8.13.0 * Update libxml2 to 2.14.2 * Build libxml2, libcurl, and boringssl with support for Android 16kb page sizes * Add build-script --extra-cmake-options=-DCMAKE_EXTRA_LINK_FLAGS=-Wl,-z,max-page-size=16384 * Add 16KB page size linker flags to linker flags in swift-toolset.json * Add 16KB page size linker flags to linker flags in swift-toolset.json * Build with ndk-r28b * Revert to building with ndk-r27c * Use official endpoints for discovering latest Swift release/devel/trunk tags * Typo fix in version script * Cleanup for PR * Change BUILD_VERSION to BUILD_SCHEME and have it match release, swift-*-branch, or development * Update Android README * Update how patches are applied * Fix source directory for patch target * Harmonize timestamps in artifactbundle with the swift source tag date for build reproducibility * Simplify toolchain-vars.sh * Run the compiler validation suite for Android (#8) * Run the compiler validation suite for Android * Add --build-compiler option * Add --cross-compile-build-swift-tools=0 from https://github.com/swiftlang/swift/pull/38441 * Build with --build-llvm=0 * Check out Yams for Swift 6.1.1 build * Add --llvm-ninja-targets-for-cross-compile-hosts=help * Install pre-requisites * Install build prerequisites * Only setup local toolchain if build-compiler is not 0 * Fix Yams version checkout * Quote arguments to build scripts * Permit empty host-toolchain argument in build.sh * Fix check for BUILD_COMPILER * Re-order Docker PATH to system clang is used before Swift toolchain clang * Use --host-test to skip attempt to test on connected device/emulator * Install clang in Dockerfile * Add --skip-test-linux flag to build * Remove more folders to free up space * Update patches * Add docker-specific CI variants that run the compiler validation tests * meaningless edit * Update pull_request.yml to stop the 6.1 release builds * Update pull_request.yml to really only build the full docker compiler with tests * Update README.md with meaningless edit to bump build * Update build.sh to skip testing XCTest for linux, as a handful of the linux tests fail for some reason * Update build.sh to disable building libTesting and for 16K memory pages, as both don't work yet * Update build.sh to skip testing Foundation for linux, which requires building SwiftPM from source first * Update build.sh to not build each arch in a separate build directory * Update Dockerfile to use clang 19 instead * Add self-hosted runner CI variant * Fix CI workflow syntax * Update CI runner config * Update CI runner config * Fix name of self-hosted CI runner * Re-order arch run sequence * Update CI for self-hosted runner * Build for self-hosted runner * Add swift-6.2-branch to self-hosted run matrix * Update build.sh to disable aarch64 temporarily, as we know it built fine * Update pull_request.yml to disable non-compiler builds, as they all work, and comment out self-hosted till we know armv7 works * Run compiler validation on self-hosted with increased timeout * Update build-docker to only build for armv7 * Update pull_request.yml to disable self-hosted builds temporarily * Update pull_request.yml to build the full compiler in github runners with the armv7 stdlib and tests * Update build-docker to build for aarch64 first * Update toolchain-vars.sh to use older trunk snapahot toolchain that didn't crash * Update toolchain-vars.sh to only download the latest release compiler if building the Swift compiler from source * Update build-docker to only build for armv7 again * Update toolchain-vars.sh to fix setting branch variable * Update build-docker to build for all three supported arches * Update pull_request.yml to try self-hosted runs again * Update build.sh to only install SDK components and remove linux stdlib * Tolerate missing linux folder when attempting to clean up unnecessary build artifacts * Fix extraCLIOptions in swift-toolset.json * gcpdw * Fix patch application * Update apply-patches.sh to remove unused changes * Update swift-android-testing-except-release.patch to add Testing fix * Update swift-android.patch to remove unneeded patches * Update build.sh to try and fix Testing and clean up the bundle more * Fix README.md --------- Co-authored-by: finagolfin * Build compiler-validated bundles from latest branch commits, not older tags Also update patches, particularly to disable failing tests from the compiler validation suite * gcpd 'Update patches' * Update patches and build matrix * Disable compiler validated builds on self-hosted * Centralize cmake variable for 6.2 in patches, as done for trunk upstream * Update disabled tests * Try running Docker build on macOS host * Remove separate checks of libxml2, curl, and yams * Remove upstreamed 6.2 branch patches * Use command-line flags to work around CMake 3.30+ linker flag bug, rather than patching files * Create an Android CMake toolchain file instead to cross-compile Testing and add 16 KB page linker flag to 6.2 branch * Install the native host LLVM tools for full compiler builds * Extend `--cross-compile-build-swift-tools=False` to disable building and installing LLVM and the Testing macros for cross-compiled hosts, then enable building and using the Testing macros for the native host. * Don't copy any libraries from the NDK: link the NDK's clang resource directory in the post-install script instead * Wildcard the clang version link in the post-install script in order to accomodate NDK 27 and 28 * Switch generated shell header to use #!/usr/bin/env bash * SBOM and nits (#14) * Address nits * Eliminate unnecessaryt pushds and use run cmake install instead of ninja * Generate SBOM with SDK dependencies * Add example of command for building locally * Remove upstreamed patches and turn the last modifications into perl substitutions instead. * Remove self-hosted build on github CI * Remove android_build job from pull_request workflow * Add license headers to Android build scripts * Remove unnecessary .gitignore * Add license header to Dockerfile * Switch over to using explicit tags and branches when invoking build-docker/local Also, force the full Swift compiler to be built from source when building from a branch, since there are no existing toolchain builds of arbitrary commits that we can download. * Fix build script arguments to use false instead of False due to true_false not handling the capitalized form * Build swift-6.2-RELEASE * Apply patch from https://github.com/swiftlang/swift/pull/84061 for 6.2.0 Android SDK release * Update patch application for 6.2 * Change 6.2 to perform local build * Change 6.2 to perform local build on ubuntu-24.04 * Switch back to building 6.2 from a tag * Switch back to building 6.2 from a tag * Switch back to building 6.2 from a tag * Build the Swift 6.2 release self-hosted with compiler validation * Set minimum Android API to 24 * Build against swift-DEVELOPMENT-SNAPSHOT-2025-10-16- * Disable building libxml2 tests to handle missing glob function in Android 24 * Disable building libxml2 tests to handle missing glob function in Android 24 * Build this PR without compiler validation * Build this PR without compiler validation * Disable posix_spawnattr_ for Android 24 * Reduce Android API from 24 to 23 * Restore Android minimum API to 24 * Add swift-nio to tests cases being run * Reduce Android API from 24 to 23 * Try building swift-collections * Try testing against emulator API level 23 * Fix backtrace call * Fail with an error for posix_spawn * Fix error for posix_spawn * Remove temporary swift-docker Android build workflow --------- Co-authored-by: Mishal Shah Co-authored-by: Chris McGee <87777443+cmcgee1024@users.noreply.github.com> Co-authored-by: Justice Adams <107649528+justice-adams-apple@users.noreply.github.com> Co-authored-by: Andrew Sukach <134116196+sookach@users.noreply.github.com> Co-authored-by: finagolfin --- swift-ci/sdks/android/README.md | 2 +- swift-ci/sdks/android/build-docker | 12 -------- swift-ci/sdks/android/build-local | 11 ------- swift-ci/sdks/android/scripts/build.sh | 4 +-- swift-ci/sdks/android/scripts/fetch-source.sh | 29 +++++++++++++++++++ .../sdks/android/scripts/toolchain-vars.sh | 4 +-- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/swift-ci/sdks/android/README.md b/swift-ci/sdks/android/README.md index 238803a0..947cfaa2 100644 --- a/swift-ci/sdks/android/README.md +++ b/swift-ci/sdks/android/README.md @@ -41,7 +41,7 @@ which will build the sources for each of the specified architectures and then combines the SDKs into a single artifactbundle with targetTriples for each of the supported architectures (`aarch64`, `x86_64`, `aarmv7`) -and Android API levels (28-35). +and Android API levels (23-35). ## Specifying Architectures diff --git a/swift-ci/sdks/android/build-docker b/swift-ci/sdks/android/build-docker index 3b88952c..8424aeee 100755 --- a/swift-ci/sdks/android/build-docker +++ b/swift-ci/sdks/android/build-docker @@ -18,7 +18,6 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7} ANDROID_NDK_VERSION=android-ndk-r27d -ANDROID_API=28 BASEPATH=$(dirname $(realpath $0)) cd ${BASEPATH} @@ -39,16 +38,6 @@ source ./scripts/toolchain-vars.sh # Check-out and patch the sources ./scripts/fetch-source.sh --source-dir ${WORKDIR}/source -# This `git grep` invocation in a trunk test fails in our Docker for some -# reason, so just turn it into a plain `grep` again. -perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh - -# Work around swiftlang/swift-driver#1822 for now -perl -pi -g -we "s#(call rm ... \".\{LIBDISPATCH_BUILD_DIR\}\"\n(\s+)fi\n)#\1\2if [[ -d \"\\\${ANDROID_NDK}\" ]]; then call ln -sf \"\\\${SWIFT_BUILD_PATH}/lib/swift\" \"\\\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib\"; fi#" ${WORKDIR}/source/swift-project/swift/utils/build-script-impl - -# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport) -perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift - mkdir -p ${WORKDIR}/products chmod ugo+rwx ${WORKDIR}/products @@ -70,6 +59,5 @@ $DOCKER run -i --rm \ --products-dir "/products" \ --host-toolchain "/usr/local/swift" \ --build-compiler "${BUILD_COMPILER}" \ - --android-api "${ANDROID_API}" \ --ndk-home "/usr/local/ndk/${ANDROID_NDK_VERSION}" \ --archs "${TARGET_ARCHS}" diff --git a/swift-ci/sdks/android/build-local b/swift-ci/sdks/android/build-local index b5f078c5..43bd0c27 100755 --- a/swift-ci/sdks/android/build-local +++ b/swift-ci/sdks/android/build-local @@ -18,7 +18,6 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7} ANDROID_NDK_VERSION=android-ndk-r27d -ANDROID_API=28 BASEPATH=$(dirname $(realpath $0)) cd ${BASEPATH} @@ -61,15 +60,6 @@ fi # Check-out and patch the sources ./scripts/fetch-source.sh --source-dir ${WORKDIR}/source -# This `git grep` invocation in a trunk test fails in our Docker for some -# reason, so just turn it into a plain `grep` again. -perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh - -# Work around swiftlang/swift-driver#1822 for now -perl -pi -g -we "s#(call rm ... \".\{LIBDISPATCH_BUILD_DIR\}\"\n(\s+)fi\n)#\1\2if [[ -d \"\\\${ANDROID_NDK}\" ]]; then call ln -sf \"\\\${SWIFT_BUILD_PATH}/lib/swift\" \"\\\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib\"; fi#" ${WORKDIR}/source/swift-project/swift/utils/build-script-impl - -# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport) -perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift mkdir -p ${WORKDIR}/products @@ -79,6 +69,5 @@ mkdir -p ${WORKDIR}/products --build-dir "${WORKDIR}/build" \ --build-compiler "${BUILD_COMPILER}" \ --host-toolchain "${HOST_TOOLCHAIN}" \ - --android-api "${ANDROID_API}" \ --ndk-home "${ANDROID_NDK_HOME}" \ --archs "${TARGET_ARCHS}" diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 3bd282ba..e3d54246 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -128,7 +128,7 @@ declare_package boringssl "boringssl" "OpenSSL AND ISC AND MIT" \ android_sdk_version=0.1 sdk_name= archs=aarch64,armv7,x86_64 -android_api=28 +android_api=23 build_type=Release parallel_jobs=$(($(nproc --all) + 2)) source_dir= @@ -345,12 +345,12 @@ for arch in $archs; do -DCMAKE_TOOLCHAIN_FILE=$ndk_home/build/cmake/android.toolchain.cmake \ -DCMAKE_BUILD_TYPE=$build_type \ -DCMAKE_EXTRA_LINK_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi -Wl,-z,max-page-size=16384" \ - -DCMAKE_BUILD_TYPE=$build_type \ -DCMAKE_INSTALL_PREFIX=$sdk_root/usr \ -DLIBXML2_WITH_PYTHON=NO \ -DLIBXML2_WITH_ICU=NO \ -DLIBXML2_WITH_ICONV=NO \ -DLIBXML2_WITH_LZMA=NO \ + -DLIBXML2_WITH_TESTS=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_STATIC_LIBS=ON diff --git a/swift-ci/sdks/android/scripts/fetch-source.sh b/swift-ci/sdks/android/scripts/fetch-source.sh index 7a5ead9f..9971fd89 100755 --- a/swift-ci/sdks/android/scripts/fetch-source.sh +++ b/swift-ci/sdks/android/scripts/fetch-source.sh @@ -161,3 +161,32 @@ pushd boringssl >/dev/null 2>&1 git checkout ${BORINGSSL_VERSION} popd >/dev/null 2>&1 groupend + +groupstart "Patching Sources" +pushd swift-project >/dev/null + +# This `git grep` invocation in a trunk test fails in our Docker for some +# reason, so just turn it into a plain `grep` again. +perl -pi -e 's:"git",:#:' swift/test/Misc/verify-swift-feature-testing.test-sh + +# Work around swiftlang/swift-driver#1822 for now +perl -pi -g -we "s#(call rm ... \".\{LIBDISPATCH_BUILD_DIR\}\"\n(\s+)fi\n)#\1\2if [[ -d \"\\\${ANDROID_NDK}\" ]]; then call ln -sf \"\\\${SWIFT_BUILD_PATH}/lib/swift\" \"\\\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib\"; fi#" swift/utils/build-script-impl + +# fix optional result value in backtrace() call +perl -pi -e 's;.init\(clamping: addresses.count\)\)\);.init\(clamping: addresses.count\)\) ?? 0\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift + +# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport); will be fixed post 6.2 (in which case only the above patch is needed) +perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift + + +# Disable posix_spawnattr_* calls for Android API 23 +perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_init;throw NSError\(domain: NSPOSIXErrorDomain, code: .init\(ENOEXEC\), userInfo: [ NSLocalizedFailureReasonErrorKey: "Process unavailable on Android" ]\) //try _throwIfPosixError\(posix_spawnattr_init;g' swift-corelibs-foundation/Sources/Foundation/Process.swift +perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_setflags;//try _throwIfPosixError\(posix_spawnattr_setflags;g' swift-corelibs-foundation/Sources/Foundation/Process.swift +perl -pi -e 's;posix_spawnattr_destroy;//posix_spawnattr_destroy;g' swift-corelibs-foundation/Sources/Foundation/Process.swift + +# Stub out getgrgid_r and getgrnam_r missing from Android API 23 +perl -pi -e 's;getgrgid_r|getgrnam_r;{ _, _, _, _, _ in 0 };g' swift-foundation/Sources/FoundationEssentials/Platform.swift + +popd >/dev/null 2>&1 +groupend + diff --git a/swift-ci/sdks/android/scripts/toolchain-vars.sh b/swift-ci/sdks/android/scripts/toolchain-vars.sh index cb0945c2..3fc3e82f 100644 --- a/swift-ci/sdks/android/scripts/toolchain-vars.sh +++ b/swift-ci/sdks/android/scripts/toolchain-vars.sh @@ -49,8 +49,8 @@ elif [[ $SWIFT_VERSION == scheme:* ]]; then echo "Building $SWIFT_VERSION with prebuilt Swift $RELEASE_TAG compiler" BUILD_COMPILER=yes echo "Branch scheme builds always build the Swift compiler from source and take much longer." -else - echo "Invalid Swift version=${SWIFT_VERSION}" +else + echo "Invalid SWIFT_VERSION: $SWIFT_VERSION" exit 1 fi