Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5f1dbac
Add Android workflow
marcprux Mar 31, 2025
1b7e52f
Merge branch 'swiftlang:main' into main
marcprux Apr 7, 2025
c263e80
Merge branch 'swiftlang:main' into main
marcprux Apr 15, 2025
dd6d09f
Merge branch 'swiftlang:main' into main
marcprux Apr 22, 2025
6565052
Build Android image (#1)
marcprux Apr 22, 2025
5f9dab4
Merge branch 'swiftlang:main' into main
marcprux Apr 28, 2025
412e6b0
Merge branch 'swiftlang:main' into main
marcprux Apr 28, 2025
40733f7
Swift Android build 6.2 (#2)
marcprux May 1, 2025
53e361a
Swift Android build 6.2 (#3)
marcprux May 8, 2025
72964f5
Build SDK in Docker container (#4)
marcprux May 18, 2025
9160168
Merge branch 'swiftlang:main' into main
marcprux May 18, 2025
4987bcc
Checkout patches repo instead of using a git submodule
marcprux May 18, 2025
ff3f274
Update libcurl to 8.13.0
marcprux May 18, 2025
595efc3
Remove resources that we no longer use
marcprux May 18, 2025
27b1bf4
Update libcurl to 8.13.0
marcprux May 18, 2025
b898129
Update libxml2 to 2.14.2
marcprux May 18, 2025
f566b23
Build libxml2, libcurl, and boringssl with support for Android 16kb p…
marcprux May 18, 2025
529e3f1
Add build-script --extra-cmake-options=-DCMAKE_EXTRA_LINK_FLAGS=-Wl,-…
marcprux May 18, 2025
c82587d
Add 16KB page size linker flags to linker flags in swift-toolset.json
marcprux May 18, 2025
217f1d7
Add 16KB page size linker flags to linker flags in swift-toolset.json
marcprux May 19, 2025
95046b3
Build with ndk-r28b
marcprux May 19, 2025
8b18b5f
Revert to building with ndk-r27c
marcprux May 19, 2025
f67f9bf
Use official endpoints for discovering latest Swift release/devel/tru…
marcprux May 19, 2025
7011a45
Typo fix in version script
marcprux May 19, 2025
4c65a93
Cleanup for PR
marcprux May 19, 2025
d80c80b
Change BUILD_VERSION to BUILD_SCHEME and have it match release, swift…
marcprux May 19, 2025
2c07eef
Update Android README
marcprux May 19, 2025
51d93f8
Update how patches are applied
marcprux May 21, 2025
46a06df
Fix source directory for patch target
marcprux May 21, 2025
afb2918
Harmonize timestamps in artifactbundle with the swift source tag date…
marcprux May 21, 2025
a469e85
Simplify toolchain-vars.sh
marcprux May 22, 2025
dea39d7
Merge branch 'swiftlang:main' into main
marcprux May 26, 2025
b3cddbd
Merge branch 'swiftlang:main' into main
marcprux Jun 2, 2025
abd3fd1
Merge branch 'swiftlang:main' into main
marcprux Jun 13, 2025
ad24ea5
Merge branch 'swiftlang:main' into main
marcprux Jun 26, 2025
50ba1cd
Run the compiler validation suite for Android (#8)
marcprux Jun 29, 2025
71b7131
Build compiler-validated bundles from latest branch commits, not olde…
finagolfin Jun 30, 2025
e2f696a
Merge pull request #9 from swift-android-sdk/Testing
finagolfin Jul 4, 2025
3f4cd4a
gcpd 'Update patches'
marcprux Jul 16, 2025
bd0df11
Update patches and build matrix
marcprux Jul 17, 2025
80291aa
Disable compiler validated builds on self-hosted
marcprux Jul 17, 2025
18c563f
Centralize cmake variable for 6.2 in patches, as done for trunk upstream
finagolfin Jul 6, 2025
ed09034
Update disabled tests
finagolfin Jul 12, 2025
e4a96b2
Merge branch 'main' into update-patches2
marcprux Jul 17, 2025
f472e9e
Try running Docker build on macOS host
marcprux Jul 17, 2025
22a4320
Remove separate checks of libxml2, curl, and yams
marcprux Jul 18, 2025
bc3f105
Merge pull request #11 from swift-android-sdk/update-patches2
marcprux Jul 18, 2025
a7b303a
Remove upstreamed 6.2 branch patches
finagolfin Jul 18, 2025
4ed1375
Merge branch 'swiftlang:main' into main
marcprux Jul 18, 2025
3f36409
Use command-line flags to work around CMake 3.30+ linker flag bug, ra…
finagolfin Jul 21, 2025
f658604
Create an Android CMake toolchain file instead to cross-compile Testi…
finagolfin Jul 23, 2025
c9fc3d8
Install the native host LLVM tools for full compiler builds
finagolfin Jul 23, 2025
b881e14
Extend `--cross-compile-build-swift-tools=False` to disable building …
finagolfin Jul 26, 2025
9af1d90
Don't copy any libraries from the NDK: link the NDK's clang resource …
finagolfin Aug 8, 2025
5693797
Wildcard the clang version link in the post-install script in order t…
marcprux Aug 18, 2025
31f00b1
Merge pull request #13 from swift-android-sdk/clang-wildcard
marcprux Aug 22, 2025
db10f68
Merge branch 'swiftlang:main' into main
marcprux Aug 22, 2025
1221544
Switch generated shell header to use #!/usr/bin/env bash
marcprux Aug 22, 2025
f555f48
SBOM and nits (#14)
marcprux Aug 22, 2025
7696a44
Remove upstreamed patches and turn the last modifications into perl s…
finagolfin Aug 9, 2025
606ab7a
Remove self-hosted build on github CI
finagolfin Sep 3, 2025
8eb982e
Remove android_build job from pull_request workflow
marcprux Sep 4, 2025
534175d
Add license headers to Android build scripts
marcprux Sep 4, 2025
d139654
Remove unnecessary .gitignore
marcprux Sep 4, 2025
510addd
Add license header to Dockerfile
marcprux Sep 4, 2025
ee191ee
Merge branch 'swiftlang:main' into main
marcprux Sep 4, 2025
87bf6a2
Switch over to using explicit tags and branches when invoking build-d…
finagolfin Sep 7, 2025
9987e54
Merge branch 'swiftlang:main' into main
marcprux Sep 12, 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
96 changes: 96 additions & 0 deletions swift-ci/sdks/android/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ===----------------------------------------------------------------------===
#
# Swift Android SDK: Docker-based build
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

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 \
clang-19 \
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 \
&& 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/lib/llvm-19/bin:/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/*

# 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

85 changes: 85 additions & 0 deletions swift-ci/sdks/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Dockerfile-based build for Swift Android SDK

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 tag:swift-6.2-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 a branch scheme, like "scheme:release/6.2", or a
tag, like "tag:swift-6.2-DEVELOPMENT-SNAPSHOT-2025-09-04-a".

> [!WARNING]
> The workdir argument must not be located in a git repository (e.g., it cannot be the
> current directory)

## Running

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.

It then applies some perl substitutions and invokes `scripts/build.sh`,
which will build the sources for each of the specified
architectures and then combines the SDKs into a single
artifactbundle with targetTriples for each of the supported
architectures (`aarch64`, `x86_64`, `aarmv7`)
and Android API levels (28-35).

## Specifying Architectures

By default, all the supported Android architectures
will be built, but this can be reduced in order to speed
up the build. This can be useful, e.g., as part of a CI that
validates a pull request, as building a single architecture
takes around 30 minutes on a standard ubuntu-24.04 GitHub runner,
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-docker scheme:main /tmp/android-sdk
```

## Building the Swift compiler from source and running the validation suite

All tags that are specified will download the official release or snapshot
toolchain and build only the bundle by default, while building from a branch
scheme always builds the full Swift compiler from the latest commit in that
branch. If you want to build the Swift compiler from source for a tag also and
run the compiler validation suite, specify the `BUILD_COMPILER` variable:

```
BUILD_COMPILER=yes ./build-docker tag:swift-DEVELOPMENT-SNAPSHOT-2025-09-04-a /tmp/android-sdk
```

## Building locally

Instead of building within a Docker container, the script can also
perform the build locally on an Ubuntu 24.04 machine with all the
build prerequisites already installed. This will generate
the same artifacts in approximately half the time, and
may be suitable to an already containerized envrionment (such as
a GitHub runner). A local build can be run with the
`build-local` script, such as:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include an example of the command(s) for running the build locally?

Copy link
Contributor Author

@marcprux marcprux Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```
./build-local scheme:release/6.2 /tmp/android-sdk
```
75 changes: 75 additions & 0 deletions swift-ci/sdks/android/build-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash -e
#
# ===----------------------------------------------------------------------===
#
# Swift Android SDK: Docker Container Build Script
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2025 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

# default architectures to build for
TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}

ANDROID_NDK_VERSION=android-ndk-r27d
ANDROID_API=28

BASEPATH=$(dirname $(realpath $0))
cd ${BASEPATH}

export SWIFT_VERSION=${1}
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
WORKDIR=${2}
if [[ "${WORKDIR}" == '' ]]; then
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
exit 1
fi
mkdir -p ${WORKDIR}
WORKDIR=$(realpath ${WORKDIR})

HOST_OS=ubuntu24.04
source ./scripts/toolchain-vars.sh

# Check-out and patch the sources
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source

# This `git grep` invocation in a trunk test fails in our Docker for some
# reason, so just turn it into a plain `grep` again.
perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh

# 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#" ${WORKDIR}/source/swift-project/swift/utils/build-script-impl

# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift

mkdir -p ${WORKDIR}/products
chmod ugo+rwx ${WORKDIR}/products

if [[ "$DOCKER" == "" ]]; then
DOCKER=docker
fi

CONTAINER_NAME="swift-android"

# Build the Docker image
$DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX --build-arg SWIFT_TOOLCHAIN_URL=$SWIFT_TOOLCHAIN_URL --build-arg ANDROID_NDK_VERSION=$ANDROID_NDK_VERSION -t ${CONTAINER_NAME} .

$DOCKER run -i --rm \
-v ${WORKDIR}/source:/source \
-v ${WORKDIR}/products:/products:rw \
${CONTAINER_NAME} \
/scripts/build.sh \
--source-dir "/source" \
--products-dir "/products" \
--host-toolchain "/usr/local/swift" \
--build-compiler "${BUILD_COMPILER}" \
--android-api "${ANDROID_API}" \
--ndk-home "/usr/local/ndk/${ANDROID_NDK_VERSION}" \
--archs "${TARGET_ARCHS}"
84 changes: 84 additions & 0 deletions swift-ci/sdks/android/build-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash -e
#
# ===----------------------------------------------------------------------===
#
# Swift Android SDK: Local (non-Docker-containerized) Build Script
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2025 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

# default architectures to build for
TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}

ANDROID_NDK_VERSION=android-ndk-r27d
ANDROID_API=28

BASEPATH=$(dirname $(realpath $0))
cd ${BASEPATH}

export SWIFT_VERSION=${1}
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
WORKDIR=${2}
if [[ "${WORKDIR}" == '' ]]; then
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
exit 1
fi
mkdir -p ${WORKDIR}
WORKDIR=$(realpath ${WORKDIR})

HOST_OS=ubuntu$(lsb_release -sr)
source ./scripts/toolchain-vars.sh

SWIFT_ROOT=${WORKDIR}/host-toolchain
HOST_TOOLCHAIN=$SWIFT_ROOT/$SWIFT_BASE/usr
if [[ ! -d "$HOST_TOOLCHAIN" ]]; then
./scripts/install-swift.sh ${HOST_TOOLCHAIN}
fi

$HOST_TOOLCHAIN/bin/swift --version

# ensure the correct Swift is first in the PATH
export PATH=$HOST_TOOLCHAIN/bin:$PATH

export ANDROID_NDK_HOME=${WORKDIR}/ndk/${ANDROID_NDK_VERSION}

if [[ ! -d ${ANDROID_NDK_HOME} ]]; then
mkdir -p $(dirname ${ANDROID_NDK_HOME})
pushd $(dirname ${ANDROID_NDK_HOME})
NDKFILE=$(basename $ANDROID_NDK_HOME)-linux.zip
wget -q https://dl.google.com/android/repository/${NDKFILE}
unzip -q ${NDKFILE}
popd
fi


# Check-out and patch the sources
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source
# This `git grep` invocation in a trunk test fails in our Docker for some
# reason, so just turn it into a plain `grep` again.
perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh

# 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#" ${WORKDIR}/source/swift-project/swift/utils/build-script-impl

# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift

mkdir -p ${WORKDIR}/products

./scripts/build.sh \
--source-dir "${WORKDIR}/source" \
--products-dir "${WORKDIR}/products" \
--build-dir "${WORKDIR}/build" \
--build-compiler "${BUILD_COMPILER}" \
--host-toolchain "${HOST_TOOLCHAIN}" \
--android-api "${ANDROID_API}" \
--ndk-home "${ANDROID_NDK_HOME}" \
--archs "${TARGET_ARCHS}"
Loading
Loading