feat: cross-x86_64-gnu toolchain w/ optional rust libstd

This commit is contained in:
Lance R. Vick 2024-10-13 14:27:15 -07:00
parent 70d4422bc4
commit 7793830f26
No known key found for this signature in database
GPG key ID: 8E47A1EC35A1551D
6 changed files with 181 additions and 54 deletions

View file

@ -22,10 +22,10 @@ COPY --from=stagex/gcc . /
COPY --from=stagex/libunwind . /
COPY --from=stagex/musl . /
COPY --from=stagex/rust . /
COPY --from=stagex/glibc . /
COPY --from=stagex/curl . /
COPY --from=stagex/ca-certificates . /
COPY --from=stagex/llvm . /
COPY --from=stagex/cross-x86_64-gnu . /
RUN tar -xzf rustc-${VERSION}-src.tar.gz
WORKDIR rustc-${VERSION}-src
@ -46,30 +46,29 @@ RUN <<EOF
--enable-locked-deps \
--enable-vendor \
--dist-compression-formats=gz \
--release-channel="stable" \
--python="python3" \
--prefix="/usr" \
--libdir="/usr/lib/x86_64-linux-gnu" \
--sysconfdir="/rootfs/etc" \
--release-channel="stable" \
--set="install.prefix=/rootfs" \
--set="build.extended=true" \
--libdir="/opt/cross/lib/x86_64-linux-gnu" \
--set="install.prefix=/rootfs" \
--set="rust.musl-root=/usr" \
--set="target.x86_64-unknown-linux-gnu.musl-libdir=/opt/cross/lib/x86_64-linux-gnu" \
--set="target.x86_64-unknown-linux-gnu.llvm-config=/usr/bin/llvm-config" \
--set="target.x86_64-unknown-linux-gnu.cc=x86_64-linux-gnu-gcc" \
--set="target.x86_64-unknown-linux-gnu.cxx=x86_64-linux-gnu-c++" \
--set="target.x86_64-unknown-linux-gnu.ar=x86_64-linux-gnu-ar" \
--set="target.x86_64-unknown-linux-gnu.linker=x86_64-linux-gnu-gcc" \
--set="build.extended=true" \
--set="rust.backtrace-on-ice=true" \
--set="rust.codegen-units=1" \
--set="rust.codegen-units-std=1" \
--set="rust.deny-warnings=false" \
--set="rust.parallel-compiler=false" \
--set="rust.remap-debuginfo=true" \
--set="rust.llvm-libunwind=system" \
--set="rust.llvm-libunwind=in-tree" \
--set="build.full-bootstrap=true" \
--set="target.x86_64-unknown-linux-gnu.llvm-config=/usr/bin/llvm-config" \
--set="target.x86_64-unknown-linux-gnu.cc=cc" \
--set="target.x86_64-unknown-linux-gnu.cxx=c++" \
--set="target.x86_64-unknown-linux-gnu.ar=ar" \
--set="target.x86_64-unknown-linux-gnu.linker=cc" \
--set="target.x86_64-unknown-linux-gnu.musl-libdir=/usr/lib/x86_64-linux-gnu"
rm /lib64
mv /usr/lib64-pre-move /lib64
python3 x.py build --stage 0 --target x86_64-unknown-linux-gnu library
EOF

View file

@ -0,0 +1,168 @@
FROM scratch AS base
ENV GCC_VERSION=13.1.0
ENV GCC_HASH=61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86
ENV GCC_FILE=gcc-$GCC_VERSION.tar.xz
ENV GCC_SITE=https://mirrors.kernel.org/gnu/gcc/gcc-${GCC_VERSION}/${GCC_FILE}
ENV GMP_VERSION=6.2.1
ENV GMP_HASH=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
ENV GMP_FILE=gmp-${GMP_VERSION}.tar.bz2
ENV GMP_SITE=https://gcc.gnu.org/pub/gcc/infrastructure/${GMP_FILE}
ENV MPFR_VERSION=4.1.0
ENV MPFR_HASH=feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926
ENV MPFR_FILE=mpfr-${MPFR_VERSION}.tar.bz2
ENV MPFR_SITE=https://gcc.gnu.org/pub/gcc/infrastructure/${MPFR_FILE}
ENV MPC_VERSION=1.2.1
ENV MPC_HASH=17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459
ENV MPC_FILE=mpc-${MPC_VERSION}.tar.gz
ENV MPC_SITE=https://gcc.gnu.org/pub/gcc/infrastructure/${MPC_FILE}
ENV ISL_VERSION=0.24
ENV ISL_HASH=fcf78dd9656c10eb8cf9fbd5f59a0b6b01386205fe1934b3b287a0a1898145c0
ENV ISL_FILE=isl-${ISL_VERSION}.tar.bz2
ENV ISL_SITE=https://gcc.gnu.org/pub/gcc/infrastructure/${ISL_FILE}
ENV GLIBC_VERSION=2.40
ENV GLIBC_FILE=glibc-${GLIBC_VERSION}.tar.gz
ENV GLIBC_SITE=http://ftpmirror.gnu.org/gnu/glibc/${GLIBC_FILE}
ENV GLIBC_HASH=2abc038f5022949cb67e996c3cae0e7764f99b009f0b9b7fd954dfc6577b599e
ENV BINUTILS_VERSION=2.35
ENV BINUTILS_HASH=1b11659fb49e20e18db460d44485f09442c8c56d5df165de9461eb09c8302f85
ENV BINUTILS_FILE=binutils-${BINUTILS_VERSION}.tar.xz
ENV BINUTILS_SITE=https://ftp.gnu.org/gnu/binutils/${BINUTILS_FILE}
ENV ARCH=x86_64
ENV BUILD=${ARCH}-linux-musl
ENV HOST=${ARCH}-linux-musl
ENV TARGET=${ARCH}-linux-gnu
ENV TZ=UTC
ENV LANG=C.UTF-8
ENV SOURCE_DATE_EPOCH=1
ENV KCONFIG_NOTIMESTAMP=1
ENV OUTPUT=/opt/cross
ENV PATH=/opt/cross/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
FROM base AS fetch
WORKDIR /
ADD --checksum=sha256:${GLIBC_HASH} ${GLIBC_SITE} .
ADD --checksum=sha256:${BINUTILS_HASH} ${BINUTILS_SITE} .
ADD --checksum=sha256:${GCC_HASH} ${GCC_SITE} .
ADD --checksum=sha256:${GMP_HASH} ${GMP_SITE} .
ADD --checksum=sha256:${MPFR_HASH} ${MPFR_SITE} .
ADD --checksum=sha256:${MPC_HASH} ${MPC_SITE} .
ADD --checksum=sha256:${ISL_HASH} ${ISL_SITE} .
FROM fetch AS build
COPY --from=stagex/busybox . /
COPY --from=stagex/musl . /
COPY --from=stagex/gcc . /
COPY --from=stagex/binutils . /
COPY --from=stagex/make . /
COPY --from=stagex/gawk . /
COPY --from=stagex/linux-headers /usr/include/. ${OUTPUT}/${TARGET}/include/
COPY --from=stagex/bison . /
COPY --from=stagex/m4 . /
COPY --from=stagex/perl . /
COPY --from=stagex/python . /
COPY --from=stagex/grep . /
RUN --network=none <<-EOF
set -eux
tar -kxf ${BINUTILS_FILE}
tar -kxf ${GCC_FILE}
tar -kxzf ${GLIBC_FILE}
cd gcc-${GCC_VERSION}
mv ../*.tar.* .; \
./contrib/download_prerequisites
EOF
# Phase 1: Build cross binutils
WORKDIR /build-binutils
RUN --network=none <<-EOF
set -eux
../binutils-${BINUTILS_VERSION}/configure \
--target=${TARGET} \
--prefix=${OUTPUT} \
--disable-multilib
make all -j "$(nproc)"
make install
EOF
# Phase 2: Build and install cross gcc, without libgcc
WORKDIR /build-gcc
RUN --network=none <<-EOF
set -eux
../gcc-${GCC_VERSION}/configure \
--target=${TARGET} \
--prefix=${OUTPUT} \
--enable-languages=c,c++ \
--disable-multilib \
--disable-libssp \
--disable-libsanitizer
make all-gcc
make install-gcc
EOF
# Phase 4: Build and Install glibc headers for use by libgcc
WORKDIR /build-glibc
RUN --network=none <<-EOF
set -eux
sed -i 's/--yacc //' \
../glibc-${GLIBC_VERSION}/intl/Makefile
../glibc-${GLIBC_VERSION}/configure \
--prefix=${OUTPUT}/${TARGET} \
--build=${BUILD} \
--host=${TARGET} \
--target=${TARGET} \
--with-headers=${OUTPUT}/${TARGET}/include \
--disable-multilib \
--disable-werror \
libc_cv_forced_unwind=yes
make \
install-bootstrap-headers=yes \
install-headers
make -j "$(nproc)" csu/subdir_lib
mkdir -p ${OUTPUT}/${TARGET}/lib ${OUTPUT}/${TARGET}/include/gnu
install csu/crt1.o csu/crti.o csu/crtn.o -t ${OUTPUT}/${TARGET}/lib
${TARGET}-gcc \
-nostdlib \
-nostartfiles \
-shared \
-x c /dev/null \
-o ${OUTPUT}/${TARGET}/lib/libc.so
touch ${OUTPUT}/${TARGET}/include/gnu/stubs.h
EOF
# Phase 5: Build and install libgcc
WORKDIR /build-gcc
RUN --network=none <<-EOF
set -eux
make -j "$(nproc)" all-target-libgcc
make install-target-libgcc
EOF
# Phase 6: Build and install glibc
WORKDIR /build-glibc
RUN --network=none <<-EOF
set -eux
make -j "$(nproc)"
make install
EOF
# Phase 7: Build and install remaining gcc targets (C++)
WORKDIR /build-gcc
RUN --network=none <<-EOF
set -eux
make -j "$(nproc)"
make install
EOF
FROM build as install
RUN --network=none <<-EOF
mkdir -p /rootfs/opt /rootfs/usr/bin
mv /opt/cross /rootfs/opt/cross
for bin_path in $(find /rootfs/opt/cross/bin -name ${TARGET}-*); do
bin_name=$(basename "$bin_path")
ln -s /opt/cross/bin/${bin_name} /rootfs/usr/bin/${bin_name}
done
ls -lah /rootfs/usr/bin
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -6,7 +6,6 @@ ENV SRC_SITE=http://ftpmirror.gnu.org/gnu/glibc/${SRC_FILE}
ENV SRC_HASH=2abc038f5022949cb67e996c3cae0e7764f99b009f0b9b7fd954dfc6577b599e
ENV CFLAGS="-Os -fstack-clash-protection -Wformat -Werror=format-security"
ENV CXXFLAGS="-Os -fstack-clash-protection -Wformat -Werror=format-security -D_GLIBCXX_ASSERTIONS=1 -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -D_LIBCPP_ENABLE_HARDENED_MODE=1"
#ENV LDFLAGS="-Wl,--as-needed,-O1,--sort-common -Wl,-soname,libc.musl-${ARCH}.so.1"
FROM base AS fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
@ -32,9 +31,7 @@ ENV _LIBDIR=/usr/lib/${_TRIPLE}
ENV _INCDIR=/usr/include/${_TRIPLE}
RUN --network=none <<-EOF
set -eux
sed -i 's/--yacc //' intl/Makefile
mkdir build
cd build
echo "slibdir=${_LIBDIR}" >> configparams
@ -69,9 +66,6 @@ RUN --network=none <<-EOF
rmdir /rootfs/sbin
ln -s ${ARCH}-linux-gnu/libc.so /rootfs/usr/lib/ld-gnu-${ARCH}.so.1
EOF
ADD glibc-gcc /rootfs/usr/bin/
ADD glibc-gcc.specs /rootfs/usr/lib/${ARCH}-linux-gnu/glibc-gcc.specs
RUN ls -Rlah /rootfs
FROM scratch AS package
COPY --from=stagex/filesystem . /

View file

@ -1,2 +0,0 @@
#!/bin/sh
exec "${REALGCC:-x86_64-linux-musl-gcc}" "$@" -specs "/usr/lib/x86_64-linux-gnu/glibc-gcc.specs"

View file

@ -1,32 +0,0 @@
%rename cpp_options old_cpp_options
*cpp_options:
-nostdinc -isystem /usr/include/x86_64-linux-gnu -isystem include%s %(old_cpp_options)
*cc1:
%(cc1_cpu) -nostdinc -isystem /usr/include/x86_64-linux-gnu -isystem include%s
*link_libgcc:
-L/usr/lib/x86_64-linux-gnu -L .%s
*libgcc:
libgcc.a%s %:if-exists(libgcc_eh.a%s)
*startfile:
%{!shared: /usr/lib/x86_64-linux-gnu/Scrt1.o} /usr/lib/x86_64-linux-gnu/crti.o crtbeginS.o%s
*endfile:
crtendS.o%s /usr/lib/x86_64-linux-gnu/crtn.o
*link:
-dynamic-linker -nostdlib %{shared:-shared} %{static:-static} %{rdynamic:-export-dynamic}
*esp_link:
*esp_options:
*esp_cpp_options: