diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4a0f0046..bb79fe96 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -25,3 +25,159 @@ jobs: name: docker-logs path: | *.log + + android-build: + name: Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} ${{ matrix.runner }} (compiler=${{ matrix.build-compiler }}) + strategy: + fail-fast: false + matrix: + include: + - swift-version: 'tag:swift-DEVELOPMENT-SNAPSHOT-2025-11-03-a' + build-type: 'docker' + build-compiler: '1' + runner: 'self-hosted' + runs-on: ${{ matrix.runner }} + # 16 hour timeout + timeout-minutes: 1080 + steps: + - name: Free Disk Space + if: ${{ matrix.runner != 'self-hosted' }} + run: | + df -h + # brings available space from 25G to 32G + # otherwise we sometimes run out of space during the build + sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /opt/ghc /opt/hostedtoolcache /usr/local/graalvm/ /usr/local/.ghcup/ /usr/local/lib/node_modules /usr/local/share/boost + sudo docker image prune --all --force + sudo docker builder prune -a + df -h + - name: Setup + id: config + run: | + # these variabes are used by build-docker and build-local + # to determine which Swift version to build for + echo "SWIFT_VERSION=${{ matrix.swift-version }}" >> $GITHUB_ENV + # pass the build-compiler matrix through to the build script + echo "BUILD_COMPILER=${{ matrix.build-compiler }}" >> $GITHUB_ENV + echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV + echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV + - name: Checkout repository + uses: actions/checkout@v4 + - name: Build Android SDK (Local) + if: ${{ matrix.build-type == 'local' }} + working-directory: swift-ci/sdks/android + run: | + sudo apt install -q patchelf build-essential cmake ninja-build python3 golang git gnupg2 libcurl4-openssl-dev libedit-dev libicu-dev libncurses5-dev libpython3-dev libsqlite3-dev libxml2-dev rsync uuid-dev uuid-runtime tzdata curl unzip + ./build-local ${SWIFT_VERSION} ${WORKDIR} + - name: Build Android SDK (Docker) + if: ${{ matrix.build-type == 'docker' }} + working-directory: swift-ci/sdks/android + run: | + ./build-docker ${SWIFT_VERSION} ${WORKDIR} + - name: Install Host Toolchain + if: ${{ matrix.build-type == 'docker' }} + working-directory: swift-ci/sdks/android + run: | + # when building in a Docker container, we don't have a local host toolchain, + # but we need one in order to run the SDK validation tests, so we install it now + HOST_OS=ubuntu$(lsb_release -sr) + source ./scripts/toolchain-vars.sh + mkdir -p ${WORKDIR}/host-toolchain + ./scripts/install-swift.sh ${WORKDIR}/host-toolchain/$SWIFT_BASE/usr + ls ${WORKDIR}/host-toolchain + ${WORKDIR}/host-toolchain/*/usr/bin/swift --version + - name: Get artifact info + id: info + shell: bash + run: | + set -ex + SWIFT_ROOT=$(dirname ${WORKDIR}/host-toolchain/*/usr) + echo "swift-root=${SWIFT_ROOT}" >> $GITHUB_OUTPUT + echo "swift-path=${SWIFT_ROOT}/usr/bin/swift" >> $GITHUB_OUTPUT + + ARTIFACT_PATH=$(realpath ${WORKDIR}/products/*.artifactbundle.tar.gz) + echo "artifact-path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT + echo "sdk-id=x86_64-unknown-linux-android28" >> $GITHUB_OUTPUT + + ARTIFACT_EXT=".artifactbundle.tar.gz" + ARTIFACT_NAME="$(basename ${ARTIFACT_PATH} ${ARTIFACT_EXT})" + # depending on whether we are building locally or in a container, add a maker to the name + if [[ "${{ matrix.build-type }}" == 'local' ]]; then + ARTIFACT_NAME="${ARTIFACT_NAME}-local" + fi + if [[ "${{ matrix.build-compiler }}" == '1' ]]; then + ARTIFACT_NAME="${ARTIFACT_NAME}-hostbuild" + fi + # artifacts need a unique name so we suffix with the matrix arch(s) + if [[ ! -z "${{ matrix.arch }}" ]]; then + ARTIFACT_NAME="${ARTIFACT_NAME}-$(echo ${{ matrix.arch }} | tr ',' '-')" + fi + ARTIFACT_NAME="${ARTIFACT_NAME}${ARTIFACT_EXT}" + + # There is no way to prevent even a single-file artifact from being zipped: + # https://github.com/actions/upload-artifact?tab=readme-ov-file#zip-archives + # so the actual artifact download will look like: + # swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip + echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT + - name: Upload SDK artifactbundle + uses: actions/upload-artifact@v4 + with: + compression-level: 0 + name: ${{ steps.info.outputs.artifact-name }} + path: ${{ steps.info.outputs.artifact-path }} + - name: Cleanup + if: ${{ matrix.runner != 'self-hosted' }} + run: | + # need to free up some space or else when installing we get: No space left on device + df -h + rm -rf ${WORKDIR}/{build,source} + sudo docker image prune --all --force + sudo docker builder prune -a + df -h + - name: Install artifactbundle + if: ${{ matrix.runner != 'self-hosted' }} + shell: bash + run: | + set -ex + ${{ steps.info.outputs.swift-path }} sdk install ${{ steps.info.outputs.artifact-path }} + ${{ steps.info.outputs.swift-path }} sdk configure --show-configuration $(${{ steps.info.outputs.swift-path }} sdk list | head -n 1) ${{ steps.info.outputs.sdk-id }} + # recent releases require that ANDROID_NDK_ROOT *not* be set + # see https://github.com/swiftlang/swift-driver/pull/1879 + echo "ANDROID_NDK_ROOT=" >> $GITHUB_ENV + + - name: Create Demo Project + if: ${{ matrix.runner != 'self-hosted' }} + run: | + cd ${{ runner.temp }} + mkdir DemoProject + cd DemoProject + ${{ steps.info.outputs.swift-path }} --version + ${{ steps.info.outputs.swift-path }} package init + echo 'import Foundation' >> Sources/DemoProject/DemoProject.swift + echo 'import FoundationEssentials' >> Sources/DemoProject/DemoProject.swift + echo 'import FoundationXML' >> Sources/DemoProject/DemoProject.swift + echo 'import FoundationNetworking' >> Sources/DemoProject/DemoProject.swift + echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift + echo 'import Android' >> Sources/DemoProject/DemoProject.swift + - name: Test Demo Project on Android + uses: skiptools/swift-android-action@main + if: ${{ matrix.runner != 'self-hosted' }} + with: + # only test for the complete arch SDK build to speed up CI + #run-tests: ${{ matrix.arch == '' }} + package-path: ${{ runner.temp }}/DemoProject + installed-sdk: ${{ steps.info.outputs.sdk-id }} + installed-swift: ${{ steps.info.outputs.swift-root }} + + - name: Checkout swift-algorithms + if: ${{ matrix.runner != 'self-hosted' }} + uses: actions/checkout@v4 + with: + repository: apple/swift-algorithms + path: swift-algorithms + - name: Test swift-algorithms + if: ${{ matrix.runner != 'self-hosted' }} + uses: skiptools/swift-android-action@main + with: + package-path: swift-algorithms + installed-sdk: ${{ steps.info.outputs.sdk-id }} + installed-swift: ${{ steps.info.outputs.swift-root }} diff --git a/nightly-6.2/fedora/39/Dockerfile b/nightly-6.2/fedora/39/Dockerfile index e94c3689..08b2d408 100644 --- a/nightly-6.2/fedora/39/Dockerfile +++ b/nightly-6.2/fedora/39/Dockerfile @@ -6,6 +6,7 @@ RUN yum -y install \ binutils \ gcc \ git \ + zip \ unzip \ libcurl-devel \ libedit-devel \ diff --git a/nightly-6.2/fedora/39/buildx/Dockerfile b/nightly-6.2/fedora/39/buildx/Dockerfile index 59ed0737..805da82a 100644 --- a/nightly-6.2/fedora/39/buildx/Dockerfile +++ b/nightly-6.2/fedora/39/buildx/Dockerfile @@ -6,6 +6,7 @@ RUN yum -y install \ binutils \ gcc \ git \ + zip \ unzip \ libcurl-devel \ libedit-devel \ diff --git a/nightly-6.2/ubuntu/20.04/buildx/Dockerfile b/nightly-6.2/ubuntu/20.04/buildx/Dockerfile index 44db2825..6ad4dd5b 100644 --- a/nightly-6.2/ubuntu/20.04/buildx/Dockerfile +++ b/nightly-6.2/ubuntu/20.04/buildx/Dockerfile @@ -6,6 +6,7 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && ap apt-get -q install -y \ binutils \ git \ + zip \ unzip \ gnupg2 \ libc6-dev \ diff --git a/nightly-main/fedora/39/Dockerfile b/nightly-main/fedora/39/Dockerfile index 678fbbb5..68bb73de 100644 --- a/nightly-main/fedora/39/Dockerfile +++ b/nightly-main/fedora/39/Dockerfile @@ -6,6 +6,7 @@ RUN yum -y install \ binutils \ gcc \ git \ + zip \ unzip \ libcurl-devel \ libedit-devel \ diff --git a/nightly-main/fedora/39/buildx/Dockerfile b/nightly-main/fedora/39/buildx/Dockerfile index 5cefaba3..e7d8208b 100644 --- a/nightly-main/fedora/39/buildx/Dockerfile +++ b/nightly-main/fedora/39/buildx/Dockerfile @@ -6,6 +6,7 @@ RUN yum -y install \ binutils \ gcc \ git \ + zip \ unzip \ libcurl-devel \ libedit-devel \ diff --git a/nightly-main/ubuntu/20.04/buildx/Dockerfile b/nightly-main/ubuntu/20.04/buildx/Dockerfile index 3f812801..53dada94 100644 --- a/nightly-main/ubuntu/20.04/buildx/Dockerfile +++ b/nightly-main/ubuntu/20.04/buildx/Dockerfile @@ -6,6 +6,7 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && ap apt-get -q install -y \ binutils \ git \ + zip \ unzip \ gnupg2 \ libc6-dev \ diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 8a5a4389..11ff3d50 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -128,7 +128,7 @@ declare_package boringssl "boringssl" "OpenSSL AND ISC AND MIT" \ android_sdk_version=0.1 sdk_name= archs=aarch64,armv7,x86_64 -android_api=23 +android_api=28 build_type=Release parallel_jobs=$(($(nproc --all) + 2)) source_dir= diff --git a/swift-ci/sdks/android/scripts/fetch-source.sh b/swift-ci/sdks/android/scripts/fetch-source.sh index 9971fd89..8cc2e8a1 100755 --- a/swift-ci/sdks/android/scripts/fetch-source.sh +++ b/swift-ci/sdks/android/scripts/fetch-source.sh @@ -169,24 +169,14 @@ pushd swift-project >/dev/null # reason, so just turn it into a plain `grep` again. perl -pi -e 's:"git",:#:' swift/test/Misc/verify-swift-feature-testing.test-sh +rm swift/test/SILOptimizer/pack_specialization.swift + # Work around swiftlang/swift-driver#1822 for now perl -pi -g -we "s#(call rm ... \".\{LIBDISPATCH_BUILD_DIR\}\"\n(\s+)fi\n)#\1\2if [[ -d \"\\\${ANDROID_NDK}\" ]]; then call ln -sf \"\\\${SWIFT_BUILD_PATH}/lib/swift\" \"\\\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib\"; fi#" swift/utils/build-script-impl -# fix optional result value in backtrace() call -perl -pi -e 's;.init\(clamping: addresses.count\)\)\);.init\(clamping: addresses.count\)\) ?? 0\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift - # disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport); will be fixed post 6.2 (in which case only the above patch is needed) perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift - -# Disable posix_spawnattr_* calls for Android API 23 -perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_init;throw NSError\(domain: NSPOSIXErrorDomain, code: .init\(ENOEXEC\), userInfo: [ NSLocalizedFailureReasonErrorKey: "Process unavailable on Android" ]\) //try _throwIfPosixError\(posix_spawnattr_init;g' swift-corelibs-foundation/Sources/Foundation/Process.swift -perl -pi -e 's;try _throwIfPosixError\(posix_spawnattr_setflags;//try _throwIfPosixError\(posix_spawnattr_setflags;g' swift-corelibs-foundation/Sources/Foundation/Process.swift -perl -pi -e 's;posix_spawnattr_destroy;//posix_spawnattr_destroy;g' swift-corelibs-foundation/Sources/Foundation/Process.swift - -# Stub out getgrgid_r and getgrnam_r missing from Android API 23 -perl -pi -e 's;getgrgid_r|getgrnam_r;{ _, _, _, _, _ in 0 };g' swift-foundation/Sources/FoundationEssentials/Platform.swift - popd >/dev/null 2>&1 groupend