Skip to content

Commit

Permalink
build Ubuntu release-specific images
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Dec 9, 2024
1 parent ba57231 commit 1f33c75
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 23 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ on:

jobs:
build:
name: Build and push Docker image to Docker Hub
strategy:
matrix:
os:
- dockerfile: 'Ubuntu.22.04'
display: 'Ubuntu 22.04'
images:
- tayloraswift/swift-cross-aarch64-jammy

- dockerfile: 'Ubuntu.24.04'
display: 'Ubuntu 24.04'
images:
- tayloraswift/swift-cross-aarch64-noble
- tayloraswift/swift-cross-aarch64

name: ${{ matrix.os.display }}
runs-on: ubuntu-latest
permissions:
packages: write
Expand All @@ -31,7 +45,7 @@ jobs:
- name: Extract Docker metadata
uses: docker/metadata-action@master
with:
images: tayloraswift/swift-cross-aarch64
images: ${{ matrix.os.images }}
id: metadata

- name: Set up Buildx
Expand All @@ -42,7 +56,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
file: ${{ matrix.os.dockerfile }}.Dockerfile
push: true
labels: ${{ steps.metadata.outputs.labels }}
tags: ${{ steps.metadata.outputs.tags }}
38 changes: 20 additions & 18 deletions Scripts/TestAll
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/bin/bash
set -e

docker build . -t swift-cross-aarch64:__test
for dockerfile in *.Dockerfile; do
docker build -f $dockerfile -t swift-cross-aarch64:__test .

# Test dynamically linked standard library
docker run --rm \
-v=$PWD/Tests:/swift \
-w=/swift \
swift-cross-aarch64:__test \
/home/ubuntu/x86_64/swift/usr/bin/swift \
build -c release \
--destination aarch64-unknown-linux-gnu.json
# Test dynamically linked standard library
docker run --rm \
-v=$PWD/Tests:/swift \
-w=/swift \
swift-cross-aarch64:__test \
/home/ubuntu/x86_64/swift/usr/bin/swift \
build -c release \
--destination aarch64-unknown-linux-gnu.json

# Test statically linked standard library
docker run --rm \
-v=$PWD/Tests:/swift \
-w=/swift \
swift-cross-aarch64:__test \
/home/ubuntu/x86_64/swift/usr/bin/swift \
build -c release \
--destination aarch64-unknown-linux-gnu.static.json \
--static-swift-stdlib
# Test statically linked standard library
docker run --rm \
-v=$PWD/Tests:/swift \
-w=/swift \
swift-cross-aarch64:__test \
/home/ubuntu/x86_64/swift/usr/bin/swift \
build -c release \
--destination aarch64-unknown-linux-gnu.static.json \
--static-swift-stdlib
done
4 changes: 2 additions & 2 deletions Dockerfile → Ubuntu.22.04.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Cross compilation requires libstdc++-12-dev-arm64-cross, which is only available in
# Ubuntu 22.04 or newer.
FROM ubuntu:jammy
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
SHELL ["/bin/bash", "-c"]

ARG SWIFT_VERSION='6.0.2'
ARG SWIFT_VERSION
ARG UBUNTU_VERSION='ubuntu22.04'

WORKDIR /home/ubuntu
Expand Down
80 changes: 80 additions & 0 deletions Ubuntu.24.04.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND noninteractive
SHELL ["/bin/bash", "-c"]

ARG SWIFT_VERSION
ARG UBUNTU_VERSION='ubuntu24.04'

WORKDIR /home/ubuntu

RUN apt update
RUN apt -y install curl

# Note: The Docker CLI does not print the correct URL to the console, but the actual
# interpolated string passed to `curl` is correct.
RUN curl "https://download.swift.org/\
swift-${SWIFT_VERSION}-release/\
${UBUNTU_VERSION//[.]/}/\
swift-${SWIFT_VERSION}-RELEASE/\
swift-${SWIFT_VERSION}-RELEASE-${UBUNTU_VERSION}.tar.gz" \
-o toolchain.tar.gz

RUN curl "https://download.swift.org/\
swift-${SWIFT_VERSION}-release/\
${UBUNTU_VERSION//[.]/}-aarch64/\
swift-${SWIFT_VERSION}-RELEASE/\
swift-${SWIFT_VERSION}-RELEASE-${UBUNTU_VERSION}-aarch64.tar.gz" \
-o toolchain-aarch64.tar.gz

RUN apt -y dist-upgrade

# Install dependencies of the Swift toolchain
RUN apt update
RUN apt -y install \
binutils \
git \
gnupg2 \
libc6-dev \
libcurl4-openssl-dev \
libedit2 \
libgcc-9-dev \
libsqlite3-0 \
libstdc++-9-dev \
libxml2-dev \
libz3-dev \
pkg-config \
tzdata \
unzip \
zlib1g-dev

# Install dependencies needed for AArch64 cross-compilation. For some reason, `apt` cannot
# resolve the dependencies if we install them all at once.
RUN apt -y install gcc-aarch64-linux-gnu
RUN apt -y install libstdc++-12-dev-arm64-cross
RUN apt -y install g++-multilib

# Unpack the Swift toolchain for x86_64
WORKDIR /home/ubuntu/x86_64/${SWIFT_VERSION}

RUN tar --strip-components=1 -xf /home/ubuntu/toolchain.tar.gz
RUN rm /home/ubuntu/toolchain.tar.gz

# Unpack the Swift toolchain for AArch64
WORKDIR /home/ubuntu/aarch64/${SWIFT_VERSION}

RUN tar --strip-components=1 -xf /home/ubuntu/toolchain-aarch64.tar.gz
RUN rm /home/ubuntu/toolchain-aarch64.tar.gz


WORKDIR /home/ubuntu

# See:
# https://forums.swift.org/t/swift-runtime-unable-to-suspend-thread-when-compiling-in-qemu/67676/3
RUN rm /home/ubuntu/aarch64/${SWIFT_VERSION}/usr/lib/swift/clang
RUN ln -s \
/home/ubuntu/x86_64/${SWIFT_VERSION}/usr/lib/swift/clang \
/home/ubuntu/aarch64/${SWIFT_VERSION}/usr/lib/swift/clang

# Create symbolic links to the Swift toolchains, to make it easier to reference them
RUN ln -s /home/ubuntu/aarch64/${SWIFT_VERSION} /home/ubuntu/aarch64/swift
RUN ln -s /home/ubuntu/x86_64/${SWIFT_VERSION} /home/ubuntu/x86_64/swift

0 comments on commit 1f33c75

Please sign in to comment.