Skip to content

Commit 0d4b9b8

Browse files
committed
Remove musl_root and CRT fallback from musl targets
1 parent 02e9525 commit 0d4b9b8

File tree

15 files changed

+5
-211
lines changed

15 files changed

+5
-211
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,16 +1558,12 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15581558

15591559
/// Whether we link to our own CRT objects instead of relying on gcc to pull them.
15601560
/// We only provide such support for a very limited number of targets.
1561-
fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
1561+
fn crt_objects_fallback(sess: &Session, _crate_type: CrateType) -> bool {
15621562
if let Some(self_contained) = sess.opts.cg.link_self_contained {
15631563
return self_contained;
15641564
}
15651565

15661566
match sess.target.crt_objects_fallback {
1567-
// FIXME: Find a better heuristic for "native musl toolchain is available",
1568-
// based on host and linker path, for example.
1569-
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
1570-
Some(CrtObjectsFallback::Musl) => sess.crt_static(Some(crate_type)),
15711567
Some(CrtObjectsFallback::Mingw) => {
15721568
sess.host == sess.target
15731569
&& sess.target.vendor != "uwp"

compiler/rustc_target/src/spec/crt_objects.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,6 @@ pub(super) fn all(obj: &'static str) -> CrtObjects {
6363
])
6464
}
6565

66-
pub(super) fn pre_musl_fallback() -> CrtObjects {
67-
new(&[
68-
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
69-
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
70-
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
71-
(LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]),
72-
(LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]),
73-
(LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]),
74-
])
75-
}
76-
77-
pub(super) fn post_musl_fallback() -> CrtObjects {
78-
new(&[
79-
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
80-
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
81-
(LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]),
82-
(LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]),
83-
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]),
84-
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]),
85-
])
86-
}
87-
8866
pub(super) fn pre_mingw_fallback() -> CrtObjects {
8967
new(&[
9068
(LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
@@ -127,7 +105,6 @@ pub(super) fn post_wasi_fallback() -> CrtObjects {
127105
/// Which logic to use to determine whether to fall back to the "self-contained" mode or not.
128106
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
129107
pub enum CrtObjectsFallback {
130-
Musl,
131108
Mingw,
132109
Wasm,
133110
}
@@ -137,7 +114,6 @@ impl FromStr for CrtObjectsFallback {
137114

138115
fn from_str(s: &str) -> Result<CrtObjectsFallback, ()> {
139116
Ok(match s {
140-
"musl" => CrtObjectsFallback::Musl,
141117
"mingw" => CrtObjectsFallback::Mingw,
142118
"wasm" => CrtObjectsFallback::Wasm,
143119
_ => return Err(()),
@@ -148,7 +124,6 @@ impl FromStr for CrtObjectsFallback {
148124
impl ToJson for CrtObjectsFallback {
149125
fn to_json(&self) -> Json {
150126
match *self {
151-
CrtObjectsFallback::Musl => "musl",
152127
CrtObjectsFallback::Mingw => "mingw",
153128
CrtObjectsFallback::Wasm => "wasm",
154129
}

compiler/rustc_target/src/spec/linux_musl_base.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use crate::spec::crt_objects::{self, CrtObjectsFallback};
21
use crate::spec::TargetOptions;
32

43
pub fn opts() -> TargetOptions {
54
let mut base = super::linux_base::opts();
65

76
base.env = "musl".into();
8-
base.pre_link_objects_fallback = crt_objects::pre_musl_fallback();
9-
base.post_link_objects_fallback = crt_objects::post_musl_fallback();
10-
base.crt_objects_fallback = Some(CrtObjectsFallback::Musl);
117

128
// These targets statically link libc by default
139
base.crt_static_default = true;

config.toml.example

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,6 @@ changelog-seen = 2
523523
# supplementary build information, like distro-specific package versions.
524524
#description = <none> (string)
525525

526-
# The root location of the musl installation directory. The library directory
527-
# will also need to contain libunwind.a for an unwinding implementation. Note
528-
# that this option only makes sense for musl targets that produce statically
529-
# linked binaries.
530-
#
531-
# Defaults to /usr on musl hosts. Has no default otherwise.
532-
#musl-root = <platform specific> (path)
533-
534526
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
535527
# platforms to ensure that the compiler is usable by default from the build
536528
# directory (as it links to a number of dynamic libraries). This may not be
@@ -703,15 +695,6 @@ changelog-seen = 2
703695
# only use static libraries. If unset, the target's default linkage is used.
704696
#crt-static = <platform-specific> (bool)
705697

706-
# The root location of the musl installation directory. The library directory
707-
# will also need to contain libunwind.a for an unwinding implementation. Note
708-
# that this option only makes sense for musl targets that produce statically
709-
# linked binaries.
710-
#musl-root = build.musl-root (path)
711-
712-
# The full path to the musl libdir.
713-
#musl-libdir = musl-root/lib
714-
715698
# The root location of the `wasm32-wasi` sysroot. Only used for the
716699
# `wasm32-wasi` target. If you are building wasm32-wasi target, make sure to
717700
# create a `[target.wasm32-wasi]` section and move this field there.

src/bootstrap/cc_detect.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
4141
Some(PathBuf::from(ar))
4242
} else if target.contains("msvc") {
4343
None
44-
} else if target.contains("musl") {
45-
Some(PathBuf::from("ar"))
4644
} else if target.contains("openbsd") {
4745
Some(PathBuf::from("ar"))
4846
} else if target.contains("vxworks") {
@@ -101,7 +99,7 @@ pub fn find(build: &mut Build) {
10199
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
102100
cfg.compiler(cc);
103101
} else {
104-
set_compiler(&mut cfg, Language::C, target, config, build);
102+
set_compiler(&mut cfg, Language::C, target, config);
105103
}
106104

107105
let compiler = cfg.get_compiler();
@@ -122,7 +120,7 @@ pub fn find(build: &mut Build) {
122120
cfg.compiler(cxx);
123121
true
124122
} else if build.hosts.contains(&target) || build.build == target {
125-
set_compiler(&mut cfg, Language::CPlusPlus, target, config, build);
123+
set_compiler(&mut cfg, Language::CPlusPlus, target, config);
126124
true
127125
} else {
128126
// Use an auto-detected compiler (or one configured via `CXX_target_triple` env vars).
@@ -158,7 +156,6 @@ fn set_compiler(
158156
compiler: Language,
159157
target: TargetSelection,
160158
config: Option<&Target>,
161-
build: &Build,
162159
) {
163160
match &*target.triple {
164161
// When compiling for android we may have the NDK configured in the
@@ -201,26 +198,6 @@ fn set_compiler(
201198
}
202199
}
203200

204-
"mips-unknown-linux-musl" => {
205-
if cfg.get_compiler().path().to_str() == Some("gcc") {
206-
cfg.compiler("mips-linux-musl-gcc");
207-
}
208-
}
209-
"mipsel-unknown-linux-musl" => {
210-
if cfg.get_compiler().path().to_str() == Some("gcc") {
211-
cfg.compiler("mipsel-linux-musl-gcc");
212-
}
213-
}
214-
215-
t if t.contains("musl") => {
216-
if let Some(root) = build.musl_root(target) {
217-
let guess = root.join("bin/musl-gcc");
218-
if guess.exists() {
219-
cfg.compiler(guess);
220-
}
221-
}
222-
}
223-
224201
_ => {}
225202
}
226203
}

src/bootstrap/compile.rs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -230,38 +230,7 @@ fn copy_self_contained_objects(
230230

231231
// Copies the libc and CRT objects.
232232
//
233-
// rustc historically provides a more self-contained installation for musl targets
234-
// not requiring the presence of a native musl toolchain. For example, it can fall back
235-
// to using gcc from a glibc-targeting toolchain for linking.
236-
// To do that we have to distribute musl startup objects as a part of Rust toolchain
237-
// and link with them manually in the self-contained mode.
238-
if target.contains("musl") {
239-
let srcdir = builder.musl_libdir(target).unwrap_or_else(|| {
240-
panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple)
241-
});
242-
for &obj in &["libc.a", "crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
243-
copy_and_stamp(
244-
builder,
245-
&libdir_self_contained,
246-
&srcdir,
247-
obj,
248-
&mut target_deps,
249-
DependencyType::TargetSelfContained,
250-
);
251-
}
252-
let crt_path = builder.ensure(native::CrtBeginEnd { target });
253-
for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] {
254-
let src = crt_path.join(obj);
255-
let target = libdir_self_contained.join(obj);
256-
builder.copy(&src, &target);
257-
target_deps.push((target, DependencyType::TargetSelfContained));
258-
}
259-
260-
if !target.starts_with("s390x") {
261-
let libunwind_path = copy_llvm_libunwind(builder, target, &libdir_self_contained);
262-
target_deps.push((libunwind_path, DependencyType::TargetSelfContained));
263-
}
264-
} else if target.ends_with("-wasi") {
233+
if target.ends_with("-wasi") {
265234
let srcdir = builder
266235
.wasi_root(target)
267236
.unwrap_or_else(|| {
@@ -345,15 +314,6 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
345314
.arg("--manifest-path")
346315
.arg(builder.src.join("library/test/Cargo.toml"));
347316

348-
// Help the libc crate compile by assisting it in finding various
349-
// sysroot native libraries.
350-
if target.contains("musl") {
351-
if let Some(p) = builder.musl_libdir(target) {
352-
let root = format!("native={}", p.to_str().unwrap());
353-
cargo.rustflag("-L").rustflag(&root);
354-
}
355-
}
356-
357317
if target.ends_with("-wasi") {
358318
if let Some(p) = builder.wasi_root(target) {
359319
let root = format!("native={}/lib/wasm32-wasi", p.to_str().unwrap());

src/bootstrap/config.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ pub struct Config {
185185
pub print_step_rusage: bool,
186186
pub missing_tools: bool,
187187

188-
// Fallback musl-root for all targets
189-
pub musl_root: Option<PathBuf>,
190188
pub prefix: Option<PathBuf>,
191189
pub sysconfdir: Option<PathBuf>,
192190
pub datadir: Option<PathBuf>,
@@ -401,8 +399,6 @@ pub struct Target {
401399
pub sanitizers: Option<bool>,
402400
pub profiler: Option<bool>,
403401
pub crt_static: Option<bool>,
404-
pub musl_root: Option<PathBuf>,
405-
pub musl_libdir: Option<PathBuf>,
406402
pub wasi_root: Option<PathBuf>,
407403
pub qemu_rootfs: Option<PathBuf>,
408404
pub no_std: bool,
@@ -694,7 +690,6 @@ define_config! {
694690
default_linker: Option<String> = "default-linker",
695691
channel: Option<String> = "channel",
696692
description: Option<String> = "description",
697-
musl_root: Option<String> = "musl-root",
698693
rpath: Option<bool> = "rpath",
699694
verbose_tests: Option<bool> = "verbose-tests",
700695
optimize_tests: Option<bool> = "optimize-tests",
@@ -739,8 +734,6 @@ define_config! {
739734
sanitizers: Option<bool> = "sanitizers",
740735
profiler: Option<bool> = "profiler",
741736
crt_static: Option<bool> = "crt-static",
742-
musl_root: Option<String> = "musl-root",
743-
musl_libdir: Option<String> = "musl-libdir",
744737
wasi_root: Option<String> = "wasi-root",
745738
qemu_rootfs: Option<String> = "qemu-rootfs",
746739
no_std: Option<bool> = "no-std",
@@ -1110,7 +1103,6 @@ impl Config {
11101103
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
11111104
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
11121105
config.rustc_default_linker = rust.default_linker;
1113-
config.musl_root = rust.musl_root.map(PathBuf::from);
11141106
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
11151107
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
11161108
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
@@ -1163,8 +1155,6 @@ impl Config {
11631155
target.ranlib = cfg.ranlib.map(PathBuf::from);
11641156
target.linker = cfg.linker.map(PathBuf::from);
11651157
target.crt_static = cfg.crt_static;
1166-
target.musl_root = cfg.musl_root.map(PathBuf::from);
1167-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
11681158
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
11691159
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
11701160
target.sanitizers = cfg.sanitizers;

src/bootstrap/configure.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,6 @@ def v(*args):
112112
"aarch64-linux-android NDK standalone path")
113113
v("x86_64-linux-android-ndk", "target.x86_64-linux-android.android-ndk",
114114
"x86_64-linux-android NDK standalone path")
115-
v("musl-root", "target.x86_64-unknown-linux-musl.musl-root",
116-
"MUSL root installation directory (deprecated)")
117-
v("musl-root-x86_64", "target.x86_64-unknown-linux-musl.musl-root",
118-
"x86_64-unknown-linux-musl install directory")
119-
v("musl-root-i586", "target.i586-unknown-linux-musl.musl-root",
120-
"i586-unknown-linux-musl install directory")
121-
v("musl-root-i686", "target.i686-unknown-linux-musl.musl-root",
122-
"i686-unknown-linux-musl install directory")
123-
v("musl-root-arm", "target.arm-unknown-linux-musleabi.musl-root",
124-
"arm-unknown-linux-musleabi install directory")
125-
v("musl-root-armhf", "target.arm-unknown-linux-musleabihf.musl-root",
126-
"arm-unknown-linux-musleabihf install directory")
127-
v("musl-root-armv5te", "target.armv5te-unknown-linux-musleabi.musl-root",
128-
"armv5te-unknown-linux-musleabi install directory")
129-
v("musl-root-armv7", "target.armv7-unknown-linux-musleabi.musl-root",
130-
"armv7-unknown-linux-musleabi install directory")
131-
v("musl-root-armv7hf", "target.armv7-unknown-linux-musleabihf.musl-root",
132-
"armv7-unknown-linux-musleabihf install directory")
133-
v("musl-root-aarch64", "target.aarch64-unknown-linux-musl.musl-root",
134-
"aarch64-unknown-linux-musl install directory")
135-
v("musl-root-mips", "target.mips-unknown-linux-musl.musl-root",
136-
"mips-unknown-linux-musl install directory")
137-
v("musl-root-mipsel", "target.mipsel-unknown-linux-musl.musl-root",
138-
"mipsel-unknown-linux-musl install directory")
139-
v("musl-root-mips64", "target.mips64-unknown-linux-muslabi64.musl-root",
140-
"mips64-unknown-linux-muslabi64 install directory")
141-
v("musl-root-mips64el", "target.mips64el-unknown-linux-muslabi64.musl-root",
142-
"mips64el-unknown-linux-muslabi64 install directory")
143115
v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs",
144116
"rootfs in qemu testing, you probably don't want to use this")
145117
v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs",

src/bootstrap/lib.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,25 +1151,6 @@ impl Build {
11511151
}
11521152
}
11531153

1154-
/// Returns the "musl root" for this `target`, if defined
1155-
fn musl_root(&self, target: TargetSelection) -> Option<&Path> {
1156-
self.config
1157-
.target_config
1158-
.get(&target)
1159-
.and_then(|t| t.musl_root.as_ref())
1160-
.or_else(|| self.config.musl_root.as_ref())
1161-
.map(|p| &**p)
1162-
}
1163-
1164-
/// Returns the "musl libdir" for this `target`.
1165-
fn musl_libdir(&self, target: TargetSelection) -> Option<PathBuf> {
1166-
let t = self.config.target_config.get(&target)?;
1167-
if let libdir @ Some(_) = &t.musl_libdir {
1168-
return libdir.clone();
1169-
}
1170-
self.musl_root(target).map(|root| root.join("lib"))
1171-
}
1172-
11731154
/// Returns the sysroot for the wasi target, if defined
11741155
fn wasi_root(&self, target: TargetSelection) -> Option<&Path> {
11751156
self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p)

src/bootstrap/sanity.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::collections::HashMap;
1212
use std::env;
1313
use std::ffi::{OsStr, OsString};
14-
use std::fs;
1514
use std::path::PathBuf;
1615
use std::process::Command;
1716

@@ -190,28 +189,6 @@ than building it.
190189
}
191190
}
192191

193-
// Make sure musl-root is valid
194-
if target.contains("musl") {
195-
// If this is a native target (host is also musl) and no musl-root is given,
196-
// fall back to the system toolchain in /usr before giving up
197-
if build.musl_root(*target).is_none() && build.config.build == *target {
198-
let target = build.config.target_config.entry(*target).or_default();
199-
target.musl_root = Some("/usr".into());
200-
}
201-
match build.musl_libdir(*target) {
202-
Some(libdir) => {
203-
if fs::metadata(libdir.join("libc.a")).is_err() {
204-
panic!("couldn't find libc.a in musl libdir: {}", libdir.display());
205-
}
206-
}
207-
None => panic!(
208-
"when targeting MUSL either the rust.musl-root \
209-
option or the target.$TARGET.musl-root option must \
210-
be specified in config.toml"
211-
),
212-
}
213-
}
214-
215192
if need_cmake && target.contains("msvc") {
216193
// There are three builds of cmake on windows: MSVC, MinGW, and
217194
// Cygwin. The Cygwin build does not have generators for Visual

src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ COPY scripts/cmake.sh /scripts/
3434
RUN /scripts/cmake.sh
3535

3636
ENV RUST_CONFIGURE_ARGS \
37-
--musl-root-i586=/musl-i586 \
38-
--musl-root-i686=/musl-i686 \
3937
--disable-docs
4038

4139
# Newer binutils broke things on some vms/distros (i.e., linking against

0 commit comments

Comments
 (0)