Skip to content

SDKs

SDKs #1331

Workflow file for this run

name: SDKs
on:
pull_request:
schedule:
- cron: '0 9 * * *'
jobs:
get-latest-toolchain:
runs-on: ubuntu-latest
strategy:
matrix:
version: [release, devel, trunk]
outputs:
release-version: ${{ steps.check.outputs.release-tag }}
devel-version: ${{ steps.check.outputs.devel-tag }}
trunk-version: ${{ steps.check.outputs.trunk-tag }}
steps:
- name: Check for latest Swift ${{ matrix.version }} toolchain
id: check
run: |
if [ ${{ matrix.version }} = 'release' ]; then
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/apple/swift/releases | grep -m1 swift-5.8 | 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-5.9-DEV | cut -d- -f8-10)
SWIFT_TAG="swift-5.9-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-${LATEST_TOOLCHAIN_VERSION}-a"
echo "trunk-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT
fi
echo "latest-tag=$SWIFT_TAG" >> $GITHUB_OUTPUT
- name: Get cached toolchain
id: cache-toolchain
uses: actions/cache@v3
with:
path: ~/${{ steps.check.outputs.latest-tag }}-ubuntu22.04.tar.gz
key: ${{ steps.check.outputs.latest-tag }}-toolchain
- name: Get latest toolchain if not cached
if: ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }}
run: |
if [ ${{ matrix.version }} = 'release' ]; then
SWIFT_BRANCH="swift-$(echo ${{ steps.check.outputs.release-tag }} | cut -d- -f2)-release"
elif [ ${{ matrix.version }} = 'devel' ]; then
SWIFT_BRANCH="swift-5.9-branch"
else
SWIFT_BRANCH="development"
fi
cd
SWIFT_TAG="${{ steps.check.outputs.latest-tag }}"
wget -q https://download.swift.org/$SWIFT_BRANCH/ubuntu2204/$SWIFT_TAG/$SWIFT_TAG-ubuntu22.04.tar.gz
echo "got latest toolchain: ${SWIFT_TAG}"
build-sdk-and-tests:
runs-on: ubuntu-latest
needs: get-latest-toolchain
strategy:
fail-fast: false
matrix:
version: [release, devel, trunk]
arch: [aarch64, x86_64, armv7]
env:
ANDROID_API_LEVEL: 24
steps:
- name: Extract the latest version string
id: version
run: |
if [ ${{ matrix.version }} = 'release' ]; then
TAG="${{ needs.get-latest-toolchain.outputs.release-version }}"
echo "latest=$(echo $TAG | cut -d- -f2)" >> $GITHUB_OUTPUT
elif [ ${{ matrix.version }} = 'devel' ]; then
TAG="${{ needs.get-latest-toolchain.outputs.devel-version }}"
echo "latest=$(echo $TAG | cut -d- -f5-7)" >> $GITHUB_OUTPUT
else
TAG="${{ needs.get-latest-toolchain.outputs.trunk-version }}"
echo "latest=$(echo $TAG | cut -d- -f4-6)" >> $GITHUB_OUTPUT
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Get cached Swift ${{ matrix.version }} toolchain
id: cache-toolchain
uses: actions/cache@v3
with:
path: ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz
key: ${{ steps.version.outputs.tag }}-toolchain
- name: Get cached SDK
id: cache-sdk
uses: actions/cache@v3
with:
path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}-*-sdk.tar.xz
key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-bump-sdk
- name: Clone
uses: actions/checkout@v3
with:
path: sdk-config
- name: Build Swift ${{ matrix.version }} Android SDK if not the latest
if: ${{ steps.cache-sdk.outputs.cache-hit != 'true' }}
env:
SWIFT_TAG: ${{ steps.version.outputs.tag }}
ANDROID_ARCH: ${{ matrix.arch }}
run: |
cd sdk-config
sudo apt install ninja-build
BUILD_SWIFT_PM=1 swift get-packages-and-swift-source.swift
SDK_NAME=$(ls | grep swift-${{ matrix.version }}-android-${{ matrix.arch }})
SDK=`pwd`/$SDK_NAME
tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz
git apply swift-android.patch swift-android-ci.patch
sed -i "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc
if [ ${{ matrix.version }} = 'release' ]; then
sed -i "s%String(cString: getpass%\"fake\" //%" swiftpm/Sources/PackageRegistryTool/SwiftPackageRegistryTool.swift
else
sed -i "s%String(cString: getpass%\"fake\" //%" swiftpm/Sources/PackageRegistryTool/PackageRegistryTool+Auth.swift
sed -i "s%#include <unistd%#include <signal.h>\n#include <unistd%" swift-corelibs-libdispatch/dispatch/dispatch.h
sed -i "s%#include <unistd%#include <signal.h>\n#include <unistd%" llbuild/products/libllbuild/include/llbuild/buildsystem.h
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
fi
./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=`pwd`/$SWIFT_TAG-ubuntu22.04/usr/bin --native-clang-tools-path=`pwd`/$SWIFT_TAG-ubuntu22.04/usr/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
patchelf --set-rpath \$ORIGIN $SDK/usr/lib/swift/android/libdispatch.so
patchelf --set-rpath \$ORIGIN/../..:\$ORIGIN $SDK/usr/lib/swift/android/lib[FXs]*.so
tar cJf ~/$SDK_NAME.tar.xz $SDK_NAME
rm -rf $SDK_NAME
- name: Unpack ${{ matrix.version }} toolchain and SDK
id: sdk-unpack
run: |
cd sdk-config
if [ ! -d ${{ steps.version.outputs.tag }}-ubuntu22.04 ]; then
tar xf ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz
fi
tar xf ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}*-${ANDROID_API_LEVEL}-sdk.tar.xz
- name: Get Swift Argument Parser package
uses: actions/checkout@v3
with:
repository: apple/swift-argument-parser
path: swift-argument-parser
- name: Build Swift Argument Parser package
run: |
cd swift-argument-parser
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift crypto package
uses: actions/checkout@v3
with:
repository: apple/swift-crypto
path: swift-crypto
- name: Build Swift crypto package
run: |
cd swift-crypto
sed -i "s%#include <time%#include <signal.h>\n#include <time%" Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
sed -i "s%\\\\(testsDirectory)/.*Vectors%/data/local/tmp/pack/crypto-vectors%" Tests/CryptoTests/Utils/RFCVector.swift Tests/CryptoTests/Utils/Wycheproof.swift Tests/_CryptoExtrasTests/Utils/Wycheproof.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift NIO package
uses: actions/checkout@v3
with:
repository: apple/swift-nio
path: swift-nio
- name: Build Swift NIO package
run: |
cd swift-nio
git apply ../sdk-config/swift-nio-disable-ecn-tests.patch
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift Numerics package
uses: actions/checkout@v3
with:
repository: apple/swift-numerics
path: sn
- name: Build Swift Numerics package
run: |
cd sn
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --enable-test-discovery --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift System package
uses: actions/checkout@v3
with:
repository: apple/swift-system
path: ss
- name: Build Swift System package
run: |
cd ss
sed -i "s%/tmp%/data/local/tmp%" Tests/SystemTests/FileOperationsTest.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --enable-test-discovery --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift Collections package
uses: actions/checkout@v3
with:
repository: apple/swift-collections
path: sco
- name: Build Swift Collections package
run: |
cd sco
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build -j 1 --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift Atomics package
uses: actions/checkout@v3
with:
repository: apple/swift-atomics
path: swift-atomics
ref: 1.1.0
- name: Get Swift NIO SSH package
uses: actions/checkout@v3
with:
repository: apple/swift-nio-ssh
path: sns
- name: Build Swift NIO SSH package
run: |
cd sns
sed -i "s%url: .*swift-\(\w\+\)\.git.*$%path: \"../swift-\1\"),%g" Package.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift NIO SSL package
uses: actions/checkout@v3
with:
repository: apple/swift-nio-ssl
path: snl
- name: Build Swift NIO SSL package
run: |
cd snl
sed -i "s%#include <time%#include <signal.h>\n#include <time%" Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1.h
SWIFTCI_USE_LOCAL_DEPS=1 ../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Yams package
uses: actions/checkout@v3
with:
repository: jpsim/Yams
path: yams
- name: Build Yams package
run: |
cd yams
sed -i "s% fixturesDirectory + \"/SourceKitten#289% \"/data/local/tmp/pack%" Tests/YamsTests/PerformanceTests.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift NIO HTTP/2 package
uses: actions/checkout@v3
with:
repository: apple/swift-nio-http2
path: snh
- name: Build Swift NIO HTTP/2 package
if: ${{ matrix.arch != 'armv7' }}
run: |
cd snh
sed -i "s%url: .*swift-\(\w\+\)\.git.*$%path: \"../swift-\1\"),%g" Package.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get Swift Algorithms package
uses: actions/checkout@v3
with:
repository: apple/swift-algorithms
path: sa
- name: Build Swift Algorithms package
run: |
cd sa
sed -i "s%url: .*$%path: \"../sn\"),%" Package.swift
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift build --build-tests --enable-test-discovery --destination ../sdk-config/swift-${{ matrix.version }}-*-sdk/usr/swiftpm-android-${{ matrix.arch }}.json -Xlinker -rpath -Xlinker \$ORIGIN/lib/swift/android
- name: Get cached Termux debug app for NIO tests
if: ${{ matrix.arch == 'x86_64' }}
id: cache-termux
uses: actions/cache@v3
with:
path: ~/termux-debug.apk
key: termux-app
- name: Get Termux debug app if not cached
if: ${{ matrix.arch == 'x86_64' && steps.cache-termux.outputs.cache-hit != 'true'}}
run: wget -O ~/termux-debug.apk https://github.com/termux/termux-app/releases/download/v0.118.0/termux-app_v0.118.0+github-debug_x86_64.apk
- name: Put SDK and x86_64 tests in one directory to push to Android x86_64 emulator
run: |
mkdir pack
cp ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}*-${ANDROID_API_LEVEL}-sdk.tar.xz pack
if [ ${{ matrix.arch }} = 'x86_64' ]; then
mkdir -p pack/lib/swift/android
TARGET="x86_64-unknown-linux-android$ANDROID_API_LEVEL"
cp swift-argument-parser/.build/$TARGET/debug/{generate-manual,math,repeat,roll,swift-argument-parserPackageTests.xctest} pack
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
cp swift-crypto/.build/$TARGET/debug/swift-cryptoPackageTests.xctest pack
cp swift-nio/.build/$TARGET/debug/swift-nioPackageTests.xctest pack
cp sn/.build/$TARGET/debug/swift-numericsPackageTests.xctest pack
cp ss/.build/$TARGET/debug/swift-systemPackageTests.xctest pack
cp sco/.build/$TARGET/debug/swift-collectionsPackageTests.xctest pack
cp sns/.build/$TARGET/debug/swift-nio-sshPackageTests.xctest pack
cp snl/.build/$TARGET/debug/swift-nio-sslPackageTests.xctest pack
cp yams/.build/$TARGET/debug/YamsPackageTests.xctest pack
cp snh/.build/$TARGET/debug/swift-nio-http2PackageTests.xctest pack
cp sa/.build/$TARGET/debug/swift-algorithmsPackageTests.xctest pack
mkdir pack/crypto-vectors pack/swift-crypto_CryptoTests.resources
cp swift-crypto/Tests/Test\ Vectors/* swift-crypto/Tests/_CryptoExtrasVectors/* pack/crypto-vectors
cp swift-crypto/Tests/CryptoTests/HPKE/hpke-test-vectors.json pack/swift-crypto_CryptoTests.resources
cp yams/Tests/YamsTests/Fixtures/SourceKitten#289/debug.yaml pack
cp sdk-config/swift-${{ matrix.version }}*-android-x86_64-*${ANDROID_API_LEVEL}-sdk/usr/lib/lib*so pack/lib
cp sdk-config/swift-${{ matrix.version }}*-android-x86_64-*${ANDROID_API_LEVEL}-sdk/usr/lib/swift/android/lib*so pack/lib/swift/android
mv pack/lib/libc++_shared.so pack/lib/swift/android
cp ~/termux-debug.apk pack
fi
- name: Upload test directory
uses: actions/upload-artifact@v3
with:
name: sdk-tests-${{ matrix.version }}-${{ matrix.arch }}
path: pack/
run-tests-on-android-x86_64-emulator:
runs-on: macos-latest
needs: build-sdk-and-tests
strategy:
fail-fast: false
matrix:
version: [release, devel, trunk]
steps:
- name: Download test directory
uses: actions/download-artifact@v3
with:
name: sdk-tests-${{ matrix.version }}-x86_64
path: pack
- name: Run tests on Android x86_64 emulator
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 24
arch: x86_64
script: |
rm pack/swift-${{ matrix.version }}-android-x86_64*-sdk.tar.xz
adb install pack/termux-debug.apk
chmod 755 pack/{generate-manual,math,repeat,roll,*.xctest}
adb push pack /data/local/tmp
adb shell /data/local/tmp/pack/swift-argument-parserPackageTests.xctest
adb shell /data/local/tmp/pack/swift-cryptoPackageTests.xctest
adb shell "run-as com.termux mkdir /data/data/com.termux/pack"
adb shell "run-as com.termux cp /data/local/tmp/pack/swift-nioPackageTests.xctest /data/data/com.termux/pack"
adb shell "run-as com.termux cp -r /data/local/tmp/pack/lib /data/data/com.termux/pack"
adb shell "run-as com.termux sh -c 'TMPDIR=/data/data/com.termux /data/data/com.termux/pack/swift-nioPackageTests.xctest'"
adb shell /data/local/tmp/pack/swift-numericsPackageTests.xctest
adb shell /data/local/tmp/pack/swift-systemPackageTests.xctest
adb shell /data/local/tmp/pack/swift-collectionsPackageTests.xctest
adb shell /data/local/tmp/pack/swift-nio-sshPackageTests.xctest
adb shell /data/local/tmp/pack/swift-nio-sslPackageTests.xctest
adb shell /data/local/tmp/pack/swift-nio-http2PackageTests.xctest
adb shell /data/local/tmp/pack/swift-algorithmsPackageTests.xctest
adb shell /data/local/tmp/pack/YamsPackageTests.xctest