add rust-target-x86_64-gnu

This commit is contained in:
ryan 2024-09-20 15:49:06 -04:00
parent 0231a5079a
commit c1c40c22b5
No known key found for this signature in database
GPG key ID: 8E401478A3FBEF72
3 changed files with 137 additions and 6 deletions

View file

@ -29,6 +29,9 @@ COPY --from=stagex/python . /
RUN tar -xzf ${SRC_FILE}
WORKDIR glibc-${VERSION}
COPY --from=stagex/linux-headers /usr/include /usr/include/x86_64-linux-gnu
ENV _TRIPLE=x86_64-linux-gnu
ENV _LIBDIR=/usr/lib/${_TRIPLE}
ENV _INCDIR=/usr/include/${_TRIPLE}
RUN --network=none <<-EOF
set -eux
@ -36,6 +39,8 @@ RUN --network=none <<-EOF
mkdir build
cd build
echo "slibdir=${_LIBDIR}" >> configparams
echo "rtlddir=${_LIBDIR}" >> configparams
../configure \
--build=${ARCH}-linux-musl \
--host=${ARCH}-linux-musl \
@ -43,10 +48,11 @@ RUN --network=none <<-EOF
--sysconfdir=/etc \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--libdir=/usr/lib/x86_64-linux-gnu \
--includedir=/usr/include/x86_64-linux-gnu \
--libdir=${_LIBDIR} \
--libexecdir=${_LIBDIR} \
--includedir=${_INCDIR} \
--localstatedir=/var \
--with-headers=/usr/include/x86_64-linux-gnu \
--with-headers=${_INCDIR} \
--disable-nls \
--disable-werror \
--enable-debug
@ -58,9 +64,9 @@ RUN --network=none <<-EOF
set -eux
cd build
make DESTDIR=/rootfs install
mv /rootfs/lib64/* /rootfs/usr/lib/x86_64-linux-gnu/
mv /rootfs/sbin/* /rootfs/usr/bin
rmdir /rootfs/lib64 /rootfs/sbin
mv /rootfs/lib64 /rootfs/usr/lib64-pre-move
rmdir /rootfs/sbin
# mkdir -p /rootfs/usr/bin /rootfs/usr/lib
# rm -rf /rootfs/lib
# ln -sf /usr/lib/ld-musl-${ARCH}.so.1 /rootfs/usr/bin/ldd
@ -69,5 +75,6 @@ RUN --network=none <<-EOF
# ln -sf /usr/lib/ld-musl-${ARCH}.so.1 /rootfs/usr/lib/libc.so
EOF
FROM stagex/filesystem AS package
FROM scratch AS package
COPY --from=stagex/filesystem . /
COPY --from=install /rootfs/. /

View file

@ -0,0 +1,105 @@
FROM scratch AS base
ARG VERSION=1.76.0
ENV SRC_SITE=https://static.rust-lang.org/dist
ENV SRC_HASH=9e5cff033a7f0d2266818982ad90e4d3e4ef8f8ee1715776c6e25073a136c021
FROM base AS fetch
COPY --from=stagex/busybox . /
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE}/rustc-${VERSION}-src.tar.gz .
#ADD rust rustc-${VERSION}-src
FROM fetch AS build
COPY --from=stagex/binutils . /
COPY --from=stagex/bash . /
COPY --from=stagex/make . /
COPY --from=stagex/cmake . /
COPY --from=stagex/python . /
COPY --from=stagex/py-setuptools . /
COPY --from=stagex/zlib . /
COPY --from=stagex/pkgconf . /
COPY --from=stagex/openssl . /
COPY --from=stagex/perl . /
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/llvm16 . /
RUN mkdir -p $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/
#ADD no-default-static.patch .
ADD glibc.patch .
RUN <<EOF
set -eux
#PATCHES=no-default-static
PATCHES=glibc
PREFIX=/rust-${VERSION}/usr
tar -xzf rustc-${VERSION}-src.tar.gz
cd rustc-${VERSION}-src
[[ -z "$PATCHES" ]] || for name in ${PATCHES//,/ }; do
patch -p1 < ../${name}.patch
done
./configure \
--build="x86_64-unknown-linux-musl" \
--host="x86_64-unknown-linux-musl" \
--target="x86_64-unknown-linux-gnu" \
--enable-local-rust \
--llvm-root="/usr" \
--disable-docs \
--enable-llvm-link-shared \
--enable-option-checking \
--enable-locked-deps \
--enable-vendor \
--dist-compression-formats=gz \
--python="python3" \
--prefix="/rootfs/usr" \
--libdir="/usr/lib/x86_64-linux-gnu" \
--sysconfdir="/rootfs/etc" \
--release-channel="stable" \
--set="install.prefix=/rootfs" \
--set="build.extended=true" \
--set="rust.musl-root=/usr" \
--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="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"
# un-usrmerge glibc
rm /lib64
mv /usr/lib64-pre-move /lib64
python3 x.py build --stage 0 --target x86_64-unknown-linux-gnu library
# RUSTFLAGS from pcsc
# export RUSTFLAGS="-L /rustc-1.76.0-src/build/x86_64-unknown-linux-musl/stage0-sysroot/lib64/rustlib/x86_64-unknown-linux-gnu/lib/ -L /rustc-1.76.0-src/build/x86_64-unknown-linux-musl/stage0-sysroot/lib64/rustlib/x86_64-unknown-linux-gnu/lib/self-contained/ -L /usr/lib/x86_64-linux-gnu -L /lib64 -C target-feature=+crt-static"
EOF
FROM build AS test
ENV RUSTFLAGS="-L /rustc-1.76.0-src/build/x86_64-unknown-linux-musl/stage0-sysroot/lib64/rustlib/x86_64-unknown-linux-gnu/lib/ -L /rustc-1.76.0-src/build/x86_64-unknown-linux-musl/stage0-sysroot/lib64/rustlib/x86_64-unknown-linux-gnu/lib/self-contained/ -L /usr/lib/x86_64-linux-gnu -L /lib64 -C target-feature=+crt-static"
RUN <<EOF
set -eux
cargo new --bin hello_world
cd hello_world
cargo run --release --target x86_64-unknown-linux-gnu
EOF
FROM build AS install
RUN <<-EOF
mkdir /rootfs
cp -r /rustc-1.76.0-src/build/x86_64-unknown-linux-musl/stage0-sysroot/lib64/rustlib/x86_64-unknown-linux-gnu /usr/lib/rustlib/x86_64-unknown-linux-gnu
EOF
FROM stagex/filesystem AS package
COPY --from=install /rootfs/. /

View file

@ -0,0 +1,19 @@
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index df4d1a43dab..17bb8bf9659 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -438,12 +438,12 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
// Help the libc crate compile by assisting it in finding various
// sysroot native libraries.
- if target.contains("musl") {
+ //if target.contains("musl") {
if let Some(p) = builder.musl_libdir(target) {
let root = format!("native={}", p.to_str().unwrap());
cargo.rustflag("-L").rustflag(&root);
}
- }
+ //}
if target.contains("-wasi") {
if let Some(p) = builder.wasi_root(target) {