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 4b0e0159..8a5a4389 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