fix: force musl rust to default to dynamic linking

This commit is contained in:
Lance R. Vick 2024-03-07 08:38:27 -08:00
parent 8f3bfd7ef8
commit c945174b83
No known key found for this signature in database
GPG key ID: 8E47A1EC35A1551D
2 changed files with 65 additions and 1 deletions

View file

@ -106,12 +106,16 @@ COPY <<-'EOF' build.sh
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 ${BUILD_PREFIX}/lib/rustlib/x86_64-unknown-linux-musl/lib/*.so /usr/lib
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" \
@ -184,7 +188,9 @@ RUN sh build.sh 1.74.0 1.73.0
# HACK: Required by Rust 1.75.0
RUN mkdir -p $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/
RUN sh build.sh 1.75.0 1.74.0
RUN sh build.sh 1.76.0 1.75.0 cargo,clippy,rustdoc,rustfmt,rust-demangler
ADD no-default-static.patch .
RUN sh build.sh 1.76.0 1.75.0 cargo,clippy,rustdoc,rustfmt,rust-demangler no-default-static
FROM build as install
RUN <<-EOF

View file

@ -0,0 +1,58 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 08 Aug 2016 15:06:00 +0200
Subject: [PATCH] Fix linux_musl_base for native musl host
See https://github.com/rust-lang/rust/pull/40113
--- a/compiler/rustc_target/src/spec/base/linux_musl.rs
+++ b/compiler/rustc_target/src/spec/base/linux_musl.rs
@@ -1,16 +1,12 @@
-use crate::spec::crt_objects;
-use crate::spec::{base, LinkSelfContainedDefault, TargetOptions};
+use crate::spec::{base, TargetOptions};
pub fn opts() -> TargetOptions {
let mut base = base::linux::opts();
base.env = "musl".into();
- base.pre_link_objects_self_contained = crt_objects::pre_musl_self_contained();
- base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
- base.link_self_contained = LinkSelfContainedDefault::InferredForMusl;
// These targets statically link libc by default
- base.crt_static_default = true;
+ base.crt_static_default = false;
base
}
--- a/compiler/rustc_target/src/spec/crt_objects.rs
+++ b/compiler/rustc_target/src/spec/crt_objects.rs
@@ -58,28 +61,6 @@
(LinkOutputKind::StaticPicExe, &[obj]),
(LinkOutputKind::DynamicDylib, &[obj]),
(LinkOutputKind::StaticDylib, &[obj]),
- ])
-}
-
-pub(super) fn pre_musl_self_contained() -> CrtObjects {
- new(&[
- (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
- (LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
- (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
- (LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]),
- (LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]),
- (LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]),
- ])
-}
-
-pub(super) fn post_musl_self_contained() -> CrtObjects {
- new(&[
- (LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
- (LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
- (LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]),
- (LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]),
- (LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]),
- (LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]),
])
}