Skip to content

Commit e0cfa1c

Browse files
committed
Dev: switch to official sdk docker
1 parent 8f0d496 commit e0cfa1c

File tree

9 files changed

+1430
-471
lines changed

9 files changed

+1430
-471
lines changed

.github/workflows/build-android-toolchain.yml

Lines changed: 4 additions & 471 deletions
Large diffs are not rendered by default.

Dockerfile

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# ===----------------------------------------------------------------------===
2+
#
3+
# Swift Android SDK: Docker-based build
4+
#
5+
# This source file is part of the Swift.org open source project
6+
#
7+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
8+
# Licensed under Apache License v2.0 with Runtime Library Exception
9+
#
10+
# See https://swift.org/LICENSE.txt for license information
11+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
#
13+
# ===----------------------------------------------------------------------===
14+
15+
FROM ubuntu:24.04
16+
17+
# Architecture to build on (empty means x86-64)
18+
ARG OS_ARCH_SUFFIX=
19+
20+
# the Swift toolchain URL to download
21+
ARG SWIFT_TOOLCHAIN_URL=
22+
23+
# ............................................................................
24+
25+
# Install development tools
26+
RUN apt-get -q update \
27+
&& DEBIAN_FRONTEND=noninteractive apt-get -q install -y \
28+
build-essential \
29+
clang-19 \
30+
cmake \
31+
ninja-build \
32+
python3 \
33+
golang \
34+
git \
35+
gnupg2 \
36+
libcurl4-openssl-dev \
37+
libedit-dev \
38+
libicu-dev \
39+
libncurses5-dev \
40+
libpython3-dev \
41+
libsqlite3-dev \
42+
libxml2-dev \
43+
rsync \
44+
uuid-dev \
45+
uuid-runtime \
46+
tzdata \
47+
curl \
48+
unzip \
49+
&& rm -rf /var/lib/apt-lists/*
50+
51+
# Install Swift
52+
ARG SWIFT_SIGNING_KEY=E813C892820A6FA13755B268F167DF1ACF9CE069
53+
ARG SWIFT_PLATFORM=ubuntu
54+
ARG OS_MAJOR_VER=24
55+
ARG OS_MINOR_VER=04
56+
57+
ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
58+
SWIFT_PLATFORM=$SWIFT_PLATFORM \
59+
OS_MAJOR_VER=$OS_MAJOR_VER \
60+
OS_MINOR_VER=$OS_MINOR_VER \
61+
OS_VER=$SWIFT_PLATFORM$OS_MAJOR_VER.$OS_MINOR_VER
62+
63+
COPY scripts/install-swift.sh /scripts/install-swift.sh
64+
RUN chmod ugo+x /scripts/install-swift.sh
65+
RUN /scripts/install-swift.sh /usr/local/swift
66+
ENV PATH="/usr/lib/llvm-19/bin:/usr/local/swift/bin:${PATH}"
67+
68+
ARG ANDROID_NDK_VERSION=
69+
70+
ENV ANDROID_NDK_VERSION=$ANDROID_NDK_VERSION
71+
72+
COPY scripts/install-ndk.sh /scripts/install-ndk.sh
73+
RUN chmod ugo+x /scripts/install-ndk.sh
74+
RUN /scripts/install-ndk.sh
75+
ENV ANDROID_NDK_HOME="/usr/local/ndk/${ANDROID_NDK_VERSION}"
76+
77+
ENV SWIFT_VERSION=$SWIFT_VERSION \
78+
LIBXML2_VERSION=$LIBXML2_VERSION \
79+
CURL_VERSION=$CURL_VERSION \
80+
BORINGSSL_VERSION=$BORINGSSL_VERSION \
81+
ICU_VERSION=$ICU_VERSION \
82+
ZLIB_VERSION=$ZLIB_VERSION
83+
84+
ENV SWIFT_BUILD_DOCKER="1"
85+
86+
COPY scripts /scripts
87+
RUN chmod ugo+x /scripts/*
88+
89+
# Create a user
90+
RUN groupadd -g 998 build-user && \
91+
useradd -m -r -u 998 -g build-user build-user
92+
93+
USER build-user
94+
95+
WORKDIR /home/build-user
96+

build-docker

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash -e
2+
#
3+
# ===----------------------------------------------------------------------===
4+
#
5+
# Swift Android SDK: Docker Container Build Script
6+
#
7+
# This source file is part of the Swift.org open source project
8+
#
9+
# Copyright (c) 2025 Apple Inc. and the Swift project authors
10+
# Licensed under Apache License v2.0 with Runtime Library Exception
11+
#
12+
# See https://swift.org/LICENSE.txt for license information
13+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
14+
#
15+
# ===----------------------------------------------------------------------===
16+
17+
# default architectures to build for
18+
TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
19+
20+
ANDROID_NDK_VERSION=android-ndk-r27d
21+
ANDROID_API=28
22+
23+
BASEPATH=$(dirname $(realpath $0))
24+
cd ${BASEPATH}
25+
26+
export SWIFT_VERSION=${1}
27+
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
28+
WORKDIR=${2}
29+
if [[ "${WORKDIR}" == '' ]]; then
30+
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
31+
exit 1
32+
fi
33+
mkdir -p ${WORKDIR}
34+
WORKDIR=$(realpath ${WORKDIR})
35+
36+
HOST_OS=ubuntu24.04
37+
source ./scripts/toolchain-vars.sh
38+
39+
# Check-out and patch the sources
40+
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source
41+
42+
# This `git grep` invocation in a trunk test fails in our Docker for some
43+
# reason, so just turn it into a plain `grep` again.
44+
perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh
45+
46+
# Work around swiftlang/swift-driver#1822 for now
47+
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
48+
49+
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
50+
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
51+
52+
mkdir -p ${WORKDIR}/products
53+
chmod ugo+rwx ${WORKDIR}/products
54+
55+
if [[ "$DOCKER" == "" ]]; then
56+
DOCKER=docker
57+
fi
58+
59+
CONTAINER_NAME="swift-android"
60+
61+
# Build the Docker image
62+
$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} .
63+
64+
$DOCKER run -i --rm \
65+
-v ${WORKDIR}/source:/source \
66+
-v ${WORKDIR}/products:/products:rw \
67+
${CONTAINER_NAME} \
68+
/scripts/build.sh \
69+
--source-dir "/source" \
70+
--products-dir "/products" \
71+
--host-toolchain "/usr/local/swift" \
72+
--build-compiler "${BUILD_COMPILER}" \
73+
--android-api "${ANDROID_API}" \
74+
--ndk-home "/usr/local/ndk/${ANDROID_NDK_VERSION}" \
75+
--archs "${TARGET_ARCHS}"

build-local

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash -e
2+
#
3+
# ===----------------------------------------------------------------------===
4+
#
5+
# Swift Android SDK: Local (non-Docker-containerized) Build Script
6+
#
7+
# This source file is part of the Swift.org open source project
8+
#
9+
# Copyright (c) 2025 Apple Inc. and the Swift project authors
10+
# Licensed under Apache License v2.0 with Runtime Library Exception
11+
#
12+
# See https://swift.org/LICENSE.txt for license information
13+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
14+
#
15+
# ===----------------------------------------------------------------------===
16+
17+
# default architectures to build for
18+
TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
19+
20+
ANDROID_NDK_VERSION=android-ndk-r27d
21+
ANDROID_API=28
22+
23+
BASEPATH=$(dirname $(realpath $0))
24+
cd ${BASEPATH}
25+
26+
export SWIFT_VERSION=${1}
27+
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
28+
WORKDIR=${2}
29+
if [[ "${WORKDIR}" == '' ]]; then
30+
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
31+
exit 1
32+
fi
33+
mkdir -p ${WORKDIR}
34+
WORKDIR=$(realpath ${WORKDIR})
35+
36+
HOST_OS=ubuntu$(lsb_release -sr)
37+
source ./scripts/toolchain-vars.sh
38+
39+
SWIFT_ROOT=${WORKDIR}/host-toolchain
40+
HOST_TOOLCHAIN=$SWIFT_ROOT/$SWIFT_BASE/usr
41+
if [[ ! -d "$HOST_TOOLCHAIN" ]]; then
42+
./scripts/install-swift.sh ${HOST_TOOLCHAIN}
43+
fi
44+
45+
$HOST_TOOLCHAIN/bin/swift --version
46+
47+
# ensure the correct Swift is first in the PATH
48+
export PATH=$HOST_TOOLCHAIN/bin:$PATH
49+
50+
export ANDROID_NDK_HOME=${WORKDIR}/ndk/${ANDROID_NDK_VERSION}
51+
52+
if [[ ! -d ${ANDROID_NDK_HOME} ]]; then
53+
mkdir -p $(dirname ${ANDROID_NDK_HOME})
54+
pushd $(dirname ${ANDROID_NDK_HOME})
55+
NDKFILE=$(basename $ANDROID_NDK_HOME)-linux.zip
56+
wget -q https://dl.google.com/android/repository/${NDKFILE}
57+
unzip -q ${NDKFILE}
58+
popd
59+
fi
60+
61+
62+
# Check-out and patch the sources
63+
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source
64+
# This `git grep` invocation in a trunk test fails in our Docker for some
65+
# reason, so just turn it into a plain `grep` again.
66+
perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh
67+
68+
# Work around swiftlang/swift-driver#1822 for now
69+
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
70+
71+
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
72+
perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' ${WORKDIR}/source/swift-project/swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
73+
74+
mkdir -p ${WORKDIR}/products
75+
76+
./scripts/build.sh \
77+
--source-dir "${WORKDIR}/source" \
78+
--products-dir "${WORKDIR}/products" \
79+
--build-dir "${WORKDIR}/build" \
80+
--build-compiler "${BUILD_COMPILER}" \
81+
--host-toolchain "${HOST_TOOLCHAIN}" \
82+
--android-api "${ANDROID_API}" \
83+
--ndk-home "${ANDROID_NDK_HOME}" \
84+
--archs "${TARGET_ARCHS}"

0 commit comments

Comments
 (0)