-
Notifications
You must be signed in to change notification settings - Fork 207
Android SDK build scripts #467
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
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
5f1dbac
Add Android workflow
marcprux 1b7e52f
Merge branch 'swiftlang:main' into main
marcprux c263e80
Merge branch 'swiftlang:main' into main
marcprux dd6d09f
Merge branch 'swiftlang:main' into main
marcprux 6565052
Build Android image (#1)
marcprux 5f9dab4
Merge branch 'swiftlang:main' into main
marcprux 412e6b0
Merge branch 'swiftlang:main' into main
marcprux 40733f7
Swift Android build 6.2 (#2)
marcprux 53e361a
Swift Android build 6.2 (#3)
marcprux 72964f5
Build SDK in Docker container (#4)
marcprux 9160168
Merge branch 'swiftlang:main' into main
marcprux 4987bcc
Checkout patches repo instead of using a git submodule
marcprux ff3f274
Update libcurl to 8.13.0
marcprux 595efc3
Remove resources that we no longer use
marcprux 27b1bf4
Update libcurl to 8.13.0
marcprux b898129
Update libxml2 to 2.14.2
marcprux f566b23
Build libxml2, libcurl, and boringssl with support for Android 16kb p…
marcprux 529e3f1
Add build-script --extra-cmake-options=-DCMAKE_EXTRA_LINK_FLAGS=-Wl,-…
marcprux c82587d
Add 16KB page size linker flags to linker flags in swift-toolset.json
marcprux 217f1d7
Add 16KB page size linker flags to linker flags in swift-toolset.json
marcprux 95046b3
Build with ndk-r28b
marcprux 8b18b5f
Revert to building with ndk-r27c
marcprux f67f9bf
Use official endpoints for discovering latest Swift release/devel/tru…
marcprux 7011a45
Typo fix in version script
marcprux 4c65a93
Cleanup for PR
marcprux d80c80b
Change BUILD_VERSION to BUILD_SCHEME and have it match release, swift…
marcprux 2c07eef
Update Android README
marcprux 51d93f8
Update how patches are applied
marcprux 46a06df
Fix source directory for patch target
marcprux afb2918
Harmonize timestamps in artifactbundle with the swift source tag date…
marcprux a469e85
Simplify toolchain-vars.sh
marcprux dea39d7
Merge branch 'swiftlang:main' into main
marcprux b3cddbd
Merge branch 'swiftlang:main' into main
marcprux abd3fd1
Merge branch 'swiftlang:main' into main
marcprux ad24ea5
Merge branch 'swiftlang:main' into main
marcprux 50ba1cd
Run the compiler validation suite for Android (#8)
marcprux 71b7131
Build compiler-validated bundles from latest branch commits, not olde…
finagolfin e2f696a
Merge pull request #9 from swift-android-sdk/Testing
finagolfin 3f4cd4a
gcpd 'Update patches'
marcprux bd0df11
Update patches and build matrix
marcprux 80291aa
Disable compiler validated builds on self-hosted
marcprux 18c563f
Centralize cmake variable for 6.2 in patches, as done for trunk upstream
finagolfin ed09034
Update disabled tests
finagolfin e4a96b2
Merge branch 'main' into update-patches2
marcprux f472e9e
Try running Docker build on macOS host
marcprux 22a4320
Remove separate checks of libxml2, curl, and yams
marcprux bc3f105
Merge pull request #11 from swift-android-sdk/update-patches2
marcprux a7b303a
Remove upstreamed 6.2 branch patches
finagolfin 4ed1375
Merge branch 'swiftlang:main' into main
marcprux 3f36409
Use command-line flags to work around CMake 3.30+ linker flag bug, ra…
finagolfin f658604
Create an Android CMake toolchain file instead to cross-compile Testi…
finagolfin c9fc3d8
Install the native host LLVM tools for full compiler builds
finagolfin b881e14
Extend `--cross-compile-build-swift-tools=False` to disable building …
finagolfin 9af1d90
Don't copy any libraries from the NDK: link the NDK's clang resource …
finagolfin 5693797
Wildcard the clang version link in the post-install script in order t…
marcprux 31f00b1
Merge pull request #13 from swift-android-sdk/clang-wildcard
marcprux db10f68
Merge branch 'swiftlang:main' into main
marcprux 1221544
Switch generated shell header to use #!/usr/bin/env bash
marcprux f555f48
SBOM and nits (#14)
marcprux 7696a44
Remove upstreamed patches and turn the last modifications into perl s…
finagolfin 606ab7a
Remove self-hosted build on github CI
finagolfin 8eb982e
Remove android_build job from pull_request workflow
marcprux 534175d
Add license headers to Android build scripts
marcprux d139654
Remove unnecessary .gitignore
marcprux 510addd
Add license header to Dockerfile
marcprux ee191ee
Merge branch 'swiftlang:main' into main
marcprux 87bf6a2
Switch over to using explicit tags and branches when invoking build-d…
finagolfin 9987e54
Merge branch 'swiftlang:main' into main
marcprux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 | ||
|
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
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: | ||
|
||
``` | ||
./build-local scheme:release/6.2 /tmp/android-sdk | ||
``` |
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
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}" |
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
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}" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in swift-android-sdk#14