Skip to content

Run the compiler validation suite for Android #8

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

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
69800e6
Run the compiler validation suite for Android
marcprux May 26, 2025
e350942
Add --build-compiler option
marcprux May 27, 2025
fcde0f1
Add --cross-compile-build-swift-tools=0 from https://github.com/swift…
marcprux May 27, 2025
53aa633
Build with --build-llvm=0
marcprux May 28, 2025
60c3370
Check out Yams for Swift 6.1.1 build
marcprux May 28, 2025
63f3750
Add --llvm-ninja-targets-for-cross-compile-hosts=help
marcprux May 28, 2025
bfb9e50
Install pre-requisites
marcprux May 29, 2025
c527b1d
Install build prerequisites
marcprux Jun 2, 2025
ef3f51e
Only setup local toolchain if build-compiler is not 0
marcprux Jun 2, 2025
84e885a
Fix Yams version checkout
marcprux Jun 2, 2025
cdbd187
Quote arguments to build scripts
marcprux Jun 2, 2025
060c871
Permit empty host-toolchain argument in build.sh
marcprux Jun 2, 2025
163220d
Fix check for BUILD_COMPILER
marcprux Jun 2, 2025
f8db216
Re-order Docker PATH to system clang is used before Swift toolchain c…
marcprux Jun 3, 2025
a9942a2
Use --host-test to skip attempt to test on connected device/emulator
marcprux Jun 3, 2025
1cbf01e
Install clang in Dockerfile
marcprux Jun 4, 2025
383fb46
Add --skip-test-linux flag to build
marcprux Jun 5, 2025
af85033
Remove more folders to free up space
marcprux Jun 6, 2025
d78eb9e
Update patches
marcprux Jun 6, 2025
f7d1437
Add docker-specific CI variants that run the compiler validation tests
marcprux Jun 7, 2025
4e6f935
meaningless edit
finagolfin Jun 7, 2025
1692659
Update pull_request.yml to stop the 6.1 release builds
finagolfin Jun 7, 2025
287e81d
Update pull_request.yml to really only build the full docker compiler…
finagolfin Jun 7, 2025
e438467
Update README.md with meaningless edit to bump build
finagolfin Jun 8, 2025
324a3b7
Update build.sh to skip testing XCTest for linux, as a handful of the…
finagolfin Jun 9, 2025
02485be
Update build.sh to disable building libTesting and for 16K memory pag…
finagolfin Jun 9, 2025
d070103
Update build.sh to skip testing Foundation for linux, which requires …
finagolfin Jun 9, 2025
ee9529b
Update build.sh to not build each arch in a separate build directory
finagolfin Jun 10, 2025
4b99b11
Update Dockerfile to use clang 19 instead
finagolfin Jun 10, 2025
896ba60
Add self-hosted runner CI variant
marcprux Jun 13, 2025
9b9d56b
Fix CI workflow syntax
marcprux Jun 13, 2025
a157ab3
Update CI runner config
marcprux Jun 13, 2025
f8c0ffd
Update CI runner config
marcprux Jun 13, 2025
73ccf2e
Fix name of self-hosted CI runner
marcprux Jun 13, 2025
4af2892
Re-order arch run sequence
marcprux Jun 14, 2025
60e2543
Update CI for self-hosted runner
marcprux Jun 14, 2025
87b297a
Build for self-hosted runner
marcprux Jun 14, 2025
67a5291
Add swift-6.2-branch to self-hosted run matrix
marcprux Jun 15, 2025
6c3a1ba
Update build.sh to disable aarch64 temporarily, as we know it built fine
finagolfin Jun 15, 2025
b30c138
Update pull_request.yml to disable non-compiler builds, as they all w…
finagolfin Jun 15, 2025
3a0189b
Run compiler validation on self-hosted with increased timeout
marcprux Jun 15, 2025
929ff18
Update build-docker to only build for armv7
finagolfin Jun 16, 2025
28fbe55
Update pull_request.yml to disable self-hosted builds temporarily
finagolfin Jun 16, 2025
eaa140e
Update pull_request.yml to build the full compiler in github runners …
finagolfin Jun 16, 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
47 changes: 33 additions & 14 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,38 @@ jobs:
*.log

android-build:
name: Build Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} SDK
name: Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} ${{ matrix.runner }} (compiler=${{ matrix.build-compiler }})
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
include:
#- swift-version: 'swift-6.2-branch'
# build-type: 'docker'
# build-compiler: '1'
# runner: 'self-hosted'
#- swift-version: 'development'
# build-type: 'docker'
# build-compiler: '1'
# runner: 'self-hosted'
- swift-version: 'swift-6.2-branch'
build-type: 'docker'
build-compiler: '1'
runner: 'ubuntu-24.04'
- swift-version: 'development'
build-type: 'docker'
build-compiler: '1'
runner: 'ubuntu-24.04'
runs-on: ${{ matrix.runner }}
# 12 hour timeout
timeout-minutes: 720
steps:
- name: Free Disk Space
if: ${{ matrix.runner != 'self-hosted' }}
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 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 /usr/local/graalvm/ /usr/local/.ghcup/ /usr/local/lib/node_modules /usr/local/share/boost
sudo docker image prune --all --force
sudo docker builder prune -a
df -h
Expand All @@ -53,6 +64,8 @@ jobs:
# 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
# pass the build-compiler matrix through to the build script
echo "BUILD_COMPILER=${{ matrix.build-compiler }}" >> $GITHUB_ENV
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV
- name: Checkout repository
Expand All @@ -61,7 +74,7 @@ jobs:
if: ${{ matrix.build-type == 'local' }}
working-directory: swift-ci/sdks/android
run: |
sudo apt install -q ninja-build patchelf
sudo apt install -q patchelf build-essential 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
./build-local ${BUILD_SCHEME} ${WORKDIR}
- name: Build Android SDK (Docker)
if: ${{ matrix.build-type == 'docker' }}
Expand Down Expand Up @@ -99,6 +112,9 @@ jobs:
if [[ "${{ matrix.build-type }}" == 'local' ]]; then
ARTIFACT_NAME="${ARTIFACT_NAME}-local"
fi
if [[ "${{ matrix.build-compiler }}" == '1' ]]; then
ARTIFACT_NAME="${ARTIFACT_NAME}-hostbuild"
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 @@ -117,6 +133,7 @@ jobs:
name: ${{ steps.info.outputs.artifact-name }}
path: ${{ steps.info.outputs.artifact-path }}
- name: Cleanup
if: ${{ matrix.runner != 'self-hosted' }}
run: |
# need to free up some space or else when installing we get: No space left on device
df -h
Expand All @@ -125,6 +142,7 @@ jobs:
sudo docker builder prune -a
df -h
- name: Install artifactbundle
if: ${{ matrix.runner != 'self-hosted' }}
shell: bash
run: |
set -ex
Expand All @@ -135,6 +153,7 @@ jobs:
echo "ANDROID_NDK_ROOT=" >> $GITHUB_ENV

- name: Create Demo Project
if: ${{ matrix.runner != 'self-hosted' }}
run: |
cd ${{ runner.temp }}
mkdir DemoProject
Expand All @@ -149,6 +168,7 @@ jobs:
echo 'import Android' >> Sources/DemoProject/DemoProject.swift
- name: Test Demo Project on Android
uses: skiptools/swift-android-action@main
if: false # disabled because we aren't building Testing
with:
# only test for the complete arch SDK build to speed up CI
#run-tests: ${{ matrix.arch == '' }}
Expand All @@ -164,7 +184,6 @@ jobs:
- 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 }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<img src="https://swift.org/assets/images/swift.svg" alt="Swift logo" height="70" >

### Docker images for [Swift](https://swift.org).
### images for [Swift](https://swift.org).

#### You can find the Docker Hub repo here: [https://hub.docker.com/_/swift/](https://hub.docker.com/_/swift/)
#### You can find the Hub repo here: [https://hub.docker.com/_/swift/](https://hub.docker.com/_/swift/)

#### Nightly image tags are published here: [https://hub.docker.com/r/swiftlang/swift](https://hub.docker.com/r/swiftlang/swift)

Expand Down
3 changes: 2 additions & 1 deletion swift-ci/sdks/android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ARG SWIFT_TOOLCHAIN_URL=
RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -q install -y \
build-essential \
clang-19 \
cmake \
ninja-build \
python3 \
Expand Down Expand Up @@ -54,7 +55,7 @@ ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
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}"
ENV PATH="/usr/lib/llvm-19/bin:/usr/local/swift/bin:${PATH}"

ARG ANDROID_NDK_VERSION=

Expand Down
15 changes: 8 additions & 7 deletions swift-ci/sdks/android/build-docker
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ===----------------------------------------------------------------------===

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

ANDROID_NDK_VERSION=android-ndk-r27c
ANDROID_API=28
Expand Down Expand Up @@ -59,9 +59,10 @@ $DOCKER run -i --rm \
-v ${WORKDIR}/products:/products:rw \
${CONTAINER_NAME} \
/scripts/build.sh \
--source-dir /source \
--products-dir /products \
--host-toolchain /usr/local/swift \
--android-api ${ANDROID_API} \
--ndk-home /usr/local/ndk/${ANDROID_NDK_VERSION} \
--archs ${TARGET_ARCHS}
--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}"
33 changes: 18 additions & 15 deletions swift-ci/sdks/android/build-local
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ 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
if [[ "${BUILD_COMPILER}" != "1" ]]; then
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
$HOST_TOOLCHAIN/bin/swift --version

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

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

Expand All @@ -55,10 +57,11 @@ ${WORKDIR}/source/swift-android-patches/apply-patches.sh ${WORKDIR}/source/swift
mkdir -p ${WORKDIR}/products

./scripts/build.sh \
--source-dir ${WORKDIR}/source \
--products-dir ${WORKDIR}/products \
--build-dir ${WORKDIR}/build \
--host-toolchain ${HOST_TOOLCHAIN} \
--android-api ${ANDROID_API} \
--ndk-home ${ANDROID_NDK_HOME} \
--archs ${TARGET_ARCHS}
--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}"
95 changes: 73 additions & 22 deletions swift-ci/sdks/android/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function groupend {

function usage {
cat <<EOF
usage: build.sh --source-dir <path> --products-dir <path> --ndk-home <path> --host-toolchain <path>
usage: build.sh --source-dir <path> --products-dir <path> --ndk-home <path>
[--name <sdk-name>] [--version <version>] [--build-dir <path>]
[--archs <arch>[,<arch> ...]]

Expand All @@ -63,6 +63,7 @@ Options:
--source-dir <path> Specify the path in which the sources can be found.
--ndk-home <path> Specify the path to the Android NDK
--host-toolchain <tc> Specify the path to the host Swift toolchain
--build-compiler <bc> Whether to build and validate the host compiler
--products-dir <path> Specify the path in which the products should be written.
--build-dir <path> Specify the path in which intermediates should be stored.
--android-api <api> Specify the Android API level
Expand Down Expand Up @@ -113,7 +114,7 @@ declare_package boringssl "boringssl" "OpenSSL AND ISC AND MIT" \
# Parse command line arguments
android_sdk_version=0.1
sdk_name=
archs=aarch64,armv7,x86_64
archs=armv7,x86_64
android_api=28
build_type=Release
parallel_jobs=$(($(nproc --all) + 2))
Expand All @@ -130,6 +131,8 @@ while [ "$#" -gt 0 ]; do
ndk_home="$2"; shift ;;
--host-toolchain)
host_toolchain="$2"; shift ;;
--build-compiler)
build_compiler="$2"; shift ;;
--build-dir)
build_dir="$2"; shift ;;
--android-api)
Expand All @@ -155,7 +158,7 @@ done
# Change the commas for spaces
archs="${archs//,/ }"

if [[ -z "$source_dir" || -z "$products_dir" || -z "$ndk_home" || -z "$host_toolchain" ]]; then
if [[ -z "$source_dir" || -z "$products_dir" || -z "$ndk_home" ]]; then
usage
exit 1
fi
Expand Down Expand Up @@ -234,8 +237,10 @@ export ANDROID_NDK_HOME=$ndk_home
export ANDROID_NDK=$ndk_home

echo "Swift found at ${swift_dir}"
echo "Host toolchain found at ${host_toolchain}"
${host_toolchain}/bin/swift --version
if [[ ! -z "${host_toolchain}" ]]; then
echo "Host toolchain found at ${host_toolchain}"
${host_toolchain}/bin/swift --version
fi
echo "Android NDK found at ${ndk_home}"
${ndk_installation}/bin/clang --version
echo "Building for ${archs}"
Expand All @@ -262,11 +267,31 @@ function run() {

for arch in $archs; do
case $arch in
armv7) target_host="arm-linux-androideabi"; compiler_target_host="armv7a-linux-androideabi$android_api"; android_abi="armeabi-v7a" ;;
aarch64) target_host="aarch64-linux-android"; compiler_target_host="$target_host$android_api"; android_abi="arm64-v8a" ;;
x86_64) target_host="x86_64-linux-android"; compiler_target_host="$target_host$android_api"; android_abi="x86_64" ;;
x86) target_host="x86-linux-android"; compiler_target_host="$target_host$android_api"; android_abi="x86" ;;
*) echo "Unknown architecture '$1'"; usage; exit 0 ;;
armv7)
target_host="arm-linux-androideabi"
compiler_target_host="armv7a-linux-androideabi$android_api"
android_abi="armeabi-v7a"
;;
aarch64)
target_host="aarch64-linux-android"
compiler_target_host="$target_host$android_api"
android_abi="arm64-v8a"
;;
x86_64)
target_host="x86_64-linux-android"
compiler_target_host="$target_host$android_api"
android_abi="x86_64"
;;
x86)
target_host="x86-linux-android"
compiler_target_host="$target_host$android_api"
android_abi="x86"
;;
*)
echo "Unknown architecture '$1'"
usage
exit 0
;;
esac

sdk_root=${build_dir}/sdk_root/${arch}
Expand Down Expand Up @@ -378,35 +403,61 @@ for arch in $archs; do
RelWithDebInfo) build_type_flag="--release-debuginfo" ;;
esac

# use an out-of-tree build folder, otherwise subsequent arch builds have conflicts
export SWIFT_BUILD_ROOT=${build_dir}/$arch/swift-project
case $build_compiler in
1|true|yes|YES)
build_cmark=""
local_build=""
build_llvm="1"
build_swift_tools="1"
validation_test="1"
native_swift_tools_path=""
native_clang_tools_path=""
;;
*)
build_cmark="--skip-build-cmark"
local_build="--skip-local-build"
build_llvm="0"
build_swift_tools="0"
validation_test="0"
native_swift_tools_path="--native-swift-tools-path=$host_toolchain/bin"
native_clang_tools_path="--native-clang-tools-path=$host_toolchain/bin"
;;
esac

# use an out-of-tree build folder
export SWIFT_BUILD_ROOT=${build_dir}/swift-project

./swift/utils/build-script \
$build_type_flag \
--reconfigure \
--no-assertions \
--validation-test=$validation_test \
--android \
--android-ndk=$ndk_home \
--android-arch=$arch \
--android-api-level=$android_api \
--native-swift-tools-path=$host_toolchain/bin \
--native-clang-tools-path=$host_toolchain/bin \
--cross-compile-hosts=android-$arch \
--cross-compile-deps-path=$sdk_root \
--install-destdir=$sdk_root \
--build-llvm=0 \
--build-swift-tools=0 \
--skip-build-cmark \
--skip-local-build \
--build-llvm=$build_llvm \
--build-swift-tools=$build_swift_tools \
${native_swift_tools_path} \
${native_clang_tools_path} \
${build_cmark} \
${local_build} \
--host-test \
--skip-test-linux \
--skip-test-xctest --skip-test-foundation \
--build-swift-static-stdlib \
--install-swift \
--install-libdispatch \
--install-foundation \
--xctest --install-xctest \
--swift-testing --install-swift-testing \
--cross-compile-append-host-target-to-destdir=False \
--extra-cmake-options='-DCMAKE_EXTRA_LINK_FLAGS="-Wl,-z,max-page-size=16384"'

--cross-compile-build-swift-tools=0 \
--llvm-ninja-targets-for-cross-compile-hosts=help \
--cross-compile-append-host-target-to-destdir=False
# --extra-cmake-options='-DCMAKE_EXTRA_LINK_FLAGS="-Wl,-z,max-page-size=16384"'
# --swift-testing --install-swift-testing \
# need to remove symlink that gets created in the NDK to the previous arch's build
# or else we get errors like:
# error: could not find module '_Builtin_float' for target 'x86_64-unknown-linux-android'; found: aarch64-unknown-linux-android, at: /home/runner/work/_temp/swift-android-sdk/ndk/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/swift/android/_Builtin_float.swiftmodule
Expand Down
Loading
Loading