Skip to content

Build SDK in Docker container #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fa6c880
Add static libraries to post-install script
marcprux May 8, 2025
3999f1c
Add post-install script to SDK bundle
marcprux May 10, 2025
9427b75
Add post-install script to SDK bundle
marcprux May 12, 2025
63e404c
marcprux May 15, 2025
b583ff8
marcprux May 15, 2025
57e06fe
marcprux May 15, 2025
a7bcbd4
marcprux May 15, 2025
d103d49
marcprux May 15, 2025
01d008b
marcprux May 15, 2025
7d49998
marcprux May 15, 2025
797c594
marcprux May 15, 2025
ca2b1a1
marcprux May 15, 2025
78c5f7a
marcprux May 15, 2025
4927569
marcprux May 15, 2025
23db569
marcprux May 15, 2025
b51597b
marcprux May 15, 2025
baa2b09
marcprux May 15, 2025
3a2dd25
marcprux May 15, 2025
c729825
marcprux May 15, 2025
db2c0db
marcprux May 15, 2025
ae612f2
marcprux May 15, 2025
7fee5ff
marcprux May 15, 2025
c9655b1
marcprux May 15, 2025
ec2cd6d
marcprux May 15, 2025
5cc8565
marcprux May 15, 2025
3893262
marcprux May 16, 2025
b20c546
marcprux May 16, 2025
e9f41fd
marcprux May 16, 2025
d17d5f2
marcprux May 16, 2025
7bfc734
marcprux May 16, 2025
bbce180
marcprux May 16, 2025
713ac90
Update submodules
marcprux May 16, 2025
f73aff4
marcprux May 16, 2025
5347bfd
marcprux May 16, 2025
f5ad6af
marcprux May 16, 2025
6f79e4c
marcprux May 16, 2025
054ca78
marcprux May 16, 2025
247f695
marcprux May 16, 2025
e11112e
marcprux May 16, 2025
634929f
marcprux May 16, 2025
2972a4e
marcprux May 16, 2025
fec3c9c
marcprux May 16, 2025
889fbc3
marcprux May 17, 2025
10db0ef
marcprux May 17, 2025
32c442b
marcprux May 17, 2025
d12b81d
marcprux May 17, 2025
736570b
marcprux May 17, 2025
68ecf81
marcprux May 17, 2025
f18311f
marcprux May 17, 2025
ad934ff
marcprux May 17, 2025
249e9c6
marcprux May 17, 2025
de874cb
marcprux May 17, 2025
a18ff07
marcprux May 17, 2025
6683bbf
marcprux May 17, 2025
ea800d2
marcprux May 17, 2025
f3c8ad1
marcprux May 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ env:
jobs:
build:
name: Build Docker images
# disabled for CI testing
if: false
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -26,8 +24,6 @@ jobs:

static-linux-build:
name: Build Static Linux image
# disabled for CI testing
if: false
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -37,16 +33,18 @@ jobs:
run: ./build

android-build:
name: Build Android ${{ matrix.swift-version }} ${{ matrix.arch }} SDK
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: ['']
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', '']
#arch: ['x86_64', '']
swift-version: ['release', 'devel', 'trunk']
runs-on: ubuntu-24.04
steps:
Expand All @@ -59,31 +57,60 @@ jobs:
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_VERSION=${{ matrix.swift-version }}" >> $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: Install Dependencies
with:
submodules: 'true'
- name: Build Android SDK (Local)
if: ${{ matrix.build-type == 'local' }}
working-directory: swift-ci/sdks/android
run: |
sudo apt install -q ninja-build patchelf
- name: Build Android SDK
./build-local ${BUILD_VERSION} ${WORKDIR}
- name: Build Android SDK (Docker)
if: ${{ matrix.build-type == 'docker' }}
working-directory: swift-ci/sdks/android
run: |
./build-docker ${BUILD_VERSION} ${WORKDIR}
- name: Install Host Toolchain
if: ${{ matrix.build-type == 'docker' }}
working-directory: swift-ci/sdks/android
run: |
BUILD_VERSION=${{ matrix.swift-version }} TARGET_ARCHS=${{ matrix.arch }} ./build
# 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 ${{ runner.temp }}/swift-android-sdk/host-toolchain/*/usr)
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_BUILD=$(realpath ${{ runner.temp }}/swift-android-sdk/build/*.artifactbundle)
ARTIFACT_PATH=$(realpath ${{ runner.temp }}/swift-android-sdk/products/*.artifactbundle.tar.gz)
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 ',' '-')"
Expand All @@ -95,9 +122,6 @@ jobs:
# 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

# show an abridged tree
tree ${ARTIFACT_BUILD} --filesfirst --prune -P 'Android.swiftmodule' -P 'libswiftAndroid.*' -P 'libFoundation.*' -P 'swiftrt.o' -P 'swift*.json' -P 'info.json' -P 'api-level.h' -P 'android.modulemap' -P 'SwiftAndroidNDK.h' -P 'bridging.modulemap' -P 'linux' -P 'libclang*.a' -P 'libunwind.a' -P 'libclang_rt.builtins-*-android.a'
- name: Upload SDK artifactbundle
uses: actions/upload-artifact@v4
with:
Expand All @@ -108,7 +132,9 @@ jobs:
run: |
# need to free up some space or else when installing we get: No space left on device
df -h
rm -rf ${{ runner.temp }}/swift-android-sdk/{build,src}
rm -rf ${WORKDIR}/{build,source}
sudo docker image prune --all --force
sudo docker builder prune -a
df -h
- name: Install artifactbundle
shell: bash
Expand All @@ -117,7 +143,7 @@ jobs:
${{ 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/finagolfin/swift-android-sdk/issues/207
# see https://github.com/swiftlang/swift-driver/pull/1879
echo "ANDROID_NDK_ROOT=" >> $GITHUB_ENV

- name: Create Demo Project
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "swift-ci/sdks/android/resources/patches"]
path = swift-ci/sdks/android/resources/patches
url = https://github.com/swift-android-sdk/swift-android-sdk
89 changes: 89 additions & 0 deletions swift-ci/sdks/android/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# ===----------------------------------------------------------------------===
#
# Swift Android SDK: Docker-based build
#
# ===----------------------------------------------------------------------===

FROM ubuntu:24.04

# Architecture to build on (empty means x86-64)
ARG OS_ARCH_SUFFIX=

# the Swift toolchain URL to download
ARG SWIFT_TOOLCHAIN_URL=

# ............................................................................

# Install development tools
RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -q install -y \
build-essential \
cmake \
ninja-build \
python3 \
golang \
git \
gnupg2 \
libsqlite3-dev \
libcurl4-openssl-dev \
libedit-dev \
libicu-dev \
libncurses5-dev \
libpython3-dev \
libsqlite3-dev \
libxml2-dev \
rsync \
uuid-dev \
uuid-runtime \
tzdata \
curl \
unzip \
&& rm -rf /var/lib/apt-lists/*

# Install Swift
ARG SWIFT_SIGNING_KEY=E813C892820A6FA13755B268F167DF1ACF9CE069
ARG SWIFT_PLATFORM=ubuntu
ARG OS_MAJOR_VER=24
ARG OS_MINOR_VER=04

ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
SWIFT_PLATFORM=$SWIFT_PLATFORM \
OS_MAJOR_VER=$OS_MAJOR_VER \
OS_MINOR_VER=$OS_MINOR_VER \
OS_VER=$SWIFT_PLATFORM$OS_MAJOR_VER.$OS_MINOR_VER

COPY scripts/install-swift.sh /scripts/install-swift.sh
RUN chmod ugo+x /scripts/install-swift.sh
RUN /scripts/install-swift.sh /usr/local/swift
ENV PATH="/usr/local/swift/bin:${PATH}"

ARG ANDROID_NDK_VERSION=

ENV ANDROID_NDK_VERSION=$ANDROID_NDK_VERSION

COPY scripts/install-ndk.sh /scripts/install-ndk.sh
RUN chmod ugo+x /scripts/install-ndk.sh
RUN /scripts/install-ndk.sh
ENV ANDROID_NDK_HOME="/usr/local/ndk/${ANDROID_NDK_VERSION}"

ENV SWIFT_VERSION=$SWIFT_VERSION \
LIBXML2_VERSION=$LIBXML2_VERSION \
CURL_VERSION=$CURL_VERSION \
BORINGSSL_VERSION=$BORINGSSL_VERSION \
ICU_VERSION=$ICU_VERSION \
ZLIB_VERSION=$ZLIB_VERSION

ENV SWIFT_BUILD_DOCKER="1"

COPY scripts /scripts
RUN chmod ugo+x /scripts/*

COPY resources /resources

# Create a user
RUN groupadd -g 998 build-user && \
useradd -m -r -u 998 -g build-user build-user

USER build-user

WORKDIR /home/build-user
43 changes: 35 additions & 8 deletions swift-ci/sdks/android/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Build scripts for Swift Android SDK
# Dockerfile-based build for Swift Android SDK

This folder contains scripts to build a Swift Android SDK
in the form of an artifactbundle.
This is a Dockerfile-based build set-up for the Swift Android SDK.

The top-level `./build-docker` script will create a
Docker container and install a host toolchain and the
Android NDK, and then invoke `scripts/fetch-source.sh` which will
fetch tagged sources for libxml2, curl, boringssl, and swift.

It can be run with:

```
$ ./build-docker <version> <workdir>
```

for example:

```
$ ./build-docker release /tmp/android-sdk
```

This will create an Ubuntu 24.04 container with the necessary dependencies
to build the Android SDK, including a Swift host toolchain and the
Android NDK that will be used for cross-compilation.

The `version` argument can be one of the following values:

| version | Swift version |
| --- | --- |
| `release` | swift-6.1-RELEASE |
| `devel` | swift-6.2-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
| `trunk` | swift-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |

## Running

The top-level `./build` script installs a host toolchain and the
The top-level `./build-docker` script installs a host toolchain and the
Android NDK, and then invokes `scripts/fetch-source.sh` which will
fetch tagged sources for libxml2, curl, boringssl, and swift.

Expand All @@ -27,7 +55,7 @@ whereas building for all the architectures takes over an hour.
To build an artifactbundle for just the `x86_64` architecture, run:

```
TARGET_ARCHS=x86_64 ./build
TARGET_ARCHS=aarch64 ./build-docker release /tmp/android-sdk
```

## Installing and validating the SDK
Expand All @@ -38,6 +66,5 @@ will create and upload an installable SDK named something like:

The workflow will also install the SDK locally and use
[swift-android-action](https://github.com/marketplace/actions/swift-android-action)
to build and test various Swift packages in an Android emulator.


to build and test various Swift packages in an Android emulator using the
freshly-created SDK bundle.
Loading
Loading