From a0ebe225e979ce211e1d9207537282a89fe2ea11 Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Sat, 21 Sep 2024 16:57:08 +0530 Subject: [PATCH] Update CI to latest 6.0 release and development snapshot tags --- .github/workflows/sdks.yml | 139 +++---- android-overlay/foundation-fixes.patch | 357 ------------------ android-overlay/import-android-devel.patch | 87 ----- android-overlay/swift-argument-parser.patch | 31 -- android-overlay/swift-stdlib-modulemap.patch | 17 - android-overlay/yams.patch | 15 - get-packages-and-swift-source.swift | 78 ++-- swift-android-ci-except-trunk.patch | 52 +++ swift-android-ci-trunk.patch | 34 ++ swift-android-ci.patch | 162 +++++++- ...ndroid-foundation-armv7-except-trunk.patch | 168 +++++++++ swift-android-foundation-devel.patch | 26 ++ swift-android-foundation-except-trunk.patch | 272 +++++++++++++ swift-android-foundation-ndk26.patch | 158 -------- swift-android-foundation-trunk.patch | 205 ++++------ swift-android-foundation.patch | 336 +++++++++++++++++ swift-android-release-stdlib.patch | 43 --- swift-android.patch | 71 +++- swift-crypto.patch | 14 + ...h-ndks.patch => swift-nio-filesystem.patch | 26 ++ swift-nio-http2-test.patch | 15 + swift-nio-ndk27.patch | 88 +++++ swift-nio-ssl-test.patch | 59 +++ swift-system-tests.patch | 30 ++ .../swift-system.patch => swift-system.patch | 0 25 files changed, 1504 insertions(+), 979 deletions(-) delete mode 100644 android-overlay/foundation-fixes.patch delete mode 100644 android-overlay/import-android-devel.patch delete mode 100644 android-overlay/swift-argument-parser.patch delete mode 100644 android-overlay/swift-stdlib-modulemap.patch delete mode 100644 android-overlay/yams.patch create mode 100644 swift-android-ci-except-trunk.patch create mode 100644 swift-android-ci-trunk.patch create mode 100644 swift-android-foundation-armv7-except-trunk.patch create mode 100644 swift-android-foundation-devel.patch create mode 100644 swift-android-foundation-except-trunk.patch delete mode 100644 swift-android-foundation-ndk26.patch create mode 100644 swift-android-foundation.patch delete mode 100644 swift-android-release-stdlib.patch create mode 100644 swift-crypto.patch rename swift-nio-filesystem-both-ndks.patch => swift-nio-filesystem.patch (92%) create mode 100644 swift-nio-http2-test.patch create mode 100644 swift-nio-ssl-test.patch create mode 100644 swift-system-tests.patch rename android-overlay/swift-system.patch => swift-system.patch (100%) diff --git a/.github/workflows/sdks.yml b/.github/workflows/sdks.yml index a4d9b765..37038554 100644 --- a/.github/workflows/sdks.yml +++ b/.github/workflows/sdks.yml @@ -19,18 +19,16 @@ jobs: id: check run: | if [ ${{ matrix.version }} = 'release' ]; then - LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-5.10 | cut -d- -f2) + LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-6.0 | cut -d- -f2) SWIFT_TAG="swift-${LATEST_TOOLCHAIN_VERSION}-RELEASE" echo "release-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT elif [ ${{ matrix.version }} = 'devel' ]; then LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/tags | grep -m1 swift-6.0-DEV | cut -d- -f8-10) - SWIFT_TAG="swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-19-a" - # ${LATEST_TOOLCHAIN_VERSION}-a" + SWIFT_TAG="swift-6.0-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a" echo "devel-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT 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-2024-07-15-a" - # ${LATEST_TOOLCHAIN_VERSION}-a" + SWIFT_TAG="swift-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a" echo "trunk-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT fi echo "latest-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT @@ -75,6 +73,9 @@ jobs: version: [release, devel, trunk] arch: [x86_64, aarch64, armv7] os: [ubuntu-22.04, macos-13] + exclude: + - os: macos-13 + version: trunk env: ANDROID_API_LEVEL: 24 steps: @@ -92,16 +93,6 @@ jobs: echo "latest=$(echo $TAG | cut -d- -f4-6)" >> $GITHUB_OUTPUT fi echo "tag=$TAG" >> $GITHUB_OUTPUT - - name: Setup OS Environment - id: setup-os - run: | - if [[ ${{ matrix.os }} = 'macos'* ]]; then - # the inplace "-i" flag to sed requires an empty arg on macOS - echo 'sed -i "" "${@}"' > ~/sedinplace.sh - else - echo 'sed -i "${@}"' > ~/sedinplace.sh - fi - chmod +x ~/sedinplace.sh - name: Get cached SDK id: cache-sdk uses: actions/cache@v4 @@ -124,17 +115,20 @@ jobs: run: | set -x cd sdk-config - if [[ ${{ matrix.os }} = 'macos'* ]]; then + if ${{ startsWith(matrix.os, 'macos') }}; then mkdir ${SWIFT_TAG} pushd ${SWIFT_TAG} xar -x -C . -f ~/${SWIFT_TAG}-osx.pkg tar xz -C . -f ${SWIFT_TAG}-osx-package.pkg/Payload TOOLCHAIN=${PWD}/usr popd - elif [[ ${{ matrix.os }} = 'ubuntu'* ]]; then + elif ${{ startsWith(matrix.os, 'ubuntu') }}; then tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz TOOLCHAIN=${PWD}/$SWIFT_TAG-ubuntu22.04/usr fi + perl -pi -e 's%canImport\(Bionic%canImport\(Android%' $TOOLCHAIN/bin/swift-package + perl -pi -e 's%import Bionic%import Android%' $TOOLCHAIN/bin/swift-package + perl -pi -e 's%TSCBasic, would be%TSCBasic, would %' $TOOLCHAIN/bin/swift-package echo "TOOLCHAIN=${TOOLCHAIN}" >> $GITHUB_ENV ${TOOLCHAIN}/bin/swift --version @@ -148,9 +142,9 @@ jobs: run: | set -x - if [[ ${{ matrix.os }} = 'macos'* ]]; then + if ${{ startsWith(matrix.os, 'macos') }}; then brew install ninja patchelf - elif [[ ${{ matrix.os }} = 'ubuntu'* ]]; then + elif ${{ startsWith(matrix.os, 'ubuntu') }}; then sudo apt install ninja-build fi @@ -162,30 +156,24 @@ jobs: SDK_NAME=$(ls | grep swift-${{ matrix.version }}-android-${{ matrix.arch }}) SDK=`pwd`/$SDK_NAME - git apply swift-android-ci.patch - git apply -C1 swift-android.patch - git apply -C0 swift-android-foundation-ndk26.patch - if [[ ${{ matrix.version }} = 'release' ]]; then - ~/sedinplace.sh "s%strsignal(signal).map%String(cString: strsignal(signal)) //%" swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift - git apply swift-android-release-stdlib.patch - STUPID_FILE_RENAMING=Tool + git apply swift-android.patch swift-android-foundation.patch swift-android-ci.patch swift-crypto.patch swift-system.patch + if [ ${{ matrix.version }} = 'trunk' ]; then + git apply swift-android-ci-trunk.patch swift-android-foundation-trunk.patch else - ~/sedinplace.sh "s%r26%ndk/27%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake + git apply swift-android-ci-except-trunk.patch swift-android-foundation-except-trunk.patch + git apply -C1 swift-android-foundation-armv7-except-trunk.patch if [ ${{ matrix.version }} = 'devel' ]; then - git apply android-overlay/import-android-devel.patch - else - git apply swift-android-foundation-trunk.patch + git apply swift-android-foundation-devel.patch fi - git apply android-overlay/foundation-fixes.patch android-overlay/swift-argument-parser.patch android-overlay/swift-stdlib-modulemap.patch android-overlay/swift-system.patch android-overlay/yams.patch - STUPID_FILE_RENAMING=Command fi - ~/sedinplace.sh "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc - ~/sedinplace.sh "s%String(cString: getpass%\"fake\" //%" swiftpm/Sources/PackageRegistry$STUPID_FILE_RENAMING/PackageRegistry$STUPID_FILE_RENAMING+Auth.swift + perl -pi -e 's%r26%ndk/27%' swift/stdlib/cmake/modules/AddSwiftStdlib.cmake + perl -pi -e "s%/data/data/com.termux/files%$SDK%g" $SDK/usr/lib/pkgconfig/sqlite3.pc + perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift - ./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android --android-ndk $ANDROID_NDK --android-arch ${{ matrix.arch }} --android-api-level $ANDROID_API_LEVEL --build-swift-tools=0 --native-swift-tools-path=${TOOLCHAIN}/bin --native-clang-tools-path=${TOOLCHAIN}/bin --cross-compile-hosts=android-${{ matrix.arch }} --cross-compile-deps-path=$SDK --skip-local-build --build-swift-static-stdlib --xctest --skip-early-swift-driver --install-swift --install-libdispatch --install-foundation --install-xctest --install-destdir=$SDK --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay' --cross-compile-append-host-target-to-destdir=False -b -p --install-llbuild --sourcekit-lsp --skip-early-swiftsyntax + ./swift/utils/build-script -RA --skip-build-cmark --build-llvm=0 --android --android-ndk $ANDROID_NDK_LATEST_HOME --android-arch ${{ matrix.arch }} --android-api-level $ANDROID_API_LEVEL --build-swift-tools=0 --native-swift-tools-path=${TOOLCHAIN}/bin --native-clang-tools-path=${TOOLCHAIN}/bin --cross-compile-hosts=android-${{ matrix.arch }} --cross-compile-deps-path=$SDK --skip-local-build --build-swift-static-stdlib --xctest --skip-early-swift-driver --install-swift --install-libdispatch --install-foundation --install-xctest --install-destdir=$SDK --swift-install-components='clang-resource-dir-symlink;license;stdlib;sdk-overlay' --cross-compile-append-host-target-to-destdir=False -b -p --install-llbuild --sourcekit-lsp --skip-early-swiftsyntax - cp $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$(echo ${{ matrix.arch }} | sed "s/v7//")-linux-android*/libc++_shared.so $SDK/usr/lib + cp $ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$(echo ${{ matrix.arch }} | sed "s/v7//")-linux-android*/libc++_shared.so $SDK/usr/lib patchelf --set-rpath \$ORIGIN $SDK/usr/lib/swift/android/libdispatch.so patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN $SDK/usr/lib/swift/android/lib[FXs]*.so @@ -197,13 +185,6 @@ jobs: with: name: swift-android-sdk-${{ matrix.version }}-${{ matrix.arch }} path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}*-sdk.tar.xz - - name: "Install Android NDK" - id: setup-ndk - if: ${{ startsWith(matrix.os, 'macos') }} - uses: nttld/setup-ndk@v1 - with: - ndk-version: r27 - add-to-path: false - name: Setup Swift ${{ matrix.version }} Android SDK id: sdk-setup run: | @@ -214,10 +195,11 @@ jobs: SDK_PATH=${PWD} popd - if [[ ${{ matrix.os }} = 'ubuntu'* ]]; then + if ${{ startsWith(matrix.os, 'ubuntu') }}; then ARCH_JSON=${SDK_PATH}/usr/swiftpm-android-${{ matrix.arch }}.json cat ${ARCH_JSON} - elif [[ ${{ matrix.os }} = 'macos'* ]]; then + NDK_PREBUILT=${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64 + elif ${{ startsWith(matrix.os, 'macos') }}; then # fix the clang symlink ls -la ${SDK_PATH}/usr/lib/swift/clang rm -vf ${SDK_PATH}/usr/lib/swift/clang @@ -230,16 +212,13 @@ jobs: # so for macOS we need to manually build it ARCH=${{ matrix.arch }} ARCH_JSON="$PWD/android-${ARCH}.json" - ARCH_TARGET="${ARCH}-unknown-linux-android24" + ARCH_TARGET="${ARCH}-unknown-linux-android${ANDROID_API_LEVEL}" ARCHID="${ARCH}-linux-android" if [ "$ARCH" == "armv7" ]; then ARCHID="arm-linux-androideabi" fi - # current default on macos is 26.3.11579264, - # so use the path from the nttld/setup-ndk action for r27 - ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} - NDK_PREBUILT=${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64 + NDK_PREBUILT=${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/darwin-x86_64 # With the full SDK, the libs are all located in: #"-L", "${SDK}/usr/lib/${ARCHID}" @@ -265,6 +244,10 @@ jobs: cat ${ARCH_JSON} fi + if [ ${{ matrix.version }} = 'trunk' ]; then + ln -sf $SDK_PATH/usr/lib/swift $NDK_PREBUILT/sysroot/usr/lib/swift + fi + echo "SDK_PATH=${SDK_PATH}" >> $GITHUB_ENV echo "ARCH_JSON=${ARCH_JSON}" >> $GITHUB_ENV - name: Get Swift Argument Parser package @@ -285,9 +268,10 @@ jobs: path: swift-crypto - name: Build Swift crypto package run: | + git apply sdk-config/swift-crypto.patch cd swift-crypto - ~/sedinplace.sh "s%\\\\(testsDirectory)/.*Vectors%/data/local/tmp/pack/crypto-vectors%" Tests/{Crypto,_CryptoExtras}Tests/Utils/{RFCVector,Wycheproof}.swift - ~/sedinplace.sh 's%#file%"/data/local/tmp/pack/crypto-vectors"%;s%../_CryptoExtrasVectors/%%' Tests/_CryptoExtrasTests/TestRSABlindSigning.swift + perl -pi -e 's%\\\\(testsDirectory)/.*Vectors%/data/local/tmp/pack/crypto-vectors%' Tests/{Crypto,_CryptoExtras}Tests/Utils/{RFCVector,Wycheproof}.swift + perl -pi -e 's%#file%"/data/local/tmp/pack/crypto-vectors"%;s%../_CryptoExtrasVectors/%%' Tests/_CryptoExtrasTests/TestRSABlindSigning.swift ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift NIO package uses: actions/checkout@v4 @@ -295,12 +279,13 @@ jobs: repository: apple/swift-nio path: swift-nio - name: Build Swift NIO package + if: ${{ startsWith(matrix.os, 'ubuntu') }} run: | cd swift-nio - git apply ../sdk-config/swift-nio-disable-ecn-tests.patch ../sdk-config/swift-nio-filesystem-both-ndks.patch ../sdk-config/swift-nio-ndk27.patch + git apply ../sdk-config/swift-nio-disable-ecn-tests.patch ../sdk-config/swift-nio-filesystem.patch ../sdk-config/swift-nio-ndk27.patch ${TOOLCHAIN}/bin/swift package update cd .build/checkouts/ - patch -p1 < ../../../sdk-config/android-overlay/swift-system.patch + patch -p1 < ../../../sdk-config/swift-system.patch cd ../.. ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift Numerics package @@ -319,6 +304,7 @@ jobs: path: swift-system - name: Build Swift System package run: | + git apply sdk-config/swift-system-tests.patch cd swift-system ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift Collections package @@ -342,9 +328,10 @@ jobs: repository: apple/swift-nio-ssh path: sns - name: Build Swift NIO SSH package + if: ${{ startsWith(matrix.os, 'ubuntu') }} run: | cd sns - ~/sedinplace.sh "s%url: .*swift-\([a-z]*\)\.git.*$%path: \"../swift-\1\"),%g" Package.swift + perl -pi -e 's%url: .*swift-([a-z]*)\.git.*$%path: \"../swift-\1\"),%g' Package.swift ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift NIO SSL package uses: actions/checkout@v4 @@ -352,8 +339,10 @@ jobs: repository: apple/swift-nio-ssl path: snl - name: Build Swift NIO SSL package + if: ${{ startsWith(matrix.os, 'ubuntu') }} run: | cd snl + git apply ../sdk-config/swift-nio-ssl-test.patch SWIFTCI_USE_LOCAL_DEPS=1 ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Yams package uses: actions/checkout@v4 @@ -363,7 +352,7 @@ jobs: - name: Build Yams package run: | cd yams - ~/sedinplace.sh "s% fixturesDirectory + \"/SourceKitten#289% \"/data/local/tmp/pack%" Tests/YamsTests/PerformanceTests.swift + perl -pi -e 's% fixturesDirectory + \"/SourceKitten#289% \"/data/local/tmp/pack%' Tests/YamsTests/PerformanceTests.swift ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift NIO HTTP/2 package uses: actions/checkout@v4 @@ -371,10 +360,11 @@ jobs: repository: apple/swift-nio-http2 path: snh - name: Build Swift NIO HTTP/2 package - if: ${{ matrix.arch != 'armv7' }} + if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.arch != 'armv7' }} run: | cd snh - ~/sedinplace.sh "s%url: .*swift-\([a-z]*\)\.git.*$%path: \"../swift-\1\"),%g" Package.swift + git apply ../sdk-config/swift-nio-http2-test.patch + perl -pi -e 's%url: .*swift-([a-z]*)\.git.*$%path: \"../swift-\1\"),%g' Package.swift ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get Swift Algorithms package uses: actions/checkout@v4 @@ -384,7 +374,7 @@ jobs: - name: Build Swift Algorithms package run: | cd sa - ~/sedinplace.sh "s%url: .*$%path: \"../swift-numerics\"),%" Package.swift + perl -pi -e 's%url: .*$%path: \"../swift-numerics\"),%' Package.swift ${TOOLCHAIN}/bin/swift build --build-tests --destination ${ARCH_JSON} -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android - name: Get cached Termux debug app for NIO tests if: ${{ matrix.arch == 'x86_64' }} @@ -400,6 +390,7 @@ jobs: if: ${{ matrix.arch == 'x86_64' }} run: | set -x + if ${{ startsWith(matrix.os, 'ubuntu') }}; then # create the test runner script cat > ~/test-toolchain.sh << EOF adb install ~/termux-debug.apk @@ -413,24 +404,36 @@ jobs: adb shell "run-as com.termux sh -c 'TMPDIR=/data/data/com.termux /data/data/com.termux/pack/swift-nioPackageTests.xctest'" adb shell "TMPDIR=/data/local/tmp /data/local/tmp/pack/swift-systemPackageTests.xctest" EOF + else + cat > ~/test-toolchain.sh << EOF + adb install ~/termux-debug.apk + adb push pack /data/local/tmp + adb shell "TMPDIR=/data/local/tmp /data/local/tmp/pack/swift-systemPackageTests.xctest" + EOF + fi mkdir -p pack/lib/swift/android TARGET="x86_64-unknown-linux-android$ANDROID_API_LEVEL" - if [[ ${{ matrix.os }} != 'macos'* ]]; then + if ${{ startsWith(matrix.os, 'ubuntu') }}; then cp swift-argument-parser/.build/$TARGET/debug/{generate-manual,math,repeat,roll,swift-argument-parserPackageTests.xctest} pack echo 'adb shell /data/local/tmp/pack/swift-argument-parserPackageTests.xctest' >> ~/test-toolchain.sh - fi - wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v1.10/termux-elf-cleaner.cpp - wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v1.10/elf.h - clang -D__ANDROID_API__=$ANDROID_API_LEVEL -o elf-cleaner termux-elf-cleaner.cpp - ./elf-cleaner pack/{generate-manual,math,repeat,roll} || true + wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v2.1.1/elf-cleaner.cpp + wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v2.1.1/elf.h + wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v2.1.1/arghandling.h + wget -q https://raw.githubusercontent.com/termux/termux-elf-cleaner/v2.1.1/arghandling.c + clang -c arghandling.c + clang -o elf-cleaner arghandling.o elf-cleaner.cpp -DCOPYRIGHT=\"foo\" -DPACKAGE_NAME=\"termux-elf-cleaner\" -DPACKAGE_VERSION=\"2.2.1\" + ./elf-cleaner --api-level $ANDROID_API_LEVEL pack/{generate-manual,math,repeat,roll} || true + fi cp swift-crypto/.build/$TARGET/debug/swift-cryptoPackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/swift-cryptoPackageTests.xctest' >> ~/test-toolchain.sh + if ${{ startsWith(matrix.os, 'ubuntu') }}; then cp swift-nio/.build/$TARGET/debug/swift-nioPackageTests.xctest pack + fi cp swift-numerics/.build/$TARGET/debug/swift-numericsPackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/swift-numericsPackageTests.xctest' >> ~/test-toolchain.sh @@ -439,6 +442,7 @@ jobs: cp swift-collections/.build/$TARGET/debug/swift-collectionsPackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/swift-collectionsPackageTests.xctest' >> ~/test-toolchain.sh + if ${{ startsWith(matrix.os, 'ubuntu') }}; then cp sns/.build/$TARGET/debug/swift-nio-sshPackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/swift-nio-sshPackageTests.xctest' >> ~/test-toolchain.sh @@ -447,6 +451,7 @@ jobs: cp snh/.build/$TARGET/debug/swift-nio-http2PackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/swift-nio-http2PackageTests.xctest' >> ~/test-toolchain.sh + fi cp yams/.build/$TARGET/debug/YamsPackageTests.xctest pack echo 'adb shell /data/local/tmp/pack/YamsPackageTests.xctest' >> ~/test-toolchain.sh @@ -472,7 +477,7 @@ jobs: echo "TEST SCRIPT:" cat ~/test-toolchain.sh - if [[ ${{ matrix.os }} != 'macos'* ]]; then + if ${{ startsWith(matrix.os, 'ubuntu') }}; then echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm @@ -482,6 +487,6 @@ jobs: if: ${{ matrix.arch == 'x86_64' }} uses: reactivecircus/android-emulator-runner@v2 with: - api-level: 24 + api-level: 29 arch: x86_64 script: ~/test-toolchain.sh diff --git a/android-overlay/foundation-fixes.patch b/android-overlay/foundation-fixes.patch deleted file mode 100644 index 6920bf3d..00000000 --- a/android-overlay/foundation-fixes.patch +++ /dev/null @@ -1,357 +0,0 @@ -diff --git a/swift-corelibs-foundation/CMakeLists.txt b/swift-corelibs-foundation/CMakeLists.txt -index 4dac9a46..a929bec0 100644 ---- a/swift-corelibs-foundation/CMakeLists.txt -+++ b/swift-corelibs-foundation/CMakeLists.txt -@@ -76,6 +76,14 @@ if(HAS_LIBDISPATCH_API) - find_package(Threads REQUIRED) - endif() - -+# CMake's Threads adds '-pthread' flag to the interface link -+# libraries, which isn't supported by Swift. This is not enabled -+# when building with MSVC, but it trips up the Android build, so -+# we need to clear out the threads INTERFACE_LINK_LIBRARIES. -+if (CMAKE_SYSTEM_NAME STREQUAL "Android") -+ set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "") -+endif() -+ - set(SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) - set(BUILD_SHARED_LIBS NO) - add_subdirectory(CoreFoundation EXCLUDE_FROM_ALL) -diff --git a/swift-corelibs-foundation/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h b/swift-corelibs-foundation/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h -index cc1ba843..5bd1e283 100644 ---- a/swift-corelibs-foundation/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h -+++ b/swift-corelibs-foundation/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h -@@ -64,6 +64,7 @@ - #include - #include - #include -+#include - #elif TARGET_OS_WASI - #include - #include -diff --git a/swift-corelibs-foundation/CoreFoundation/Base.subproj/module.modulemap b/swift-corelibs-foundation/CoreFoundation/Base.subproj/module.modulemap -index fe4c0a68..8e95a176 100644 ---- a/swift-corelibs-foundation/CoreFoundation/Base.subproj/module.modulemap -+++ b/swift-corelibs-foundation/CoreFoundation/Base.subproj/module.modulemap -@@ -1,6 +1,12 @@ - framework module CoreFoundation [extern_c] [system] { - umbrella header "CoreFoundation.h" - explicit module CFPlugInCOM { header "CFPlugInCOM.h" } -+ explicit module ForSwiftFoundationOnly { -+ header "ForSwiftFoundationOnly.h" -+ // Do not re-export imported Clang modules to avoid pulling in -+ // system headers like linux/stat.h whose constants might conflict -+ // with constants from the platform module. -+ } - - export * - module * { -diff --git a/swift-corelibs-foundation/Sources/Foundation/Data.swift b/swift-corelibs-foundation/Sources/Foundation/Data.swift -index 9e5c9faf..57e17e58 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Data.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Data.swift -@@ -42,6 +42,13 @@ - @usableFromInline let memset = WASILibc.memset - @usableFromInline let memcpy = WASILibc.memcpy - @usableFromInline let memcmp = WASILibc.memcmp -+#elseif canImport(Android) -+@usableFromInline let calloc = Android.calloc -+@usableFromInline let malloc = Android.malloc -+@usableFromInline let free = Android.free -+@usableFromInline let memset = Android.memset -+@usableFromInline let memcpy = Android.memcpy -+@usableFromInline let memcmp = Android.memcmp - #endif - - #if !canImport(Darwin) -@@ -57,6 +64,8 @@ internal func malloc_good_size(_ size: Int) -> Int { - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #elseif canImport(WASILibc) - import WASILibc - #endif -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -index 72ab09a3..92cef10c 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -@@ -34,6 +34,11 @@ import WASILibc - fileprivate let _read = WASILibc.read(_:_:_:) - fileprivate let _write = WASILibc.write(_:_:_:) - fileprivate let _close = WASILibc.close(_:) -+#elseif canImport(Android) -+import Android -+fileprivate let _read = Android.read(_:_:_:) -+fileprivate let _write = Android.write(_:_:_:) -+fileprivate let _close = Android.close(_:) - #endif - - #if canImport(WinSDK) -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -index fdd84115..e4296eb3 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -@@ -25,6 +25,10 @@ import WinSDK - import WASILibc - #endif - -+#if canImport(Android) -+import Android -+#endif -+ - #if os(Windows) - internal typealias NativeFSRCharType = WCHAR - internal let NativeFSREncoding = String.Encoding.utf16LittleEndian.rawValue -diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift -index b5205ebb..6bf91c7e 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Host.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift -@@ -12,8 +12,9 @@ - import WinSDK - #endif - --#if os(Android) -- // Android Glibc differs a little with respect to the Linux Glibc. -+#if canImport(Android) -+ import Android -+ // Android Bionic differs a little with respect to the Linux Glibc. - - // IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to - // convert to UInt32. -@@ -26,7 +27,7 @@ import WinSDK - // getnameinfo uses size_t for its 4th and 6th arguments. - private func getnameinfo(_ addr: UnsafePointer?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { - guard let saddr = addr else { return -1 } -- return Glibc.getnameinfo(saddr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) -+ return Android.getnameinfo(saddr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) - } - - // getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically. -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSData.swift b/swift-corelibs-foundation/Sources/Foundation/NSData.swift -index aaeeb9ae..83a5b2b2 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSData.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSData.swift -@@ -495,6 +495,8 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { - let createMode = Int(Musl.S_IRUSR) | Int(Musl.S_IWUSR) | Int(Musl.S_IRGRP) | Int(Musl.S_IWGRP) | Int(Musl.S_IROTH) | Int(Musl.S_IWOTH) - #elseif canImport(WASILibc) - let createMode = Int(WASILibc.S_IRUSR) | Int(WASILibc.S_IWUSR) | Int(WASILibc.S_IRGRP) | Int(WASILibc.S_IWGRP) | Int(WASILibc.S_IROTH) | Int(WASILibc.S_IWOTH) -+#elseif canImport(Android) -+ let createMode = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH) - #endif - guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else { - throw _NSErrorWithErrno(errno, reading: false, path: path) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSError.swift b/swift-corelibs-foundation/Sources/Foundation/NSError.swift -index fc87a4d6..f05b503a 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSError.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSError.swift -@@ -16,6 +16,8 @@ import Darwin - import Glibc - #elseif canImport(CRT) - import CRT -+#elseif canImport(Android) -+import Android - #endif - - @_implementationOnly import CoreFoundation -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -index fa56161c..aa8fe7ef 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -@@ -11,6 +11,8 @@ - - #if canImport(Glibc) - import Glibc -+#elseif canImport(Android) -+import Android - #endif - - #if os(Windows) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -index c079ed62..c15217ab 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -@@ -18,6 +18,8 @@ - @_exported import Glibc - #elseif canImport(Musl) - @_exported import Musl -+#elseif canImport(Android) -+@_exported import Android - #elseif os(WASI) - @_exported import WASILibc - #elseif os(Windows) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -index 4d31e2ba..6169613b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -@@ -22,6 +22,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #endif - - // NOTE: this represents PLATFORM_PATH_STYLE -diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift -index c53263f0..9f1823fe 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Port.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift -@@ -96,22 +96,26 @@ fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM - fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP - #endif - --#if canImport(Glibc) && !os(Android) && !os(OpenBSD) -+#if canImport(Glibc) && !os(OpenBSD) - import Glibc - fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue) - fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) - #endif - --#if canImport(Glibc) && os(Android) || os(OpenBSD) -+#if canImport(Glibc) && os(OpenBSD) - import Glibc - fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) - fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) - fileprivate let INADDR_ANY: in_addr_t = 0 --#if os(OpenBSD) - fileprivate let INADDR_LOOPBACK = 0x7f000001 - #endif --#endif - -+#if canImport(Android) -+import Android -+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) -+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) -+fileprivate let INADDR_ANY: in_addr_t = 0 -+#endif - - #if canImport(WinSDK) - import WinSDK -diff --git a/swift-corelibs-foundation/Sources/Foundation/Thread.swift b/swift-corelibs-foundation/Sources/Foundation/Thread.swift -index 166a5d3f..4f401987 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Thread.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Thread.swift -@@ -17,6 +17,8 @@ import WinSDK - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #endif - - // WORKAROUND_SR9811 -diff --git a/swift-corelibs-foundation/Sources/Tools/plutil/main.swift b/swift-corelibs-foundation/Sources/Tools/plutil/main.swift -index d71d9ba9..bc35a172 100644 ---- a/swift-corelibs-foundation/Sources/Tools/plutil/main.swift -+++ b/swift-corelibs-foundation/Sources/Tools/plutil/main.swift -@@ -15,6 +15,9 @@ import Glibc - #elseif canImport(Musl) - import Foundation - import Musl -+#elseif canImport(Android) -+import Foundation -+import Android - #elseif canImport(CRT) - import Foundation - import CRT -diff --git a/swift-corelibs-foundation/Tests/Foundation/FTPServer.swift b/swift-corelibs-foundation/Tests/Foundation/FTPServer.swift -index 8bb4a9d7..a09fcae5 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/FTPServer.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/FTPServer.swift -@@ -15,6 +15,8 @@ import Dispatch - import Glibc - #elseif canImport(Darwin) - import Darwin -+#elseif canImport(Android) -+ import Android - #endif - - public class ServerSemaphore { -diff --git a/swift-corelibs-foundation/Tests/Foundation/HTTPServer.swift b/swift-corelibs-foundation/Tests/Foundation/HTTPServer.swift -index 0ab0f0dc..5066cda2 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/HTTPServer.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/HTTPServer.swift -@@ -21,6 +21,8 @@ import Dispatch - import Darwin - #elseif canImport(Glibc) - import Glibc -+#elseif canImport(Android) -+ import Android - #endif - - #if !os(Windows) -diff --git a/swift-corelibs-foundation/Tests/Foundation/Tests/TestFileHandle.swift b/swift-corelibs-foundation/Tests/Foundation/Tests/TestFileHandle.swift -index 5416c41c..82655a29 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/Tests/TestFileHandle.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/Tests/TestFileHandle.swift -@@ -111,7 +111,14 @@ class TestFileHandle : XCTestCase { - #else - var fds: [Int32] = [-1, -1] - fds.withUnsafeMutableBufferPointer { (pointer) -> Void in -- pipe(pointer.baseAddress) -+ let baseAddress = pointer.baseAddress -+#if canImport(Android) -+ // pipe takes in a non-nullable pointer in the Android NDK only. -+ guard let baseAddress else { -+ return -+ } -+#endif -+ pipe(baseAddress) - } - - close(fds[1]) -diff --git a/swift-corelibs-foundation/Tests/Foundation/Tests/TestNSData.swift b/swift-corelibs-foundation/Tests/Foundation/Tests/TestNSData.swift -index 2c84f633..7f72e0d0 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/Tests/TestNSData.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/Tests/TestNSData.swift -@@ -589,6 +589,8 @@ class TestNSData: LoopbackServerTest { - let permission = try fileManager._permissionsOfItem(atPath: url.path) - #if canImport(Darwin) - let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH) -+#elseif canImport(Android) -+ let expected = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH) - #else - let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH) - #endif -@@ -612,6 +614,8 @@ class TestNSData: LoopbackServerTest { - let permission = try fileManager._permissionsOfItem(atPath: url.path) - #if canImport(Darwin) - let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH) -+#elseif canImport(Android) -+ let expected = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH) - #else - let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH) - #endif -diff --git a/swift-corelibs-foundation/Tests/Foundation/Tests/TestTimeZone.swift b/swift-corelibs-foundation/Tests/Foundation/Tests/TestTimeZone.swift -index 5e15c000..5c679b38 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/Tests/TestTimeZone.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/Tests/TestTimeZone.swift -@@ -160,7 +160,12 @@ class TestTimeZone: XCTestCase { - var lt = tm() - localtime_r(&t, <) - let zoneName = NSTimeZone.system.abbreviation() ?? "Invalid Abbreviation" -- let expectedName = String(cString: lt.tm_zone, encoding: .ascii) ?? "Invalid Zone" -+ // tm_zone is nullable in the Android NDK only. -+ let tm_zone: UnsafePointer? = lt.tm_zone -+ guard let tm_zone else { -+ return -+ } -+ let expectedName = String(cString: tm_zone, encoding: .ascii) ?? "Invalid Zone" - XCTAssertEqual(zoneName, expectedName, "expected name \"\(expectedName)\" is not equal to \"\(zoneName)\"") - } - #endif -diff --git a/swift-corelibs-foundation/Tests/Foundation/main.swift b/swift-corelibs-foundation/Tests/Foundation/main.swift -index e6c7b35b..643c0c12 100644 ---- a/swift-corelibs-foundation/Tests/Foundation/main.swift -+++ b/swift-corelibs-foundation/Tests/Foundation/main.swift -@@ -13,6 +13,8 @@ - import Darwin - #elseif canImport(Glibc) - import Glibc -+#elseif canImport(Android) -+ import Android - #elseif canImport(CRT) - import CRT - #endif diff --git a/android-overlay/import-android-devel.patch b/android-overlay/import-android-devel.patch deleted file mode 100644 index 6be54786..00000000 --- a/android-overlay/import-android-devel.patch +++ /dev/null @@ -1,87 +0,0 @@ -diff --git a/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift -index 4d6577d0..0eef6e57 100644 ---- a/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift -+++ b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift -@@ -19,6 +19,8 @@ import WinSDK - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Bionic) -+import Bionic - #else - #error("Missing libc or equivalent") - #endif -@@ -136,7 +136,7 @@ import var TSCBasic.stdoutStream - } - #else - case .signalled(let signal): -- let errorMessage = strsignal(signal).map { String(cString: $0) } ?? "" -+ let errorMessage = String(cString: strsignal(signal)) - messages = constructJobSignalledMessages(job: job, error: errorMessage, output: output, - signal: signal, pid: pid).map { - ParsableMessage(name: job.kind.rawValue, kind: .signalled($0)) -diff --git a/swift-driver/Sources/SwiftDriver/SwiftScan/Loader.swift b/swift-driver/Sources/SwiftDriver/SwiftScan/Loader.swift -index 92ec883f..2ab4e6fd 100644 ---- a/swift-driver/Sources/SwiftDriver/SwiftScan/Loader.swift -+++ b/swift-driver/Sources/SwiftDriver/SwiftScan/Loader.swift -@@ -21,6 +21,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #endif - - internal enum Loader { -diff --git a/swift-driver/Sources/SwiftDriver/Utilities/DateAdditions.swift b/swift-driver/Sources/SwiftDriver/Utilities/DateAdditions.swift -index fcad533d..8d924dbd 100644 ---- a/swift-driver/Sources/SwiftDriver/Utilities/DateAdditions.swift -+++ b/swift-driver/Sources/SwiftDriver/Utilities/DateAdditions.swift -@@ -18,6 +18,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Bionic) -+import Bionic - #endif - - /// Represents a time point value with nanosecond precision. -diff --git a/swift-driver/Sources/SwiftDriver/Utilities/System.swift b/swift-driver/Sources/SwiftDriver/Utilities/System.swift -index c4fdaa89..a3b4d451 100644 ---- a/swift-driver/Sources/SwiftDriver/Utilities/System.swift -+++ b/swift-driver/Sources/SwiftDriver/Utilities/System.swift -@@ -16,6 +16,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #endif - - func argumentNeedsQuoting(_ argument: String) -> Bool { -diff --git a/swift-driver/Sources/swift-build-sdk-interfaces/main.swift b/swift-driver/Sources/swift-build-sdk-interfaces/main.swift -index 07eced80..a12a594a 100644 ---- a/swift-driver/Sources/swift-build-sdk-interfaces/main.swift -+++ b/swift-driver/Sources/swift-build-sdk-interfaces/main.swift -@@ -19,6 +19,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Bionic) -+import Bionic - #endif - - import class TSCBasic.DiagnosticsEngine -diff --git a/swift-driver/Sources/swift-driver/main.swift b/swift-driver/Sources/swift-driver/main.swift -index 8126b659..e1f2f56f 100644 ---- a/swift-driver/Sources/swift-driver/main.swift -+++ b/swift-driver/Sources/swift-driver/main.swift -@@ -20,6 +20,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #endif - - import Dispatch diff --git a/android-overlay/swift-argument-parser.patch b/android-overlay/swift-argument-parser.patch deleted file mode 100644 index e24a4333..00000000 --- a/android-overlay/swift-argument-parser.patch +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift b/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift -index b7fa046..a94e3b8 100644 ---- a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift -+++ b/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift -@@ -19,6 +19,8 @@ import Darwin - import CRT - #elseif canImport(WASILibc) - import WASILibc -+#elseif canImport(Android) -+import Android - #endif - - enum Platform {} -@@ -88,6 +90,8 @@ extension Platform { - ucrt._exit(code) - #elseif canImport(WASILibc) - WASILibc.exit(code) -+#elseif canImport(Android) -+ Android.exit(code) - #endif - } - } -@@ -108,7 +112,7 @@ extension Platform { - - // MARK: Terminal size - --#if canImport(Glibc) -+#if canImport(Glibc) || canImport(Android) - func ioctl(_ a: Int32, _ b: Int32, _ p: UnsafeMutableRawPointer) -> Int32 { - ioctl(CInt(a), UInt(b), p) - } diff --git a/android-overlay/swift-stdlib-modulemap.patch b/android-overlay/swift-stdlib-modulemap.patch deleted file mode 100644 index 9fa4103c..00000000 --- a/android-overlay/swift-stdlib-modulemap.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap -index 78e7bda9976..dc25e5c3668 100644 ---- a/swift/stdlib/public/Platform/android.modulemap -+++ b/swift/stdlib/public/Platform/android.modulemap -@@ -556,6 +556,12 @@ module _bits_sa_family_t [system] { - header "bits/sa_family_t.h" - export * - } -+ -+module _bits_sockaddr_storage [system] { -+ header "bits/sockaddr_storage.h" -+ export * -+} -+ - module _bits_stdatomic [system] { - // Note: this module is not part of 'stdatomic' - // as it depends on libc++ and forcing it to diff --git a/android-overlay/yams.patch b/android-overlay/yams.patch deleted file mode 100644 index 8495f1ed..00000000 --- a/android-overlay/yams.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/yams/Sources/Yams/Representer.swift b/yams/Sources/Yams/Representer.swift -index a749c52..b74ef8e 100644 ---- a/yams/Sources/Yams/Representer.swift -+++ b/yams/Sources/Yams/Representer.swift -@@ -14,6 +14,10 @@ private let cpow: (_: Double, _: Double) -> Double = Darwin.pow - #elseif os(Windows) - import ucrt - private let cpow: (_: Double, _: Double) -> Double = ucrt.pow -+#elseif canImport(Bionic) -+import CoreFoundation -+import Bionic -+private let cpow: (_: Double, _: Double) -> Double = Bionic.pow - #else - import CoreFoundation - import Glibc diff --git a/get-packages-and-swift-source.swift b/get-packages-and-swift-source.swift index d1d94491..3758a32d 100644 --- a/get-packages-and-swift-source.swift +++ b/get-packages-and-swift-source.swift @@ -1,20 +1,22 @@ import Foundation // The Termux packages to download and unpack -var termuxPackages = ["libicu", "libicu-static", "libandroid-spawn", "libcurl", "libxml2"] +var termuxPackages = ["libandroid-spawn", "libcurl", "libxml2"] let termuxURL = "https://packages.termux.dev/apt/termux-main" let swiftRepos = ["llvm-project", "swift", "swift-experimental-string-processing", "swift-corelibs-libdispatch", - "swift-corelibs-foundation", "swift-corelibs-xctest", "swift-syntax"] + "swift-corelibs-foundation", "swift-corelibs-xctest", "swift-syntax", "swift-collections", + "swift-foundation", "swift-foundation-icu"] let extraSwiftRepos = ["swift-llbuild", "swift-package-manager", "swift-driver", "swift-tools-support-core", "swift-argument-parser", "swift-crypto", "Yams", "indexstore-db", "sourcekit-lsp", "swift-system", - "swift-collections", "swift-certificates", "swift-asn1"] + "swift-certificates", "swift-asn1", "swift-toolchain-sqlite"] +let appleRepos = ["swift-argument-parser", "swift-crypto", "swift-system", "swift-collections", "swift-certificates", "swift-asn1"] let renameRepos = ["swift-llbuild" : "llbuild", "swift-package-manager" : "swiftpm", "Yams" : "yams"] var repoTags = ["swift-system" : "1.3.0", "swift-collections" : "1.1.2", "swift-asn1" : "1.0.0", "swift-certificates" : "1.0.1", "Yams" : "5.0.6", "swift-argument-parser" : "1.2.3", - "swift-crypto" : "3.0.0"] + "swift-crypto" : "3.0.0", "swift-toolchain-sqlite" : "1.0.1"] if ProcessInfo.processInfo.environment["BUILD_SWIFT_PM"] != nil { termuxPackages += ["ncurses", "libsqlite"] } @@ -27,8 +29,7 @@ guard let ANDROID_ARCH = ProcessInfo.processInfo.environment["ANDROID_ARCH"] els fatalError("You must specify an ANDROID_ARCH environment variable.") } -var sdkDir = "", icuVersion = "", icuMajorVersion = "", swiftVersion = "", - swiftBranch = "", swiftSnapshotDate = "" +var sdkDir = "", swiftVersion = "", swiftBranch = "", swiftSnapshotDate = "" let tagRange = NSRange(SWIFT_TAG.startIndex..., in: SWIFT_TAG) let tagExtract = try NSRegularExpression(pattern: "swift-([5-9]\\.[0-9]+)?\\.?[1-9]*-?([A-Z-]+)([0-9-]+[0-9])?") @@ -49,13 +50,11 @@ if tagExtract.numberOfMatches(in: SWIFT_TAG, range: tagRange) == 1 { } if swiftBranch == "RELEASE" { - repoTags["swift-collections"] = "1.0.5" - repoTags["swift-system"] = "1.1.1" - repoTags["Yams"] = "5.0.1" sdkDir = "swift-release-android-\(ANDROID_ARCH)-24-sdk" } else { if swiftVersion == "" { repoTags["swift-argument-parser"] = "1.4.0" + repoTags["swift-collections"] = "1.1.3" } sdkDir = "swift-\(swiftVersion == "" ? "trunk" : "devel")-android-\(ANDROID_ARCH)-\(swiftSnapshotDate)-24-sdk" } @@ -186,17 +185,6 @@ for termuxPackage in termuxPackages { "\(termuxURL)/\(packagePath)"]) } - if termuxPackage == "libicu" { - guard let icuVersionRange = packageName.range(of: "([0-9]+)\\.[0-9]", options: .regularExpression) else { - fatalError("couldn't extract ICU version from \(packageName)") - } - icuVersion = String(packageName[icuVersionRange]) - guard let icuMajorVersionRange = icuVersion.range(of: "^[0-9]+", options: .regularExpression) else { - fatalError("couldn't extract ICU major version from \(icuVersion)") - } - icuMajorVersion = String(icuVersion[icuMajorVersionRange]) - } - if !fmd.fileExists(atPath: cwd.appendingPathComponent(sdkDir)) { print("Unpacking \(packageName)") #if os(macOS) @@ -224,35 +212,6 @@ if !fmd.fileExists(atPath: sdkPath) { try fmd.removeItem(atPath: sdkPath.appendingPathComponent("usr/share/man")) } -for iculib in ["data", "i18n", "io", "test", "tu", "uc"] { - if fmd.fileExists(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so.\(icuMajorVersion)")) { - try fmd.removeItem(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so")) - try fmd.removeItem(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so.\(icuMajorVersion)")) - - if ["io", "test", "tu"].contains(iculib) { - try fmd.removeItem(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).a")) - try fmd.removeItem(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so.\(icuVersion)")) - } else { - try fmd.moveItem(atPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so.\(icuVersion)"), - toPath: sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so")) - _ = runCommand("patchelf", with: ["--set-rpath", "$ORIGIN", - "\(sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so"))"]) - _ = runCommand("patchelf", with: ["--set-soname", "libicu\(iculib).so", - "\(sdkPath.appendingPathComponent("usr/lib/libicu\(iculib).so"))"]) - - if iculib == "i18n" { - _ = runCommand("patchelf", with: ["--replace-needed", "libicuuc.so.\(icuMajorVersion)", - "libicuuc.so", "\(sdkPath.appendingPathComponent("usr/lib/libicui18n.so"))"]) - } - - if iculib == "uc" { - _ = runCommand("patchelf", with: ["--replace-needed", "libicudata.so.\(icuMajorVersion)", - "libicudata.so", "\(sdkPath.appendingPathComponent("usr/lib/libicuuc.so"))"]) - } - } - } -} - _ = runCommand("patchelf", with: ["--set-rpath", "$ORIGIN", "\(sdkPath.appendingPathComponent("usr/lib/libandroid-spawn.so"))", "\(sdkPath.appendingPathComponent("usr/lib/libcurl.so"))", @@ -262,20 +221,31 @@ for repo in swiftRepos { print("Checking for \(repo) source") if !fmd.fileExists(atPath: cwd.appendingPathComponent(repo)) { print("Downloading and extracting \(repo) source") + let tag = repoTags[repo] ?? SWIFT_TAG + var repoOrg = "swiftlang" + if ["swift-corelibs-libdispatch", "swift-collections"].contains(repo) { + repoOrg = "apple" + } _ = runCommand("curl", with: ["-f", "-L", "-O", - "https://github.com/apple/\(repo)/archive/refs/tags/\(SWIFT_TAG).tar.gz"]) - _ = runCommand("tar", with: ["xf", "\(SWIFT_TAG).tar.gz"]) - try fmd.moveItem(atPath: cwd.appendingPathComponent("\(repo)-\(SWIFT_TAG)"), + "https://github.com/\(repoOrg)/\(repo)/archive/refs/tags/\(tag).tar.gz"]) + _ = runCommand("tar", with: ["xf", "\(tag).tar.gz"]) + try fmd.moveItem(atPath: cwd.appendingPathComponent("\(repo)-\(tag)"), toPath: cwd.appendingPathComponent(repo)) - try fmd.removeItem(atPath: cwd.appendingPathComponent("\(SWIFT_TAG).tar.gz")) + try fmd.removeItem(atPath: cwd.appendingPathComponent("\(tag).tar.gz")) } } if ProcessInfo.processInfo.environment["BUILD_SWIFT_PM"] != nil { for repo in extraSwiftRepos { let tag = repoTags[repo] ?? SWIFT_TAG + var repoOrg = "swiftlang" + if repo == "Yams" { + repoOrg = "jpsim" + } else if appleRepos.contains(repo) { + repoOrg = "apple" + } _ = runCommand("curl", with: ["-f", "-L", "-O", - "https://github.com/\(repo == "Yams" ? "jpsim" : "apple")/\(repo)/archive/refs/tags/\(tag).tar.gz"]) + "https://github.com/\(repoOrg)/\(repo)/archive/refs/tags/\(tag).tar.gz"]) _ = runCommand("tar", with: ["xf", "\(tag).tar.gz"]) try fmd.moveItem(atPath: cwd.appendingPathComponent("\(repo)-\(tag)"), toPath: cwd.appendingPathComponent(renameRepos[repo] ?? repo)) diff --git a/swift-android-ci-except-trunk.patch b/swift-android-ci-except-trunk.patch new file mode 100644 index 00000000..6a50d66e --- /dev/null +++ b/swift-android-ci-except-trunk.patch @@ -0,0 +1,52 @@ +diff --git a/llbuild/products/llbuildSwift/BuildSystemBindings.swift b/llbuild/products/llbuildSwift/BuildSystemBindings.swift +index 6962fff5..8f1bf502 100644 +--- a/llbuild/products/llbuildSwift/BuildSystemBindings.swift ++++ b/llbuild/products/llbuildSwift/BuildSystemBindings.swift +@@ -17,8 +17,8 @@ import WinSDK + import Glibc + #elseif canImport(Musl) + import Musl +-#elseif canImport(Bionic) +-import Bionic ++#elseif canImport(Android) ++import Android + #else + #error("Missing libc or equivalent") + #endif +@@ -1293,7 +1293,7 @@ public final class BuildSystem { + #elseif os(Windows) + info.pointee.mod_time.seconds = UInt64(s.st_mtime) + info.pointee.mod_time.nanoseconds = 0 +- #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) ++ #elseif canImport(Glibc) || canImport(Musl) || canImport(Android) + info.pointee.mod_time.seconds = UInt64(s.st_mtim.tv_sec) + info.pointee.mod_time.nanoseconds = UInt64(s.st_mtim.tv_nsec) + #else +diff --git a/llbuild/unittests/CMakeLists.txt b/llbuild/unittests/CMakeLists.txt +index 92a1ee38..52273afb 100644 +--- a/llbuild/unittests/CMakeLists.txt ++++ b/llbuild/unittests/CMakeLists.txt +@@ -6,9 +6,9 @@ function(add_llbuild_unittest test_dirname) + endfunction() + + add_subdirectory(Basic) +-add_subdirectory(CAS) ++#add_subdirectory(CAS) + add_subdirectory(CAPI) + add_subdirectory(Core) + add_subdirectory(Evo) + add_subdirectory(BuildSystem) +-add_subdirectory(Ninja) ++#add_subdirectory(Ninja) +diff --git a/swiftpm/Sources/Basics/AsyncProcess.swift b/swiftpm/Sources/Basics/AsyncProcess.swift +--- a/swiftpm/Sources/Basics/AsyncProcess.swift ++++ b/swiftpm/Sources/Basics/AsyncProcess.swift +@@ -14,6 +14,8 @@ + + #if os(Windows) + import TSCLibc ++#elseif canImport(Android) ++import Android + #endif + + #if os(Linux) diff --git a/swift-android-ci-trunk.patch b/swift-android-ci-trunk.patch new file mode 100644 index 00000000..aa59769f --- /dev/null +++ b/swift-android-ci-trunk.patch @@ -0,0 +1,34 @@ +diff --git a/llbuild/unittests/CMakeLists.txt b/llbuild/unittests/CMakeLists.txt +index 92a1ee38..52273afb 100644 +--- a/llbuild/unittests/CMakeLists.txt ++++ b/llbuild/unittests/CMakeLists.txt +@@ -6,4 +6,4 @@ function(add_llbuild_unittest test_dirname) + add_subdirectory(CAPI) + add_subdirectory(Core) + add_subdirectory(BuildSystem) +-add_subdirectory(Ninja) ++#add_subdirectory(Ninja) +diff --git a/swiftpm/Package.swift b/swiftpm/Package.swift +--- a/swiftpm/Package.swift ++++ b/swiftpm/Package.swift +@@ -198,7 +198,7 @@ + name: "Basics", + dependencies: [ + "_AsyncFileSystem", +- .target(name: "SPMSQLite3", condition: .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .visionOS, .macCatalyst, .linux])), ++ .target(name: "SPMSQLite3", condition: .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .visionOS, .macCatalyst, .linux, .android])), + .product(name: "SwiftToolchainCSQLite", package: "swift-toolchain-sqlite", condition: .when(platforms: [.windows])), + .product(name: "DequeModule", package: "swift-collections"), + .product(name: "OrderedCollections", package: "swift-collections"), +diff --git a/swiftpm/Sources/Basics/Concurrency/AsyncProcess.swift b/swiftpm/Sources/Basics/Concurrency/AsyncProcess.swift +--- a/swiftpm/Sources/Basics/Concurrency/AsyncProcess.swift ++++ b/swiftpm/Sources/Basics/Concurrency/AsyncProcess.swift +@@ -14,6 +14,8 @@ + + #if os(Windows) + import TSCLibc ++#elseif canImport(Android) ++import Android + #endif + + #if os(Linux) diff --git a/swift-android-ci.patch b/swift-android-ci.patch index 98a12f58..a1a181ea 100644 --- a/swift-android-ci.patch +++ b/swift-android-ci.patch @@ -30,22 +30,31 @@ index 9d5a714b..3f8f8c1d 100644 + ) +endif() endif() -diff --git a/llbuild/unittests/CMakeLists.txt b/llbuild/unittests/CMakeLists.txt -index 92a1ee38..52273afb 100644 ---- a/llbuild/unittests/CMakeLists.txt -+++ b/llbuild/unittests/CMakeLists.txt -@@ -6,9 +6,9 @@ function(add_llbuild_unittest test_dirname) - endfunction() +diff --git a/sourcekit-lsp/Sources/SKSupport/Process+Run.swift b/sourcekit-lsp/Sources/SKSupport/Process+Run.swift +--- a/sourcekit-lsp/Sources/SKSupport/Process+Run.swift ++++ b/sourcekit-lsp/Sources/SKSupport/Process+Run.swift +@@ -22,6 +22,8 @@ - add_subdirectory(Basic) --add_subdirectory(CAS) -+#add_subdirectory(CAS) - add_subdirectory(CAPI) - add_subdirectory(Core) - add_subdirectory(Evo) - add_subdirectory(BuildSystem) --add_subdirectory(Ninja) -+#add_subdirectory(Ninja) + #if os(Windows) + import WinSDK ++#elseif canImport(Android) ++import Android + #endif + + extension Process { +diff --git a/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift b/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift +--- a/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift ++++ b/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift +@@ -28,6 +28,9 @@ + import struct TSCBasic.AbsolutePath + import struct TSCBasic.RelativePath + import var TSCBasic.localFileSystem ++#if canImport(Android) ++import Android ++#endif + + extension AbsolutePath { + public init?(argument: String) { diff --git a/sourcekit-lsp/Utilities/build-script-helper.py b/sourcekit-lsp/Utilities/build-script-helper.py index bd31bec..4469cab 100755 --- a/sourcekit-lsp/Utilities/build-script-helper.py @@ -58,6 +67,114 @@ index bd31bec..4469cab 100755 # Android and fail. '-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE', ] +diff --git a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift b/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift +index b7fa046..a94e3b8 100644 +--- a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift ++++ b/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift +@@ -19,6 +19,8 @@ import Darwin + import CRT + #elseif canImport(WASILibc) + import WASILibc ++#elseif canImport(Android) ++import Android + #endif + + enum Platform {} +@@ -88,6 +90,8 @@ extension Platform { + ucrt._exit(code) + #elseif canImport(WASILibc) + WASILibc.exit(code) ++#elseif canImport(Android) ++ Android.exit(code) + #endif + } + } +@@ -108,7 +112,7 @@ extension Platform { + + // MARK: Terminal size + +-#if canImport(Glibc) ++#if canImport(Glibc) || canImport(Android) + func ioctl(_ a: Int32, _ b: Int32, _ p: UnsafeMutableRawPointer) -> Int32 { + ioctl(CInt(a), UInt(b), p) + } +diff --git a/swift-certificates/Sources/X509/Verifier/RFC5280/URIConstraints.swift b/swift-certificates/Sources/X509/Verifier/RFC5280/URIConstraints.swift +--- a/swift-certificates/Sources/X509/Verifier/RFC5280/URIConstraints.swift ++++ b/swift-certificates/Sources/X509/Verifier/RFC5280/URIConstraints.swift +@@ -21,6 +21,9 @@ + #elseif canImport(Musl) + import Musl + import CoreFoundation ++#elseif canImport(Android) ++import Android ++import CoreFoundation + #elseif canImport(Darwin) + import Darwin + #endif +diff --git a/swift-tools-support-core/Sources/TSCUtility/Tracing.swift b/swift-tools-support-core/Sources/TSCUtility/Tracing.swift +--- a/swift-tools-support-core/Sources/TSCUtility/Tracing.swift ++++ b/swift-tools-support-core/Sources/TSCUtility/Tracing.swift +@@ -9,6 +9,9 @@ + */ + + import Foundation ++#if canImport(Android) ++import Android ++#endif + + public enum TracingEventType: String, Codable, Sendable { + case asyncBegin +diff --git a/swiftpm/Sources/Basics/Cancellator.swift b/swiftpm/Sources/Basics/Cancellator.swift +--- a/swiftpm/Sources/Basics/Cancellator.swift ++++ b/swiftpm/Sources/Basics/Cancellator.swift +@@ -15,6 +15,8 @@ + import class TSCBasic.Thread + #if canImport(WinSDK) + import WinSDK ++#elseif canImport(Android) ++import Android + #endif + + public typealias CancellationHandler = @Sendable (DispatchTime) throws -> Void +diff --git a/swiftpm/Sources/Basics/Environment/Environment.swift b/swiftpm/Sources/Basics/Environment/Environment.swift +--- a/swiftpm/Sources/Basics/Environment/Environment.swift ++++ b/swiftpm/Sources/Basics/Environment/Environment.swift +@@ -19,8 +19,8 @@ + #elseif os(Windows) + import CRT + import WinSDK +-#elseif canImport(Bionic) +-import Bionic ++#elseif canImport(Android) ++import Android + #else + import Darwin.C + #endif +diff --git a/swiftpm/Sources/Commands/SwiftRunCommand.swift b/swiftpm/Sources/Commands/SwiftRunCommand.swift +--- a/swiftpm/Sources/Commands/SwiftRunCommand.swift ++++ b/swiftpm/Sources/Commands/SwiftRunCommand.swift +@@ -9,6 +9,9 @@ + // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors + // + //===----------------------------------------------------------------------===// ++#if canImport(Android) ++import Android ++#endif + + import ArgumentParser + import Basics +diff --git a/swiftpm/Sources/PackagePlugin/Plugin.swift b/swiftpm/Sources/PackagePlugin/Plugin.swift +--- a/swiftpm/Sources/PackagePlugin/Plugin.swift ++++ b/swiftpm/Sources/PackagePlugin/Plugin.swift +@@ -36,6 +36,8 @@ + return String(decodingCString: baseAddress, as: UTF16.self) + } + } ++#elseif canImport(Android) ++import Android + #endif + + // diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap index 085056de..1ded1a90 100755 --- a/swiftpm/Utilities/bootstrap @@ -71,3 +188,18 @@ index 085056de..1ded1a90 100755 cross_compile_hosts = args.cross_compile_hosts if cross_compile_hosts: +diff --git a/yams/Sources/Yams/Representer.swift b/yams/Sources/Yams/Representer.swift +index a749c52..b74ef8e 100644 +--- a/yams/Sources/Yams/Representer.swift ++++ b/yams/Sources/Yams/Representer.swift +@@ -14,6 +14,10 @@ private let cpow: (_: Double, _: Double) -> Double = Darwin.pow + #elseif os(Windows) + import ucrt + private let cpow: (_: Double, _: Double) -> Double = ucrt.pow ++#elseif canImport(Bionic) ++import CoreFoundation ++import Bionic ++private let cpow: (_: Double, _: Double) -> Double = Bionic.pow + #else + import CoreFoundation + import Glibc diff --git a/swift-android-foundation-armv7-except-trunk.patch b/swift-android-foundation-armv7-except-trunk.patch new file mode 100644 index 00000000..6dd3fa7a --- /dev/null +++ b/swift-android-foundation-armv7-except-trunk.patch @@ -0,0 +1,168 @@ +commit ad6ca71b4eef90e3ae69b130e3cc989a21192020 +Author: Alex Lorenz +Date: Wed Aug 14 10:56:25 2024 -0700 + + [android] fix the LP32 armv7/i686 android build (#846) + + * [android] fix the LP32 armv7/i686 android build + + * Update Sources/FoundationEssentials/Android+Extensions.swift + + Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com> + + * drop the android Lp32 specific operator & + + --------- + + Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com> + +diff --git a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift +index 2540b14..a779837 100644 +--- a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift ++++ b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift +@@ -325,7 +325,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma + } + + let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max) +- let fileType = filestat.st_mode & S_IFMT ++ let fileType = mode_t(filestat.st_mode) & S_IFMT + #if !NO_FILESYSTEM + let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options) + #else +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift +index 991c5e8..d3e6de3 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift +@@ -221,7 +221,7 @@ internal struct _FileManagerImpl { + var statBuf = stat() + let fd = open(path, 0, 0) + guard fd >= 0 else { return nil } +- if fstat(fd, &statBuf) < 0 || statBuf.st_mode & S_IFMT == S_IFDIR { ++ if fstat(fd, &statBuf) < 0 || mode_t(statBuf.st_mode) & S_IFMT == S_IFDIR { + close(fd) + return nil + } +@@ -240,7 +240,7 @@ internal struct _FileManagerImpl { + } + + /* check for being same type */ +- if myInfo.st_mode & S_IFMT != otherInfo.st_mode & S_IFMT { ++ if mode_t(myInfo.st_mode) & S_IFMT != mode_t(otherInfo.st_mode) & S_IFMT { + return false + } + +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +index b8cd50a..bee9fb3 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +@@ -175,7 +175,8 @@ extension stat { + } + + fileprivate var fileAttributes: [FileAttributeKey : Any] { +- let fileType = st_mode.fileType ++ // On 32 bit Android, st_mode is UInt32. ++ let fileType = mode_t(st_mode).fileType + var result: [FileAttributeKey : Any] = [ + .size : _writeFileAttributePrimitive(st_size, as: UInt.self), + .modificationDate : modificationDate, +@@ -400,7 +401,7 @@ extension _FileManagerImpl { + guard stat(rep, &fileInfo) == 0 else { + return (false, false) + } +- let isDir = (fileInfo.st_mode & S_IFMT) == S_IFDIR ++ let isDir = (mode_t(fileInfo.st_mode) & S_IFMT) == S_IFDIR + return (true, isDir) + } + #endif +@@ -479,7 +480,7 @@ extension _FileManagerImpl { + return false + } + +- if ((dirInfo.st_mode & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) { ++ if ((mode_t(dirInfo.st_mode) & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) { + // its sticky so verify that we own the file + // otherwise we answer YES on the principle that if + // we create files we can delete them +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift +index 9bac967..e531cb5 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift +@@ -49,19 +49,19 @@ extension FILETIME { + #if !os(Windows) + extension stat { + var isDirectory: Bool { +- (self.st_mode & S_IFMT) == S_IFDIR ++ (mode_t(self.st_mode) & S_IFMT) == S_IFDIR + } + + var isRegular: Bool { +- (self.st_mode & S_IFMT) == S_IFREG ++ (mode_t(self.st_mode) & S_IFMT) == S_IFREG + } + + var isSymbolicLink: Bool { +- (self.st_mode & S_IFMT) == S_IFLNK ++ (mode_t(self.st_mode) & S_IFMT) == S_IFLNK + } + + var isSpecial: Bool { +- let type = self.st_mode & S_IFMT ++ let type = mode_t(self.st_mode) & S_IFMT + return type == S_IFBLK || type == S_IFCHR + } + } +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift +index 2c9a02f..500da1d 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift +@@ -367,7 +367,7 @@ struct _POSIXDirectoryContentsSequence: Sequence { + let statDir = directoryPath + "/" + fileName + if stat(statDir, &statBuf) == 0 { + // #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +- if (statBuf.st_mode & S_IFMT) == S_IFDIR { ++ if (mode_t(statBuf.st_mode) & S_IFMT) == S_IFDIR { + isDirectory = true + } + } +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift +index 03adcc6..92e609f 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift +@@ -867,7 +867,7 @@ enum _FileOperations { + defer { close(dstfd) } + + // Set the file permissions using fchmod() instead of when open()ing to avoid umask() issues +- let permissions = fileInfo.st_mode & ~S_IFMT ++ let permissions = mode_t(fileInfo.st_mode) & ~S_IFMT + guard fchmod(dstfd, permissions) == 0 else { + try delegate.throwIfNecessary(errno, String(cString: srcPtr), String(cString: dstPtr)) + return +diff --git a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +index 2e809fa..d01ca3f 100644 +--- a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift ++++ b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +@@ -198,7 +198,10 @@ final class _ProcessInfo: Sendable { + } + + var fullUserName: String { +-#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl) ++#if os(Android) && (arch(i386) || arch(arm)) ++ // On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL. ++ return "" ++#elseif canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl) + let (euid, _) = Platform.getUGIDs() + if let upwd = getpwuid(euid), + let fullname = upwd.pointee.pw_gecos { +diff --git a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift +index 477d5d3..1ce75d6 100644 +--- a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift ++++ b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift +@@ -737,7 +737,7 @@ extension String { + if lstat(buffer.baseAddress!, &statBuf) < 0 { + return nil + } +- if statBuf.st_mode & S_IFMT == S_IFLNK { ++ if mode_t(statBuf.st_mode) & S_IFMT == S_IFLNK { + /* Examples: + * fspath == /foo/bar0baz/quux/froboz + * linkx == /tic/tac/toe diff --git a/swift-android-foundation-devel.patch b/swift-android-foundation-devel.patch new file mode 100644 index 00000000..2b43da64 --- /dev/null +++ b/swift-android-foundation-devel.patch @@ -0,0 +1,26 @@ +diff --git a/swift-corelibs-foundation/Sources/Testing/Testing.swift b/swift-corelibs-foundation/Sources/Testing/Testing.swift +index 712d9dee..2483c14e 100644 +--- a/swift-corelibs-foundation/Sources/Testing/Testing.swift ++++ b/swift-corelibs-foundation/Sources/Testing/Testing.swift +@@ -11,6 +11,8 @@ + import Glibc + #elseif canImport(Musl) + import Musl ++#elseif canImport(Bionic) ++import Bionic + #elseif os(WASI) + import WASILibc + #elseif canImport(CRT) +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +index 9cd97525a..b5050a18c 100644 +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift +@@ -955,6 +955,8 @@ extension _FileManagerImpl { + #if os(WASI) + // WASI does not support extended attributes + throw CocoaError.errorWithFilePath(.featureUnsupported, path) ++ #elseif canImport(Android) ++ // Android doesn't allow setting this for normal apps, so just skip it. + #else + try Self._setAttributes(extendedAttrs, at: fileSystemRepresentation, followSymLinks: false) + #endif diff --git a/swift-android-foundation-except-trunk.patch b/swift-android-foundation-except-trunk.patch new file mode 100644 index 00000000..ce8830bd --- /dev/null +++ b/swift-android-foundation-except-trunk.patch @@ -0,0 +1,272 @@ +From d7239ae4001af292087c45dd46513285aba4ab34 +Date: Tue, 17 Sep 2024 21:10:40 +0530 +Subject: [PATCH] [Android] Enable more code and tests (#871) + +* [Android] Enable more code and tests + +while disabling setting extended file attributes and a test creating a hard link, +features not normally allowed on Android. + +* Remove incorrect WASI check + +diff --git a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift +index 48b95214d..612681d2d 100644 +--- a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift ++++ b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift +@@ -34,7 +34,7 @@ import WASILibc + func _fgetxattr(_ fd: Int32, _ name: UnsafePointer!, _ value: UnsafeMutableRawPointer!, _ size: Int, _ position: UInt32, _ options: Int32) -> Int { + #if canImport(Darwin) + return fgetxattr(fd, name, value, size, position, options) +-#elseif canImport(Glibc) || canImport(Musl) ++#elseif canImport(Glibc) || canImport(Musl) || canImport(Android) + return fgetxattr(fd, name, value, size) + #else + return -1 +@@ -355,7 +355,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma + let localProgress = (reportProgress && Progress.current() != nil) ? Progress(totalUnitCount: Int64(fileSize)) : nil + + if fileSize == 0 { +- #if os(Linux) ++ #if os(Linux) || os(Android) + // Linux has some files that may report a size of 0 but actually have contents + let chunkSize = 1024 * 4 + var buffer = malloc(chunkSize)! +diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift +--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift ++++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift +@@ -169,7 +169,7 @@ + return + } + +- state = [UnsafeMutablePointer(mutating: path), nil].withUnsafeBufferPointer { dirList in ++ state = [UnsafeMutablePointer(mutating: path), unsafeBitCast(0, to: UnsafeMutablePointer.self)].withUnsafeBufferPointer { dirList in + guard let stream = fts_open(dirList.baseAddress!, opts, nil) else { + return .error(errno, String(cString: path)) + } +diff --git a/swift-foundation/Sources/FoundationEssentials/Platform.swift b/swift-foundation/Sources/FoundationEssentials/Platform.swift +index 4549a4524..0a0aaa393 100644 +--- a/swift-foundation/Sources/FoundationEssentials/Platform.swift ++++ b/swift-foundation/Sources/FoundationEssentials/Platform.swift +@@ -192,7 +192,7 @@ extension Platform { + extension Platform { + @discardableResult + package static func copyCString(dst: UnsafeMutablePointer, src: UnsafePointer, size: Int) -> Int { +- #if canImport(Darwin) ++ #if canImport(Darwin) || canImport(Android) + return strlcpy(dst, src, size) + #else + // Glibc doesn't support strlcpy +@@ -267,7 +267,7 @@ extension Platform { + return String(cString: buffer.baseAddress!).standardizingPath + #endif + } +-#elseif os(Linux) ++#elseif os(Linux) || os(Android) + // For Linux, read /proc/self/exe + return try? FileManager.default.destinationOfSymbolicLink( + atPath: "/proc/self/exe").standardizingPath +diff --git a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +index eb55c273d..bb487c7f5 100644 +--- a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift ++++ b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift +@@ -437,7 +437,7 @@ extension _ProcessInfo { + var siInfo = SYSTEM_INFO() + GetSystemInfo(&siInfo) + return Int(siInfo.dwNumberOfProcessors) +-#elseif os(Linux) || os(FreeBSD) ++#elseif os(Linux) || os(FreeBSD) || canImport(Android) + return Int(sysconf(Int32(_SC_NPROCESSORS_CONF))) + #else + return 1 +@@ -454,7 +454,7 @@ extension _ProcessInfo { + return 0 + } + return Int(count) +-#elseif os(Linux) || os(FreeBSD) ++#elseif os(Linux) || os(FreeBSD) || canImport(Android) + #if os(Linux) + if let fsCount = Self.fsCoreCount() { + return fsCount +@@ -548,7 +548,7 @@ extension _ProcessInfo { + return 0 + } + return totalMemoryKB * 1024 +-#elseif os(Linux) || os(FreeBSD) ++#elseif os(Linux) || os(FreeBSD) || canImport(Android) + var memory = sysconf(Int32(_SC_PHYS_PAGES)) + memory *= sysconf(Int32(_SC_PAGESIZE)) + return UInt64(memory) +diff --git a/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift b/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift +index 744d77b3b..efb8d678f 100644 +--- a/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift ++++ b/swift-foundation/Sources/FoundationEssentials/TimeZone/TimeZone_Cache.swift +@@ -173,7 +173,7 @@ struct TimeZoneCache : Sendable { + } + } + +-#if os(Linux) && !os(WASI) ++#if os(Linux) + // Try localtime + tzset() + var t = time(nil) +diff --git a/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift +index 5087168ac..6b9ecf3f4 100644 +--- a/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift ++++ b/swift-foundation/Tests/FoundationEssentialsTests/DataIOTests.swift +@@ -238,7 +238,7 @@ class DataIOTests : XCTestCase { + } + + func test_zeroSizeFile() throws { +- #if !os(Linux) ++ #if !os(Linux) && !os(Android) + throw XCTSkip("This test is only applicable on Linux") + #else + // Some files in /proc report a file size of 0 bytes via a stat call +diff --git a/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift +index 7eae4692f..88428bfef 100644 +--- a/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift ++++ b/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift +@@ -1837,7 +1837,7 @@ extension DataTests { + } + + func testEOPNOTSUPP() throws { +- #if !canImport(Darwin) && !os(Linux) ++ #if !canImport(Darwin) && !os(Linux) && !os(Android) + throw XCTSkip("POSIXError.Code is not supported on this platform") + #else + // Opening a socket via open(2) on Darwin can result in the EOPNOTSUPP error code +diff --git a/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift +index a25638ab4..62dc23260 100644 +--- a/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift ++++ b/swift-foundation/Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift +@@ -23,6 +23,10 @@ import TestSupport + @testable import Foundation + #endif + ++#if canImport(Android) ++import Android ++#endif ++ + extension FileManager { + fileprivate var delegateCaptures: DelegateCaptures { + (self.delegate as! CapturingFileManagerDelegate).captures +@@ -329,8 +333,13 @@ final class FileManagerTests : XCTestCase { + XCTAssertTrue($0.delegateCaptures.isEmpty) + try $0.linkItem(atPath: "foo", toPath: "bar") + XCTAssertEqual($0.delegateCaptures.shouldLink, [.init("foo", "bar")]) ++ #if os(Android) // Hard links are not normally allowed on Android. ++ XCTAssertEqual($0.delegateCaptures.shouldProceedAfterLinkError, [.init("foo", "bar", code: .fileWriteNoPermission)]) ++ XCTAssertFalse($0.fileExists(atPath: "bar")) ++ #else + XCTAssertEqual($0.delegateCaptures.shouldProceedAfterLinkError, []) + XCTAssertTrue($0.fileExists(atPath: "bar")) ++ #endif + } + + try FileManagerPlayground { +diff --git a/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift +index 340b21a4a..d0972b537 100644 +--- a/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift ++++ b/swift-foundation/Tests/FoundationEssentialsTests/PredicateTests.swift +@@ -364,7 +364,7 @@ final class PredicateTests: XCTestCase { + func testRegex_RegexBuilder() throws { + #if !canImport(RegexBuilder) + throw XCTSkip("RegexBuilder is unavavailable on this platform") +- #elseif !os(Linux) && !FOUNDATION_FRAMEWORK ++ #elseif !os(Linux) && !os(Android) && !FOUNDATION_FRAMEWORK + // Disable this test in swift-foundation macOS CI because of incorrect availability annotations in the StringProcessing module + throw XCTSkip("This test is currently disabled on this platform") + #else +diff --git a/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift b/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift +index 1e73a9fbf..5b2cc36cf 100644 +--- a/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift ++++ b/swift-foundation/Tests/FoundationEssentialsTests/ProcessInfoTests.swift +@@ -115,7 +115,7 @@ final class ProcessInfoTests : XCTestCase { + let expectedMinMajorVersion = 2 + #endif + XCTAssertGreaterThanOrEqual(version.majorVersion, expectedMinMajorVersion, "Unrealistic major system version") +- #elseif os(Windows) || os(Linux) ++ #elseif os(Windows) || os(Linux) || os(Android) + let minVersion = OperatingSystemVersion(majorVersion: 1, minorVersion: 0, patchVersion: 0) + XCTAssertTrue(ProcessInfo.processInfo.isOperatingSystemAtLeast(minVersion)) + #else +@@ -171,7 +171,7 @@ final class ProcessInfoTests : XCTestCase { + func testProcessName() { + #if FOUNDATION_FRAMEWORK + let targetName = "TestHost" +-#elseif os(Linux) || os(Windows) ++#elseif os(Linux) || os(Windows) || os(Android) + let targetName = "FoundationPreviewPackageTests.xctest" + #else + let targetName = "xctest" +diff --git a/swift-corelibs-foundation/Package.swift b/swift-corelibs-foundation/Package.swift +--- a/swift-corelibs-foundation/Package.swift ++++ b/swift-corelibs-foundation/Package.swift +@@ -176,7 +176,8 @@ + "BlockRuntime", + "CMakeLists.txt" + ], +- cSettings: coreFoundationBuildSettings ++ cSettings: coreFoundationBuildSettings, ++ linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))] + ), + .target( + name: "_CFXMLInterface", +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +index e89b3bf6..a82fe1c2 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +@@ -347,10 +351,17 @@ + do { + guard fm.fileExists(atPath: _url.path) else { throw _NSErrorWithErrno(ENOENT, reading: true, url: url) } + _stream = try FileManager.default._fileSystemRepresentation(withPath: _url.path) { fsRep in ++#if canImport(Android) ++ let ps = UnsafeMutablePointer>.allocate(capacity: 2) ++ defer { ps.deallocate() } ++ ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) ++ ps.advanced(by: 1).initialize(to: unsafeBitCast(0, to: UnsafeMutablePointer.self)) ++#else + let ps = UnsafeMutablePointer?>.allocate(capacity: 2) + defer { ps.deallocate() } + ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) + ps.advanced(by: 1).initialize(to: nil) ++#endif + return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) + } + if _stream == nil { +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift +--- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift +@@ -19,6 +19,8 @@ + get { WASILibc.errno } + set { WASILibc.errno = newValue } + } ++#elseif os(Android) ++import Android + #endif + + #if os(Windows) +commit 3506f58a89de211823dcee98eb698dfcc1414fc5 +Author: Yuta Saito +Date: Wed Aug 7 05:10:42 2024 +0000 + + [CMake] Use LIBXML2_INCLUDE_DIR instead of hardcoding /usr/include/libxml2 + + `find_package(LibXml2 REQUIRED)` sets `LIBXML2_INCLUDE_DIR` to the correct + include directory for the libxml2 headers. Use this variable instead of + hardcoding `/usr/include/libxml2`. This allows the build to work with + custom libxml2 builds on WASI. + +diff --git a/swift-corelibs-foundation/Sources/_CFXMLInterface/CMakeLists.txt b/swift-corelibs-foundation/Sources/_CFXMLInterface/CMakeLists.txt +index d6e63a3f..d550a520 100644 +--- a/swift-corelibs-foundation/Sources/_CFXMLInterface/CMakeLists.txt ++++ b/swift-corelibs-foundation/Sources/_CFXMLInterface/CMakeLists.txt +@@ -20,7 +20,7 @@ target_include_directories(_CFXMLInterface + ../CoreFoundation/include + PRIVATE + ../CoreFoundation/internalInclude +- /usr/include/libxml2/) ++ ${LIBXML2_INCLUDE_DIR}) + + target_compile_options(_CFXMLInterface INTERFACE + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>" diff --git a/swift-android-foundation-ndk26.patch b/swift-android-foundation-ndk26.patch deleted file mode 100644 index 7dac5655..00000000 --- a/swift-android-foundation-ndk26.patch +++ /dev/null @@ -1,158 +0,0 @@ -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -index d90ece91..d2bbd22b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -@@ -741,9 +741,15 @@ extension FileManager { - if rmdir(fsRep) == 0 { - return - } else if errno == ENOTEMPTY { -+ #if os(Android) -+ let ps = UnsafeMutablePointer>.allocate(capacity: 2) -+ ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) -+ ps.advanced(by: 1).initialize(to: unsafeBitCast(0, to: UnsafeMutablePointer.self)) -+ #else - let ps = UnsafeMutablePointer?>.allocate(capacity: 2) - ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) - ps.advanced(by: 1).initialize(to: nil) -+ #endif - let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) - ps.deinitialize(count: 2) - ps.deallocate() -@@ -1085,10 +1091,18 @@ extension FileManager { - do { - guard fm.fileExists(atPath: _url.path) else { throw _NSErrorWithErrno(ENOENT, reading: true, url: url) } - _stream = try FileManager.default._fileSystemRepresentation(withPath: _url.path) { fsRep in -+ #if os(Android) -+ let ps = UnsafeMutablePointer>.allocate(capacity: 2) -+ #else - let ps = UnsafeMutablePointer?>.allocate(capacity: 2) -+ #endif - defer { ps.deallocate() } - ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) -+ #if os(Android) -+ ps.advanced(by: 1).initialize(to: unsafeBitCast(0, to: UnsafeMutablePointer.self)) -+ #else - ps.advanced(by: 1).initialize(to: nil) -+ #endif - return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) - } - if _stream == nil { -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -index a538a297..0a757c4b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -@@ -310,9 +310,15 @@ open class FileHandle : NSObject { - let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0) - // Swift does not currently expose MAP_FAILURE - if data != UnsafeMutableRawPointer(bitPattern: -1) { -+ #if os(Android) -+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in -+ munmap(buffer, length) -+ } -+ #else - return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in - munmap(buffer, length) - } -+ #endif - } - } - -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -index d90ece91..d2bbd22b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -@@ -741,13 +741,13 @@ extension FileManager { - ps.deinitialize(count: 2) - ps.deallocate() - -- if stream != nil { -+ if let openStream = stream { - defer { -- fts_close(stream) -+ fts_close(openStream) - } - -- while let current = fts_read(stream)?.pointee { -- let itemPath = string(withFileSystemRepresentation: current.fts_path, length: Int(current.fts_pathlen)) -+ while let current = fts_read(openStream)?.pointee, let current_path = current.fts_path { -+ let itemPath = string(withFileSystemRepresentation: current_path, length: Int(current.fts_pathlen)) - guard alreadyConfirmed || shouldRemoveItemAtPath(itemPath, isURL: isURL) else { - continue - } -@@ -762,11 +768,11 @@ extension FileManager { - do { - switch Int32(current.fts_info) { - case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE: -- if unlink(current.fts_path) == -1 { -+ if unlink(current_path) == -1 { - throw _NSErrorWithErrno(errno, reading: false, path: itemPath) - } - case FTS_DP: -- if rmdir(current.fts_path) == -1 { -+ if rmdir(current_path) == -1 { - throw _NSErrorWithErrno(errno, reading: false, path: itemPath) - } - case FTS_DNR, FTS_ERR, FTS_NS: -@@ -1135,14 +1149,14 @@ extension FileManager { - } - - _current = fts_read(stream) -- while let current = _current { -- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen)) -+ while let current = _current, let current_path = current.pointee.fts_path { -+ let filename = FileManager.default.string(withFileSystemRepresentation: current_path, length: Int(current.pointee.fts_pathlen)) - - switch Int32(current.pointee.fts_info) { - case FTS_D: - let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true) - if skipDescendants { -- fts_set(_stream, _current, FTS_SKIP) -+ fts_set(stream, current, FTS_SKIP) - } - if showFile { - return URL(fileURLWithPath: filename, isDirectory: true) -@@ -1315,7 +1329,7 @@ extension FileManager { - let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in - return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in - // This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard. -- if rename(newItemFS, originalFS) == 0 { -+ if let newFS = newItemFS, let origFS = originalFS, rename(newFS, origFS) == 0 { - return nil - } else { - return errno -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -index 1aa3038a..9fdb495c 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -@@ -568,13 +568,13 @@ open class FileManager : NSObject { - let attributes = try windowsFileAttributes(atPath: path) - let type = FileAttributeType(attributes: attributes, atPath: path) - #else -- if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil { -- let name = String(cString: pwd.pointee.pw_name) -+ if let pwd = getpwuid(s.st_uid), let pwd_name = pwd.pointee.pw_name { -+ let name = String(cString: pwd_name) - result[.ownerAccountName] = name - } - -- if let grd = getgrgid(s.st_gid), grd.pointee.gr_name != nil { -- let name = String(cString: grd.pointee.gr_name) -+ if let grd = getgrgid(s.st_gid), let grd_name = grd.pointee.gr_name { -+ let name = String(cString: grd_name) - result[.groupOwnerAccountName] = name - } - -diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift -index 5fe7b29c..ce571abe 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Host.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift -@@ -25,7 +25,8 @@ import WinSDK - - // getnameinfo uses size_t for its 4th and 6th arguments. - private func getnameinfo(_ addr: UnsafePointer?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { -- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) -+ guard let saddr = addr else { return -1 } -+ return Glibc.getnameinfo(saddr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) - } - - // getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically. diff --git a/swift-android-foundation-trunk.patch b/swift-android-foundation-trunk.patch index a5d0bf31..d7b8cc76 100644 --- a/swift-android-foundation-trunk.patch +++ b/swift-android-foundation-trunk.patch @@ -1,132 +1,79 @@ -commit 7e5350751e17515253c096350dddd3aeeda0eee2 -Author: Evan Wilde -Date: Tue Jul 9 22:45:20 2024 -0700 - - Workaround broken glibc modulemap - - We have been running into modularization issues on newer versions of - various Linux distros, resulting in the compiler saying that the Glibc - module doesn't have a SOCK_STREAM or SOCK_DGRAM. From some poking - around, the definition is now coming from the CoreFoundation module as - far as Swift is concerned. This is ultimately because our modulemap for - Glibc is bad, but also means that I can't bring up Swift 6 on all of the - Linux distros that 5.10 has support for. - - This workaround removes the explicit module name from `SOCK_STREAM` and - renames it to `FOUNDATION_SOCK_STREAM` to avoid an ambiguous name, and - completely removes `SOCK_DGRAM`. - - Both SOCK_STREAM and SOCK_DGRAM are fileprivates, so changing them will - have no visible external effect. It is true that if another header - somewhere defines `SOCK_STREAM`, we may pick it up instead of the - definition from the glibc module, but that will also cause some nasty - surprises to anyone using that header in C, so it is unlikely. - - Fixes: rdar://128079849 - -diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift -index c53263f0..f06f95a9 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Port.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift -@@ -90,18 +90,22 @@ open class SocketPort: Port {} +diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl +index 16e05052609..7ab8cebfab8 100755 +--- a/swift/utils/build-script-impl ++++ b/swift/utils/build-script-impl +@@ -2622,6 +2622,7 @@ for host in "${ALL_HOSTS[@]}"; do + echo "Cleaning the libdispatch build directory" + call rm -rf "${LIBDISPATCH_BUILD_DIR}" + fi ++ call ln -sf "${SWIFT_BUILD_PATH}/lib/swift" "${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib" - #else - -+#if canImport(Darwin) -+import Darwin -+fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM -+fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP -+#endif -+ - #if canImport(Glibc) && !os(Android) && !os(OpenBSD) - import Glibc --fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue) --fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM.rawValue) --fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP) -+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue) -+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) + cmake_options=( + -DENABLE_SWIFT=YES +diff --git a/swift-corelibs-foundation/Package.swift b/swift-corelibs-foundation/Package.swift +index 2b5b5e05..60f1dde8 100644 +--- a/swift-corelibs-foundation/Package.swift ++++ b/swift-corelibs-foundation/Package.swift +@@ -245,7 +245,8 @@ let package = Package( + "BlockRuntime", + "CMakeLists.txt" + ], +- cSettings: coreFoundationBuildSettings ++ cSettings: coreFoundationBuildSettings, ++ linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))] + ), + .target( + name: "BlocksRuntime", +@@ -262,7 +263,7 @@ let package = Package( + name: "_CFXMLInterface", + dependencies: [ + "CoreFoundation", +- .target(name: "Clibxml2", condition: .when(platforms: [.linux])), ++ .target(name: "Clibxml2", condition: .when(platforms: [.linux, .android])), + ], + path: "Sources/_CFXMLInterface", + exclude: [ +@@ -275,7 +276,7 @@ let package = Package( + name: "_CFURLSessionInterface", + dependencies: [ + "CoreFoundation", +- .target(name: "Clibcurl", condition: .when(platforms: [.linux])), ++ .target(name: "Clibcurl", condition: .when(platforms: [.linux, .android])), + ], + path: "Sources/_CFURLSessionInterface", + exclude: [ +@@ -348,7 +349,7 @@ let package = Package( + "FoundationNetworking", + "XCTest", + "Testing", +- .target(name: "xdgTestHelper", condition: .when(platforms: [.linux])) ++ .target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android])) + ], + resources: [ + .copy("Foundation/Resources") +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift +index 8043ef00..23b602f6 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift +@@ -10,6 +10,8 @@ + @_implementationOnly import CoreFoundation + #if os(Windows) + import WinSDK ++#elseif canImport(Android) ++import Android + #elseif os(WASI) + import WASILibc #endif - - #if canImport(Glibc) && os(Android) || os(OpenBSD) +diff --git a/swift-corelibs-foundation/Sources/Testing/Testing.swift b/swift-corelibs-foundation/Sources/Testing/Testing.swift +index 712d9dee..2483c14e 100644 +--- a/swift-corelibs-foundation/Sources/Testing/Testing.swift ++++ b/swift-corelibs-foundation/Sources/Testing/Testing.swift +@@ -11,6 +11,8 @@ import Glibc --fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM) --fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM) --fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP) -+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) -+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) - fileprivate let INADDR_ANY: in_addr_t = 0 - #if os(OpenBSD) - fileprivate let INADDR_LOOPBACK = 0x7f000001 -@@ -123,7 +127,8 @@ import WinSDK - fileprivate typealias sa_family_t = ADDRESS_FAMILY - fileprivate typealias in_port_t = USHORT - fileprivate typealias in_addr_t = UInt32 --fileprivate let IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue) -+fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM -+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue) - #endif - - // MARK: Darwin representation of socket addresses -@@ -484,7 +489,7 @@ open class SocketPort : Port { - - let data = withUnsafeBytes(of: address) { Data($0) } - -- self.init(protocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) -+ self.init(protocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) - } - - private final func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) { -@@ -500,7 +505,7 @@ open class SocketPort : Port { - var context = CFSocketContext() - context.info = Unmanaged.passUnretained(self).toOpaque() - var s: CFSocket -- if type == SOCK_STREAM { -+ if type == FOUNDATION_SOCK_STREAM { - s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context) - } else { - s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context) -@@ -519,7 +524,7 @@ open class SocketPort : Port { - var context = CFSocketContext() - context.info = Unmanaged.passUnretained(self).toOpaque() - var s: CFSocket -- if type == SOCK_STREAM { -+ if type == FOUNDATION_SOCK_STREAM { - s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context) - } else { - s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context) -@@ -543,7 +548,7 @@ open class SocketPort : Port { - sinAddr.sin_addr = inAddr - - let data = withUnsafeBytes(of: sinAddr) { Data($0) } -- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) -+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) - return - } - } -@@ -556,7 +561,7 @@ open class SocketPort : Port { - sinAddr.sin6_addr = in6Addr - - let data = withUnsafeBytes(of: sinAddr) { Data($0) } -- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) -+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) - return - } - } -@@ -573,7 +578,7 @@ open class SocketPort : Port { - withUnsafeBytes(of: in_addr_t(INADDR_LOOPBACK).bigEndian) { buffer.copyMemory(from: $0) } - } - let data = withUnsafeBytes(of: sinAddr) { Data($0) } -- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) -+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) - } - - private static let remoteSocketCoresLock = NSLock() -@@ -1049,7 +1054,7 @@ open class SocketPort : Port { - if let connector = core.connectors[signature], CFSocketIsValid(connector) { - return connector - } else { -- if signature.socketType == SOCK_STREAM { -+ if signature.socketType == FOUNDATION_SOCK_STREAM { - if let connector = CFSocketCreate(nil, socketKind.protocolFamily, socketKind.socketType, socketKind.protocol, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketData, &context), CFSocketIsValid(connector) { - var timeout = time - Date.timeIntervalSinceReferenceDate - if timeout < 0 || timeout >= SocketPort.maximumTimeout { + #elseif canImport(Musl) + import Musl ++#elseif canImport(Bionic) ++import Bionic + #elseif os(WASI) + import WASILibc + #elseif canImport(CRT) diff --git a/swift-android-foundation.patch b/swift-android-foundation.patch new file mode 100644 index 00000000..7734ccc3 --- /dev/null +++ b/swift-android-foundation.patch @@ -0,0 +1,336 @@ +diff --git a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h +index a2ba56cd..91a312dc 100644 +--- a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h ++++ b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h +@@ -69,6 +69,13 @@ + #include + #include + #include ++#include ++#ifdef __swift__ ++// The linux/stat header is private in the Android modulemap. ++#pragma clang module import posix_filesystem.linux_stat ++#else ++#include ++#endif + #elif TARGET_OS_WASI + #include + #include +diff --git a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift +index ffe3a6c6..c59977f8 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift +@@ -7,6 +7,10 @@ + // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors + // + ++#if canImport(Android) ++import Android ++#endif ++ + @frozen + public struct CGFloat: Sendable { + #if arch(i386) || arch(arm) || arch(wasm32) +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift +index b07c49ac..b540e284 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift +@@ -34,6 +34,11 @@ import WASILibc + fileprivate let _read = WASILibc.read(_:_:_:) + fileprivate let _write = WASILibc.write(_:_:_:) + fileprivate let _close = WASILibc.close(_:) ++#elseif canImport(Android) ++import Android ++fileprivate let _read = Android.read(_:_:_:) ++fileprivate let _write = Android.write(_:_:_:) ++fileprivate let _close = Android.close(_:) + #endif + + #if canImport(WinSDK) +@@ -321,10 +326,15 @@ open class FileHandle : NSObject, @unchecked Sendable { + if options.contains(.alwaysMapped) { + // Filesizes are often 64bit even on 32bit systems + let mapSize = min(length, Int(clamping: statbuf.st_size)) ++ #if canImport(Android) ++ // Bionic mmap() now returns _Nonnull, so the force unwrap below isn't needed. + let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0) ++ #else ++ let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)! ++ #endif + // Swift does not currently expose MAP_FAILURE + if data != UnsafeMutableRawPointer(bitPattern: -1) { +- return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in ++ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in + munmap(buffer, length) + } + } +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +index e89b3bf6..a82fe1c2 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +@@ -7,6 +7,10 @@ + // + #if !os(Windows) + ++#if canImport(Android) ++import Android ++#endif ++ + #if os(Android) && (arch(i386) || arch(arm)) // struct stat.st_mode is UInt32 + internal func &(left: UInt32, right: mode_t) -> mode_t { + return mode_t(left) & right +@@ -398,13 +402,13 @@ extension FileManager { + + _current = fts_read(stream) + while let current = _current { +- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen)) ++ let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path!, length: Int(current.pointee.fts_pathlen)) + + switch Int32(current.pointee.fts_info) { + case FTS_D: + let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true) + if skipDescendants { +- fts_set(_stream, _current, FTS_SKIP) ++ fts_set(stream, current, FTS_SKIP) + } + if showFile { + return URL(fileURLWithPath: filename, isDirectory: true) +@@ -578,7 +582,7 @@ extension FileManager { + let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in + return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in + // This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard. +- if rename(newItemFS, originalFS) == 0 { ++ if rename(newItemFS!, originalFS!) == 0 { + return nil + } else { + return errno +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift +index a5d75820..a19464d7 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift +@@ -21,6 +21,8 @@ import WinSDK + + #if os(WASI) + import WASILibc ++#elseif canImport(Bionic) ++import Bionic + #endif + + #if os(Windows) +diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift +index 6c4f5291..fb130631 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Host.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift +@@ -12,8 +12,9 @@ + import WinSDK + #endif + +-#if os(Android) +- // Android Glibc differs a little with respect to the Linux Glibc. ++#if canImport(Android) ++ import Android ++ // Android Bionic differs a little with respect to the Linux Glibc. + + // IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to + // convert to UInt32. +@@ -24,8 +25,8 @@ import WinSDK + } + + // getnameinfo uses size_t for its 4th and 6th arguments. +- private func getnameinfo(_ addr: UnsafePointer?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { +- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) ++ private func getnameinfo(_ addr: UnsafePointer, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { ++ return Android.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) + } + + // getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically. +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSData.swift b/swift-corelibs-foundation/Sources/Foundation/NSData.swift +index ae54f971..65eb0d93 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSData.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSData.swift +@@ -11,6 +11,9 @@ + #if !os(WASI) + import Dispatch + #endif ++#if canImport(Android) ++import Android ++#endif + + extension NSData { + public typealias ReadingOptions = Data.ReadingOptions +@@ -469,6 +472,8 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { + let createMode = Int(Musl.S_IRUSR) | Int(Musl.S_IWUSR) | Int(Musl.S_IRGRP) | Int(Musl.S_IWGRP) | Int(Musl.S_IROTH) | Int(Musl.S_IWOTH) + #elseif canImport(WASILibc) + let createMode = Int(WASILibc.S_IRUSR) | Int(WASILibc.S_IWUSR) | Int(WASILibc.S_IRGRP) | Int(WASILibc.S_IWGRP) | Int(WASILibc.S_IROTH) | Int(WASILibc.S_IWOTH) ++#elseif canImport(Android) ++ let createMode = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH) + #endif + guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else { + throw _NSErrorWithErrno(errno, reading: false, path: path) +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSError.swift b/swift-corelibs-foundation/Sources/Foundation/NSError.swift +index 6f21d3a0..dcd6f3f1 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSError.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSError.swift +@@ -16,6 +16,8 @@ import Darwin + import Glibc + #elseif canImport(CRT) + import CRT ++#elseif canImport(Android) ++import Android + #endif + + @_implementationOnly import CoreFoundation +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift +index fe1d08b7..9d0fadc9 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift +@@ -11,6 +11,8 @@ + + #if canImport(Glibc) + import Glibc ++#elseif canImport(Bionic) ++import Bionic + #endif + + #if os(Windows) +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift +index a1809026..5424f5bb 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift +@@ -10,6 +10,9 @@ + #if os(macOS) || os(iOS) + fileprivate let _NSPageSize = Int(vm_page_size) + #elseif os(Linux) || os(Android) || os(OpenBSD) ++#if canImport(Android) ++import Android ++#endif + fileprivate let _NSPageSize = Int(getpagesize()) + #elseif os(Windows) + import WinSDK +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift +index 03176c17..1509c31d 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift +@@ -19,6 +19,8 @@ internal import Synchronization + @_exported import Glibc + #elseif canImport(Musl) + @_exported import Musl ++#elseif canImport(Bionic) ++@_exported import Bionic + #elseif os(WASI) + @_exported import WASILibc + #elseif os(Windows) +diff --git a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift +index 6af73f16..9e6f20d0 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift +@@ -22,6 +22,8 @@ import Darwin + import Glibc + #elseif canImport(Musl) + import Musl ++#elseif canImport(Bionic) ++import Bionic + #endif + + // NOTE: this represents PLATFORM_PATH_STYLE +diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift +index c4ed8282..e71f591b 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Port.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift +@@ -107,7 +107,7 @@ fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM + fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP + #endif + +-#if canImport(Glibc) && !os(Android) && !os(OpenBSD) ++#if canImport(Glibc) && !os(OpenBSD) + import Glibc + fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue) + fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) +@@ -119,14 +119,19 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) + fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) + #endif + +-#if canImport(Glibc) && os(Android) || os(OpenBSD) ++#if canImport(Glibc) && os(OpenBSD) + import Glibc + fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) + fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) + fileprivate let INADDR_ANY: in_addr_t = 0 +-#if os(OpenBSD) + fileprivate let INADDR_LOOPBACK = 0x7f000001 + #endif ++ ++#if canImport(Android) ++import Android ++fileprivate let FOUNDATION_SOCK_STREAM = Int32(Android.SOCK_STREAM) ++fileprivate let FOUNDATION_IPPROTO_TCP = Int32(Android.IPPROTO_TCP) ++fileprivate let INADDR_ANY: in_addr_t = 0 + #endif + + +diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift +index ee35c23a..5e8cfbaa 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Process.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift +@@ -18,6 +18,8 @@ import struct WinSDK.HANDLE + + #if canImport(Darwin) + import Darwin ++#elseif canImport(Android) ++import Android + #endif + + internal import Synchronization +diff --git a/swift-corelibs-foundation/Sources/Foundation/Thread.swift b/swift-corelibs-foundation/Sources/Foundation/Thread.swift +index 5e79579c..0985a482 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Thread.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Thread.swift +@@ -17,6 +17,8 @@ import WinSDK + import Glibc + #elseif canImport(Musl) + import Musl ++#elseif canImport(Bionic) ++import Bionic + #endif + + // WORKAROUND_SR9811 +diff --git a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift +index e0d1cbbd..237c1daf 100644 +--- a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift ++++ b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift +@@ -15,6 +15,8 @@ import Foundation + + #if os(Windows) + import WinSDK ++#elseif canImport(Android) ++import Android + #endif + + public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable, Sendable { +diff --git a/swift-corelibs-foundation/Sources/plutil/main.swift b/swift-corelibs-foundation/Sources/plutil/main.swift +index 29316d16..29584596 100644 +--- a/swift-corelibs-foundation/Sources/plutil/main.swift ++++ b/swift-corelibs-foundation/Sources/plutil/main.swift +@@ -15,6 +15,9 @@ import Glibc + #elseif canImport(Musl) + import Foundation + import Musl ++#elseif canImport(Bionic) ++import Foundation ++import Bionic + #elseif canImport(CRT) + import Foundation + import CRT +diff --git a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift +index d515a63f..fb037e24 100644 +--- a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift ++++ b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift +@@ -19,6 +19,8 @@ import FoundationNetworking + #endif + #if os(Windows) + import WinSDK ++#elseif canImport(Android) ++import Android + #endif + + enum HelperCheckStatus : Int32 { diff --git a/swift-android-release-stdlib.patch b/swift-android-release-stdlib.patch deleted file mode 100644 index cec746c0..00000000 --- a/swift-android-release-stdlib.patch +++ /dev/null @@ -1,43 +0,0 @@ -diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -index 61447d50f08..b533b9291af 100644 ---- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -@@ -522,7 +522,11 @@ function(_add_target_variant_link_flags) - # We need to add the math library, which is linked implicitly by libc++ - list(APPEND result "-lm") - if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") -- file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*) -+ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "ndk/27") -+ file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*) -+ else() -+ file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*) -+ endif() - list(APPEND result "-resource-dir=${RESOURCE_DIR}") - endif() - -diff --git a/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift b/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift -index f8daa50325c..66be85a77f0 100644 ---- a/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift -+++ b/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift -@@ -131,6 +131,8 @@ public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) { - return _pipe(unsafeFds.baseAddress, 0, 0) - #elseif os(WASI) - preconditionFailure("No pipes available on WebAssembly/WASI") -+#elseif os(Android) -+ return pipe(unsafeFds.baseAddress!) - #else - return pipe(unsafeFds.baseAddress) - #endif -diff --git a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -index 1e4132f6279..045b8a28746 100644 ---- a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -+++ b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -@@ -61,7 +61,7 @@ SWIFT_READONLY - static inline int _swift_stdlib_memcmp(const void *s1, const void *s2, - __swift_size_t n) { - // FIXME: Is there a way to identify Glibc specifically? --#if defined(__gnu_linux__) -+#if defined(__gnu_linux__) || defined(__ANDROID__) - extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t); - #else - extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t); diff --git a/swift-android.patch b/swift-android.patch index 830f565c..cd079f61 100644 --- a/swift-android.patch +++ b/swift-android.patch @@ -1,3 +1,50 @@ +diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap +index 78e7bda9976..dc25e5c3668 100644 +--- a/swift/stdlib/public/Platform/android.modulemap ++++ b/swift/stdlib/public/Platform/android.modulemap +@@ -556,6 +556,12 @@ module _bits_sa_family_t [system] { + header "bits/sa_family_t.h" + export * + } ++ ++module _bits_sockaddr_storage [system] { ++ header "bits/sockaddr_storage.h" ++ export * ++} ++ + module _bits_stdatomic [system] { + // Note: this module is not part of 'stdatomic' + // as it depends on libc++ and forcing it to +diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl +index 16e05052609..114e768bdbb 100755 +--- a/swift/utils/build-script-impl ++++ b/swift/utils/build-script-impl +@@ -2412,7 +2412,7 @@ for host in "${ALL_HOSTS[@]}"; do + + ;; + foundation_macros) +- if [[ ${host} == "macosx"* ]]; then ++ if [[ ${host} == "macosx"* ]] || [[ "${host}" == "android-"* ]]; then + echo "Skipping Foundation Macros on OS X -- Foundation is part of the OS on this platform" + continue + fi +@@ -2601,6 +2601,7 @@ for host in "${ALL_HOSTS[@]}"; do + if [[ "${host}" == "android-"* ]]; then + cmake_options+=( + -DCMAKE_HAVE_LIBC_PTHREAD=True ++ -DSwiftFoundation_MODULE_TRIPLE:STRING="${ANDROID_ARCH}-unknown-linux-android" + ) + fi + ;; +@@ -3113,7 +3113,7 @@ for host in "${ALL_HOSTS[@]}"; do + ;; + foundation|foundation_static|foundation_macros) + # FIXME: Foundation doesn't build from the script on OS X +- if [[ ${host} == "macosx"* ]]; then ++ if [[ ${host} == "macosx"* ]] || [[ "${host}" == "android-"* && "${product}" == "foundation_macros" ]]; then + echo "Skipping Foundation on OS X -- Foundation does not build for this platform" + continue + fi diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py index 9932b854cb6..ad3ac757665 100644 --- a/swift/utils/swift_build_support/swift_build_support/targets.py @@ -16,20 +63,32 @@ index 9932b854cb6..ad3ac757665 100644 options.define('CMAKE_ANDROID_NDK:PATH', args.android_ndk) return options +diff --git a/swift-corelibs-foundation/CMakeLists.txt b/swift-corelibs-foundation/CMakeLists.txt +index 7f290d16..95366592 100644 +--- a/swift-corelibs-foundation/CMakeLists.txt ++++ b/swift-corelibs-foundation/CMakeLists.txt +@@ -55,6 +55,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) ++set(CMAKE_SHARED_LINKER_FLAGS "") + + option(BUILD_SHARED_LIBS "build shared libraries" ON) + diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt index 016bf294..5c42986a 100644 --- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt +++ b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt -@@ -167,6 +167,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) - $) - elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) - target_link_options(Foundation PRIVATE "SHELL:-no-toolchain-stdlib-rpath") +@@ -174,6 +174,12 @@ + target_link_libraries(Foundation PUBLIC + swiftDispatch) + endif() + if(${CMAKE_SYSTEM_NAME} STREQUAL Android) + target_link_libraries(Foundation PRIVATE android-spawn) + list(GET CMAKE_FIND_ROOT_PATH 0 SPAWN_DIR) + target_include_directories(Foundation PUBLIC ${SPAWN_DIR}/usr/include) + target_link_directories(Foundation PUBLIC ${SPAWN_DIR}/usr/lib) + endif() - endif() - + if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(Foundation PRIVATE "LINKER:--build-id=sha1") diff --git a/swift-crypto.patch b/swift-crypto.patch new file mode 100644 index 00000000..a4849044 --- /dev/null +++ b/swift-crypto.patch @@ -0,0 +1,14 @@ +diff --git a/swift-crypto/Sources/Crypto/Key Derivation/HKDF.swift b/swift-crypto/Sources/Crypto/Key Derivation/HKDF.swift +index 5f47c2f..4b5579e 100644 +--- a/swift-crypto/Sources/Crypto/Key Derivation/HKDF.swift ++++ b/swift-crypto/Sources/Crypto/Key Derivation/HKDF.swift +@@ -15,6 +15,9 @@ + @_exported import CryptoKit + #else + import Foundation ++#if canImport(Android) ++import Android ++#endif + + /// A standards-based implementation of an HMAC-based Key Derivation Function + /// (HKDF). diff --git a/swift-nio-filesystem-both-ndks.patch b/swift-nio-filesystem.patch similarity index 92% rename from swift-nio-filesystem-both-ndks.patch rename to swift-nio-filesystem.patch index 31e3ee00..1e3a6745 100644 --- a/swift-nio-filesystem-both-ndks.patch +++ b/swift-nio-filesystem.patch @@ -20,6 +20,32 @@ index 3fc7d561..50e0482a 100644 #else return "/tmp" #endif +diff --git a/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift b/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift +index 1e9c1661..2a4935e7 100644 +--- a/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift ++++ b/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift +@@ -454,12 +454,21 @@ internal func libc_confstr( + + /// fts(3) + #if os(Android) ++#if compiler(>=6.1) ++internal func libc_fts_open( ++ _ path: [UnsafeMutablePointer?], ++ _ options: CInt ++) -> UnsafeMutablePointer { ++ fts_open(path, options, nil)! ++} ++#else + internal func libc_fts_open( + _ path: [UnsafeMutablePointer], + _ options: CInt + ) -> UnsafeMutablePointer { + fts_open(path, options, nil)! + } ++#endif + #else + internal func libc_fts_open( + _ path: [UnsafeMutablePointer?], diff --git a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift b/Sources/NIOFileSystem/Internal/SystemFileHandle.swift index 3dc51872..49aeeeca 100644 --- a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift diff --git a/swift-nio-http2-test.patch b/swift-nio-http2-test.patch new file mode 100644 index 00000000..87c2c069 --- /dev/null +++ b/swift-nio-http2-test.patch @@ -0,0 +1,15 @@ +diff --git a/Tests/NIOHTTP2Tests/TestUtilities.swift b/Tests/NIOHTTP2Tests/TestUtilities.swift +index f091045..8aee4ca 100644 +--- a/Tests/NIOHTTP2Tests/TestUtilities.swift ++++ b/Tests/NIOHTTP2Tests/TestUtilities.swift +@@ -16,8 +16,8 @@ + import Darwin.C + #elseif canImport(Glibc) + import Glibc +-#elseif canImport(Bionic) +-import Bionic ++#elseif canImport(Android) ++import Android + #endif + + import XCTest diff --git a/swift-nio-ndk27.patch b/swift-nio-ndk27.patch index 652fce60..585d8870 100644 --- a/swift-nio-ndk27.patch +++ b/swift-nio-ndk27.patch @@ -40,3 +40,91 @@ index 33b3be73..b97fa645 100644 } } #endif +diff --git a/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift b/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift +index 53864db0..bb062226 100644 +--- a/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift ++++ b/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift +@@ -22,8 +22,8 @@ import XCTest + import Darwin + #elseif canImport(Glibc) + import Glibc +-#elseif canImport(Bionic) +-import Bionic ++#elseif canImport(Android) ++import Android + #else + #error("The Concurrency helpers test module was unable to identify your C library.") + #endif +diff --git a/Tests/NIOCoreTests/XCTest+Extensions.swift b/Tests/NIOCoreTests/XCTest+Extensions.swift +index 1717542d..99474008 100644 +--- a/Tests/NIOCoreTests/XCTest+Extensions.swift ++++ b/Tests/NIOCoreTests/XCTest+Extensions.swift +@@ -15,6 +15,10 @@ + import NIOCore + import XCTest + ++#if canImport(Android) ++import Android ++#endif ++ + func assert( + _ condition: @autoclosure () -> Bool, + within time: TimeAmount, +diff --git a/Tests/NIOEmbeddedTests/TestUtils.swift b/Tests/NIOEmbeddedTests/TestUtils.swift +index 02fe152e..c25bc44a 100644 +--- a/Tests/NIOEmbeddedTests/TestUtils.swift ++++ b/Tests/NIOEmbeddedTests/TestUtils.swift +@@ -17,6 +17,10 @@ import NIOConcurrencyHelpers + import NIOCore + import XCTest + ++#if canImport(Android) ++import Android ++#endif ++ + // FIXME: Duplicated with NIO + func assert( + _ condition: @autoclosure () -> Bool, +diff --git a/Tests/NIOFileSystemTests/FileInfoTests.swift b/Tests/NIOFileSystemTests/FileInfoTests.swift +index e69e7720..d944e425 100644 +--- a/Tests/NIOFileSystemTests/FileInfoTests.swift ++++ b/Tests/NIOFileSystemTests/FileInfoTests.swift +@@ -20,8 +20,8 @@ import XCTest + import Darwin + #elseif canImport(Glibc) + import Glibc +-#elseif canImport(Bionic) +-import Bionic ++#elseif canImport(Android) ++import Android + #endif + + final class FileInfoTests: XCTestCase { +diff --git a/Tests/NIOFileSystemTests/FileTypeTests.swift b/Tests/NIOFileSystemTests/FileTypeTests.swift +index 4b436d87..537b4642 100644 +--- a/Tests/NIOFileSystemTests/FileTypeTests.swift ++++ b/Tests/NIOFileSystemTests/FileTypeTests.swift +@@ -20,6 +20,8 @@ import XCTest + import Darwin + #elseif canImport(Glibc) + import Glibc ++#elseif canImport(Android) ++import Android + #endif + + final class FileTypeTests: XCTestCase { +diff --git a/Tests/NIOFileSystemTests/Internal/SyscallTests.swift b/Tests/NIOFileSystemTests/Internal/SyscallTests.swift +index 66ed1171..5253a650 100644 +--- a/Tests/NIOFileSystemTests/Internal/SyscallTests.swift ++++ b/Tests/NIOFileSystemTests/Internal/SyscallTests.swift +@@ -17,6 +17,10 @@ + import SystemPackage + import XCTest + ++#if canImport(Android) ++import Android ++#endif ++ + #if ENABLE_MOCKING + final class SyscallTests: XCTestCase { + func test_openat() throws { diff --git a/swift-nio-ssl-test.patch b/swift-nio-ssl-test.patch new file mode 100644 index 00000000..1b0b9daf --- /dev/null +++ b/swift-nio-ssl-test.patch @@ -0,0 +1,59 @@ +diff --git a/Tests/NIOSSLTests/NIOSSLTestHelpers.swift b/Tests/NIOSSLTests/NIOSSLTestHelpers.swift +index ac8ef96..9472460 100644 +--- a/Tests/NIOSSLTests/NIOSSLTestHelpers.swift ++++ b/Tests/NIOSSLTests/NIOSSLTestHelpers.swift +@@ -18,6 +18,10 @@ import NIOCore + import NIOEmbedded + @testable import NIOSSL + ++#if canImport(Android) ++import Android ++#endif ++ + let samplePemCert = """ + -----BEGIN CERTIFICATE----- + MIIGGzCCBAOgAwIBAgIJAJ/X0Fo0ynmEMA0GCSqGSIb3DQEBCwUAMIGjMQswCQYD +diff --git a/Tests/NIOSSLTests/SSLCertificateTest.swift b/Tests/NIOSSLTests/SSLCertificateTest.swift +index ebf04dd..eb5dac8 100644 +--- a/Tests/NIOSSLTests/SSLCertificateTest.swift ++++ b/Tests/NIOSSLTests/SSLCertificateTest.swift +@@ -17,6 +17,10 @@ import XCTest + import NIOCore + @testable import NIOSSL + ++#if canImport(Android) ++import Android ++#endif ++ + let multiSanCert = """ + -----BEGIN CERTIFICATE----- + MIIDEzCCAfugAwIBAgIURiMaUmhI1Xr0mZ4p+JmI0XjZTaIwDQYJKoZIhvcNAQEL +diff --git a/Tests/NIOSSLTests/SSLPKCS12BundleTest.swift b/Tests/NIOSSLTests/SSLPKCS12BundleTest.swift +index 12803f9..a9649dc 100644 +--- a/Tests/NIOSSLTests/SSLPKCS12BundleTest.swift ++++ b/Tests/NIOSSLTests/SSLPKCS12BundleTest.swift +@@ -17,6 +17,9 @@ import XCTest + import NIOCore + @testable import NIOSSL + ++#if canImport(Android) ++import Android ++#endif + + /// This is a base64-PKCS12 file that contains only samplePemCert and + /// samplePemKey, no extra certs. The passphrase is +diff --git a/Tests/NIOSSLTests/SSLPrivateKeyTests.swift b/Tests/NIOSSLTests/SSLPrivateKeyTests.swift +index 9dd8d61..1abd9df 100644 +--- a/Tests/NIOSSLTests/SSLPrivateKeyTests.swift ++++ b/Tests/NIOSSLTests/SSLPrivateKeyTests.swift +@@ -17,6 +17,10 @@ import XCTest + import NIOCore + @testable import NIOSSL + ++#if canImport(Android) ++import Android ++#endif ++ + class SSLPrivateKeyTest: XCTestCase { + static var pemKeyFilePath: String! = nil + static var derKeyFilePath: String! = nil diff --git a/swift-system-tests.patch b/swift-system-tests.patch new file mode 100644 index 00000000..a054ec6e --- /dev/null +++ b/swift-system-tests.patch @@ -0,0 +1,30 @@ +diff --git a/swift-system/Tests/SystemTests/FileOperationsTest.swift b/swift-system/Tests/SystemTests/FileOperationsTest.swift +index ed05dcf..db9aa0e 100644 +--- a/swift-system/Tests/SystemTests/FileOperationsTest.swift ++++ b/swift-system/Tests/SystemTests/FileOperationsTest.swift +@@ -15,6 +15,10 @@ import XCTest + @testable import System + #endif + ++#if canImport(Android) ++import Android ++#endif ++ + @available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *) + final class FileOperationsTest: XCTestCase { + func testSyscalls() { +diff --git a/swift-system/Tests/SystemTests/FileTypesTest.swift b/swift-system/Tests/SystemTests/FileTypesTest.swift +index 620cfd7..496fc56 100644 +--- a/swift-system/Tests/SystemTests/FileTypesTest.swift ++++ b/swift-system/Tests/SystemTests/FileTypesTest.swift +@@ -15,6 +15,10 @@ import SystemPackage + import System + #endif + ++#if canImport(Android) ++import Android ++#endif ++ + @available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *) + final class FileDescriptorTest: XCTestCase { + func testStandardDescriptors() { diff --git a/android-overlay/swift-system.patch b/swift-system.patch similarity index 100% rename from android-overlay/swift-system.patch rename to swift-system.patch