Source
FROM scratch AS build-base
ARG VERSION
ARG MRUSTC_VERSION
ARG TARGETARCH
COPY --from=stagex/core-filesystem . /
COPY --from=stagex/core-busybox . /
COPY --from=stagex/core-binutils . /
COPY --from=stagex/core-bash . /
COPY --from=stagex/core-make . /
COPY --from=stagex/core-cmake . /
COPY --from=stagex/core-python . /
COPY --from=stagex/core-py-setuptools . /
COPY --from=stagex/core-zlib . /
COPY --from=stagex/core-pkgconf . /
COPY --from=stagex/core-openssl . /
COPY --from=stagex/core-libzstd . /
COPY --from=stagex/core-perl . /
COPY --from=stagex/core-gcc . /
COPY --from=stagex/core-curl . /
COPY --from=stagex/core-ca-certificates . /
COPY --from=stagex/core-libunwind . /
COPY --from=stagex/core-musl . /
COPY --from=stagex/core-libffi . /
COPY --from=stagex/core-lld . /
COPY --from=stagex/core-llvm /usr/lib/libLLVM.so.19.1 /usr/lib/
COPY <<-'EOF' /etc/profile
[[ "$TARGETARCH" == "amd64" ]] && ARCH="x86_64"
[[ "$TARGETARCH" == "arm64" ]] && ARCH="aarch64"
export ARCH
export TARGET=${ARCH}-unknown-linux-musl
export MAKEFLAGS="-j$(nproc)"
EOF
SHELL ["/bin/sh","-l","-c"]
FROM build-base AS build-mrustc
COPY --from=stagex/core-llvm17 . /
COPY --from=stagex/core-hiredis . /
COPY --from=stagex/core-xxhash . /
COPY --from=stagex/core-ccache . /
ADD fetch/mrustc-${MRUSTC_VERSION}.tar.gz .
WORKDIR mrustc-${MRUSTC_VERSION}
ENV MRUSTC_TARGET_VER=1.74
ENV MRUSTC_CCACHE=1
ENV OUTDIR_SUF=
ENV RUSTC_VERSION=1.74.0
ENV RUSTC_INSTALL_BINDIR=bin
ENV LIBGIT2_SYS_USE_PKG_CONFIG=1
ENV MRUSTC_CCACHE=1
COPY fetch/rustc-${RUSTC_VERSION}-src.tar.gz .
RUN <<-EOF
set -eux
export RUSTC_TARGET=${TARGET}
export MAKEFLAGS="-j$(nproc)"
make
make RUSTCSRC
make -f minicargo.mk LIBS
make -f minicargo.mk LLVM_CONFIG=/usr/bin/llvm-config output/rustc
make -f minicargo.mk LLVM_CONFIG=/usr/bin/llvm-config output/cargo
EOF
ADD fix-lib-linking.patch .
RUN <<-EOF
set -eux
patch -p1 < fix-lib-linking.patch
make -C run_rustc LLVM_CONFIG=/usr/bin/llvm-config
mkdir /rust-1.74.0
cp -R run_rustc/output/prefix /rust-1.74.0/usr
EOF
FROM build-base AS build-script
ENV CONFIGURE_FLAGS=
COPY --chmod=0755 <<-'EOF' build
set -eux
VERSION=${1}
BUILD_VERSION=${2}
TOOLS=${3:-cargo}
PATCHES=${4:-}
PREFIX=/rust-${VERSION}/usr
BUILD_PREFIX=/rust-${BUILD_VERSION}/usr
#HACK because rust build seemindly ignores LD_LIBRARY_PATH
cp -R ${BUILD_PREFIX}/lib/rustlib /usr/lib/rustlib
cp ${BUILD_PREFIX}/lib/rustlib/${TARGET}/lib/*.so /usr/lib/
cd rustc-${VERSION}-src
[[ -z "$PATCHES" ]] || for name in ${PATCHES//,/ }; do
patch -p1 < ../${name}.patch
done
./configure \
--build="${TARGET}" \
--host="${TARGET}" \
--target="${TARGET}" \
--local-rust-root="${BUILD_PREFIX}" \
--tools="${TOOLS}" \
--llvm-root="/usr/lib" \
--llvm-libunwind="system" \
--enable-local-rust \
--enable-clang \
--enable-lld \
--enable-option-checking \
--enable-locked-deps \
--enable-vendor \
--dist-compression-formats=gz \
--disable-docs \
--python="python3" \
--prefix="${PREFIX}/usr" \
--sysconfdir="${PREFIX}/etc" \
--release-channel="stable" \
--set="install.prefix=${PREFIX}" \
--set="target.${TARGET}.crt-static=false" \
--set="target.${TARGET}.musl-root=/usr" \
--set="target.${TARGET}.llvm-config=/usr/bin/llvm-config" \
$CONFIGURE_FLAGS
python3 x.py dist
python3 x.py install
rm -rf /rust-${BUILD_VERSION}
EOF
FROM build-script AS build-llvm17
COPY --from=stagex/core-llvm17 . /
COPY --from=build-mrustc /rust-1.74.0 /rust-1.74.0
# HACK: Required by Rust 1.75.0
# https://github.com/rust-lang/rust/issues/117885
RUN mkdir -p $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/
ADD fetch/rustc-1.75.0-src.tar.gz .
RUN ./build 1.75.0 1.74.0
ADD fetch/rustc-1.76.0-src.tar.gz .
RUN ./build 1.76.0 1.75.0
ADD fetch/rustc-1.77.0-src.tar.gz .
RUN ./build 1.77.0 1.76.0
ADD fetch/rustc-1.78.0-src.tar.gz .
RUN ./build 1.78.0 1.77.0
ADD fetch/rustc-1.79.0-src.tar.gz .
RUN ./build 1.79.0 1.78.0
ADD fetch/rustc-1.80.0-src.tar.gz .
RUN ./build 1.80.0 1.79.0
ADD fetch/rustc-1.81.0-src.tar.gz .
RUN ./build 1.81.0 1.80.0
ADD fetch/rustc-1.82.0-src.tar.gz .
RUN ./build 1.82.0 1.81.0
FROM build-script AS build
COPY --from=stagex/core-llvm . /
COPY --from=stagex/core-llvm17 /usr/lib/libLLVM-17.so /usr/lib/
COPY --from=build-llvm17 /rust-1.82.0 /rust-1.82.0
ADD fetch/rustc-1.83.0-src.tar.gz .
RUN ./build 1.83.0 1.82.0
ADD fetch/rustc-1.84.0-src.tar.gz .
RUN ./build 1.84.0 1.83.0
ADD no-default-static.patch .
ADD skip-submodule-updates.patch .
ADD fetch/rustc-${VERSION}-src.tar.gz .
RUN ./build ${VERSION} 1.84.0 cargo,clippy,rustdoc,rustfmt,rust-demangler no-default-static,skip-submodule-updates
RUN <<-EOF
mv /rust-${VERSION} /rootfs
cd /rootfs/usr/lib/rustlib
rm install.log
sort -o manifest-cargo manifest-cargo
sort -o manifest-rustc manifest-rustc
sort -o manifest-rust-std-${TARGET} manifest-rust-std-${TARGET}
rm -f ${TARGET}/lib/self-contained/libunwind.a
EOF
FROM stagex/core-filesystem AS package
COPY --from=build /rootfs/ /