i have managed to compile a swift 5.9.2 release toolchain for Amazon Linux 2023, and have pushed a (2GB) docker image here: tayloraswift/5.9.2-amazonlinux2023
note that to compile anything in release mode, it is necessary to pass -Xswiftc -use-ld=ld
to the swift build
invocation, because of incompatibility between ld.gold and libstdc++.
for the sake of transparency, building this image invoked three dockerfiles:
dockerfile 2
FROM tayloraswift/swift-ci:amazonlinux2023
RUN mkdir swift-project
WORKDIR swift-project
ARG SWIFT_CHECKOUT=main
ENV SWIFT_CHECKOUT=$SWIFT_CHECKOUT
RUN git clone --depth 1 --branch $SWIFT_CHECKOUT https://github.com/apple/swift
WORKDIR /home/build-user/swift-project/swift
RUN utils/update-checkout --clone --tag $SWIFT_CHECKOUT
RUN --mount=type=cache,target=/swift-project/build \
utils/build-script \
--preset=buildbot_linux,no_assertions,no_test \
install_destdir=/home/build-user/swift-install \
installable_package=/home/build-user/swift-install/swift-${SWIFT_VERSION}-amazonlinux2023.tar.gz
dockerfile 3
FROM amazonlinux:2023
RUN yum -y update
# install sysadmin basics
RUN yum -y install sudo passwd
# install swift dependencies
RUN yum -y install \
binutils \
gcc \
git \
unzip \
glibc-static \
gzip \
libbsd \
libcurl-devel \
libedit \
libicu \
libstdc++-static \
libuuid \
libxml2-devel \
tar \
tzdata \
zlib-devel
# optional, but python, and iptables are very useful in a container
RUN sudo yum -y install \
python3 \
python3-devel \
iptables \
nc
# jemalloc
RUN sudo yum -y install bzip2 make
RUN curl https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2 \
-L -o jemalloc-5.3.0.tar.bz2
RUN tar -xf jemalloc-5.3.0.tar.bz2
RUN cd jemalloc-5.3.0 && ./configure && make && sudo make install
COPY --from=swift-toolchain-builder:5.9.2 /usr/bin/ld.gold /usr/bin/ld.gold
# install swift
COPY --from=swift-toolchain-builder:5.9.2 /home/build-user/swift-install /swift-install
RUN cp -r /swift-install/usr/bin/* /usr/bin \
&& cp -r /swift-install/usr/include/* /usr/include/ \
&& cp -r /swift-install/usr/libexec/* /usr/libexec/ \
&& cp -r /swift-install/usr/lib/* /usr/lib/ \
&& cp -r /swift-install/usr/local/* /usr/local \
&& cp -r /swift-install/usr/share/* /usr/share \
&& rm -r /swift-install
# create the `ec2-user`, and switch to her
RUN useradd -ms /bin/bash ec2-user
RUN passwd -d ec2-user
RUN usermod -aG wheel ec2-user
USER ec2-user
WORKDIR /home/ec2-user/
# generate script that will run on terminal creation,
# enables showing the PWD prompt
RUN echo "PS1='\w\$ '" >> .bashrc
RUN echo "force_color_prompt=yes" >> .bashrc
ENV TERM xterm-256color
CMD sleep infinity