Skip to content

Commit 29098b3

Browse files
committed
Remove musl_root and CRT fallback from musl targets
1 parent c7204f1 commit 29098b3

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
@@ -1613,18 +1613,14 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
16131613
/// Various toolchain components used during linking are used from rustc distribution
16141614
/// instead of being found somewhere on the host system.
16151615
/// We only provide such support for a very limited number of targets.
1616-
fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
1616+
fn self_contained(sess: &Session, _crate_type: CrateType) -> bool {
16171617
if let Some(self_contained) = sess.opts.cg.link_self_contained {
16181618
return self_contained;
16191619
}
16201620

16211621
match sess.target.link_self_contained {
16221622
LinkSelfContainedDefault::False => false,
16231623
LinkSelfContainedDefault::True => true,
1624-
// FIXME: Find a better heuristic for "native musl toolchain is available",
1625-
// based on host and linker path, for example.
1626-
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
1627-
LinkSelfContainedDefault::Musl => sess.crt_static(Some(crate_type)),
16281624
LinkSelfContainedDefault::Mingw => {
16291625
sess.host == sess.target
16301626
&& 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_self_contained() -> 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_self_contained() -> 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_self_contained() -> CrtObjects {
8967
new(&[
9068
(LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
@@ -130,7 +108,6 @@ pub(super) fn post_wasi_self_contained() -> CrtObjects {
130108
pub enum LinkSelfContainedDefault {
131109
False,
132110
True,
133-
Musl,
134111
Mingw,
135112
}
136113

@@ -141,7 +118,6 @@ impl FromStr for LinkSelfContainedDefault {
141118
Ok(match s {
142119
"false" => LinkSelfContainedDefault::False,
143120
"true" | "wasm" => LinkSelfContainedDefault::True,
144-
"musl" => LinkSelfContainedDefault::Musl,
145121
"mingw" => LinkSelfContainedDefault::Mingw,
146122
_ => return Err(()),
147123
})
@@ -153,7 +129,6 @@ impl ToJson for LinkSelfContainedDefault {
153129
match *self {
154130
LinkSelfContainedDefault::False => "false",
155131
LinkSelfContainedDefault::True => "true",
156-
LinkSelfContainedDefault::Musl => "musl",
157132
LinkSelfContainedDefault::Mingw => "mingw",
158133
}
159134
.to_json()

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, LinkSelfContainedDefault};
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_self_contained = crt_objects::pre_musl_self_contained();
9-
base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
10-
base.link_self_contained = LinkSelfContainedDefault::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
@@ -533,14 +533,6 @@ changelog-seen = 2
533533
# behavior -- this may lead to miscompilations or other bugs.
534534
#description = <none> (string)
535535

536-
# The root location of the musl installation directory. The library directory
537-
# will also need to contain libunwind.a for an unwinding implementation. Note
538-
# that this option only makes sense for musl targets that produce statically
539-
# linked binaries.
540-
#
541-
# Defaults to /usr on musl hosts. Has no default otherwise.
542-
#musl-root = <platform specific> (path)
543-
544536
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
545537
# platforms to ensure that the compiler is usable by default from the build
546538
# directory (as it links to a number of dynamic libraries). This may not be
@@ -722,15 +714,6 @@ changelog-seen = 2
722714
# only use static libraries. If unset, the target's default linkage is used.
723715
#crt-static = <platform-specific> (bool)
724716

725-
# The root location of the musl installation directory. The library directory
726-
# will also need to contain libunwind.a for an unwinding implementation. Note
727-
# that this option only makes sense for musl targets that produce statically
728-
# linked binaries.
729-
#musl-root = build.musl-root (path)
730-
731-
# The full path to the musl libdir.
732-
#musl-libdir = musl-root/lib
733-
734717
# The root location of the `wasm32-wasi` sysroot. Only used for the
735718
# `wasm32-wasi` target. If you are building wasm32-wasi target, make sure to
736719
# 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(|| {
@@ -350,15 +319,6 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
350319
.arg("--manifest-path")
351320
.arg(builder.src.join("library/test/Cargo.toml"));
352321

353-
// Help the libc crate compile by assisting it in finding various
354-
// sysroot native libraries.
355-
if target.contains("musl") {
356-
if let Some(p) = builder.musl_libdir(target) {
357-
let root = format!("native={}", p.to_str().unwrap());
358-
cargo.rustflag("-L").rustflag(&root);
359-
}
360-
}
361-
362322
if target.ends_with("-wasi") {
363323
if let Some(p) = builder.wasi_root(target) {
364324
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
@@ -190,8 +190,6 @@ pub struct Config {
190190
pub print_step_rusage: bool,
191191
pub missing_tools: bool,
192192

193-
// Fallback musl-root for all targets
194-
pub musl_root: Option<PathBuf>,
195193
pub prefix: Option<PathBuf>,
196194
pub sysconfdir: Option<PathBuf>,
197195
pub datadir: Option<PathBuf>,
@@ -429,8 +427,6 @@ pub struct Target {
429427
pub sanitizers: Option<bool>,
430428
pub profiler: Option<bool>,
431429
pub crt_static: Option<bool>,
432-
pub musl_root: Option<PathBuf>,
433-
pub musl_libdir: Option<PathBuf>,
434430
pub wasi_root: Option<PathBuf>,
435431
pub qemu_rootfs: Option<PathBuf>,
436432
pub no_std: bool,
@@ -723,7 +719,6 @@ define_config! {
723719
default_linker: Option<String> = "default-linker",
724720
channel: Option<String> = "channel",
725721
description: Option<String> = "description",
726-
musl_root: Option<String> = "musl-root",
727722
rpath: Option<bool> = "rpath",
728723
verbose_tests: Option<bool> = "verbose-tests",
729724
optimize_tests: Option<bool> = "optimize-tests",
@@ -770,8 +765,6 @@ define_config! {
770765
sanitizers: Option<bool> = "sanitizers",
771766
profiler: Option<bool> = "profiler",
772767
crt_static: Option<bool> = "crt-static",
773-
musl_root: Option<String> = "musl-root",
774-
musl_libdir: Option<String> = "musl-libdir",
775768
wasi_root: Option<String> = "wasi-root",
776769
qemu_rootfs: Option<String> = "qemu-rootfs",
777770
no_std: Option<bool> = "no-std",
@@ -1175,7 +1168,6 @@ impl Config {
11751168
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
11761169
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
11771170
config.rustc_default_linker = rust.default_linker;
1178-
config.musl_root = rust.musl_root.map(PathBuf::from);
11791171
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
11801172
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
11811173
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
@@ -1235,8 +1227,6 @@ impl Config {
12351227
target.ranlib = cfg.ranlib.map(PathBuf::from);
12361228
target.linker = cfg.linker.map(PathBuf::from);
12371229
target.crt_static = cfg.crt_static;
1238-
target.musl_root = cfg.musl_root.map(PathBuf::from);
1239-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
12401230
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
12411231
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
12421232
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
@@ -1168,25 +1168,6 @@ impl Build {
11681168
}
11691169
}
11701170

1171-
/// Returns the "musl root" for this `target`, if defined
1172-
fn musl_root(&self, target: TargetSelection) -> Option<&Path> {
1173-
self.config
1174-
.target_config
1175-
.get(&target)
1176-
.and_then(|t| t.musl_root.as_ref())
1177-
.or_else(|| self.config.musl_root.as_ref())
1178-
.map(|p| &**p)
1179-
}
1180-
1181-
/// Returns the "musl libdir" for this `target`.
1182-
fn musl_libdir(&self, target: TargetSelection) -> Option<PathBuf> {
1183-
let t = self.config.target_config.get(&target)?;
1184-
if let libdir @ Some(_) = &t.musl_libdir {
1185-
return libdir.clone();
1186-
}
1187-
self.musl_root(target).map(|root| root.join("lib"))
1188-
}
1189-
11901171
/// Returns the sysroot for the wasi target, if defined
11911172
fn wasi_root(&self, target: TargetSelection) -> Option<&Path> {
11921173
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

0 commit comments

Comments
 (0)