Build Swift Android SDK #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Swift Android SDK | |
on: | |
push: | |
branches: '*' | |
tags: "[0-9]+.[0-9]+.[0-9]+" | |
schedule: | |
- cron: '30 4,9,16,21 * * *' | |
workflow_dispatch: | |
pull_request: | |
jobs: | |
android-build: | |
name: Build Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} SDK | |
strategy: | |
fail-fast: false | |
matrix: | |
#build-type: ['docker'] | |
build-type: ['docker', 'local'] | |
# blank arch builds all (aarch64,x86_64,armv7) | |
arch: [''] | |
# builds only x86_64 to speed up the validation | |
#arch: ['x86_64'] | |
# build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs | |
#arch: ['x86_64', ''] | |
swift-version: ['release', 'swift-6.2-branch', 'development'] | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
repository: swiftlang/swift-docker | |
- name: Checkout https://github.com/swiftlang/swift-docker/pull/467 | |
run: gh pr checkout 467 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Free Disk Space | |
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/CodeQL | |
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 "BUILD_SCHEME=${{ matrix.swift-version }}" >> $GITHUB_ENV | |
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV | |
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV | |
- name: Build Android SDK (Local) | |
if: ${{ matrix.build-type == 'local' }} | |
working-directory: swift-ci/sdks/android | |
run: | | |
sudo apt install -q ninja-build patchelf | |
./build-local ${BUILD_SCHEME} ${WORKDIR} | |
- name: Build Android SDK (Docker) | |
if: ${{ matrix.build-type == 'docker' }} | |
working-directory: swift-ci/sdks/android | |
run: | | |
./build-docker ${BUILD_SCHEME} ${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 | |
# 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 | |
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 | |
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 | |
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 | |
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 | |
uses: actions/checkout@v4 | |
with: | |
repository: apple/swift-algorithms | |
path: swift-algorithms | |
- name: Test swift-algorithms | |
uses: skiptools/swift-android-action@main | |
with: | |
run-tests: ${{ matrix.arch == '' }} | |
package-path: swift-algorithms | |
installed-sdk: ${{ steps.info.outputs.sdk-id }} | |
installed-swift: ${{ steps.info.outputs.swift-root }} | |