Skip to content

Commit 575b255

Browse files
committed
Remove musl_root and CRT fallback from musl targets
1 parent 741978c commit 575b255

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
@@ -1573,18 +1573,14 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15731573
/// Various toolchain components used during linking are used from rustc distribution
15741574
/// instead of being found somewhere on the host system.
15751575
/// We only provide such support for a very limited number of targets.
1576-
fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
1576+
fn self_contained(sess: &Session, _crate_type: CrateType) -> bool {
15771577
if let Some(self_contained) = sess.opts.cg.link_self_contained {
15781578
return self_contained;
15791579
}
15801580

15811581
match sess.target.link_self_contained {
15821582
LinkSelfContainedDefault::False => false,
15831583
LinkSelfContainedDefault::True => true,
1584-
// FIXME: Find a better heuristic for "native musl toolchain is available",
1585-
// based on host and linker path, for example.
1586-
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
1587-
LinkSelfContainedDefault::Musl => sess.crt_static(Some(crate_type)),
15881584
LinkSelfContainedDefault::Mingw => {
15891585
sess.host == sess.target
15901586
&& 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
@@ -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
@@ -707,15 +699,6 @@ changelog-seen = 2
707699
# only use static libraries. If unset, the target's default linkage is used.
708700
#crt-static = <platform-specific> (bool)
709701

710-
# The root location of the musl installation directory. The library directory
711-
# will also need to contain libunwind.a for an unwinding implementation. Note
712-
# that this option only makes sense for musl targets that produce statically
713-
# linked binaries.
714-
#musl-root = build.musl-root (path)
715-
716-
# The full path to the musl libdir.
717-
#musl-libdir = musl-root/lib
718-
719702
# The root location of the `wasm32-wasi` sysroot. Only used for the
720703
# `wasm32-wasi` target. If you are building wasm32-wasi target, make sure to
721704
# 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>,
@@ -402,8 +400,6 @@ pub struct Target {
402400
pub sanitizers: Option<bool>,
403401
pub profiler: Option<bool>,
404402
pub crt_static: Option<bool>,
405-
pub musl_root: Option<PathBuf>,
406-
pub musl_libdir: Option<PathBuf>,
407403
pub wasi_root: Option<PathBuf>,
408404
pub qemu_rootfs: Option<PathBuf>,
409405
pub no_std: bool,
@@ -695,7 +691,6 @@ define_config! {
695691
default_linker: Option<String> = "default-linker",
696692
channel: Option<String> = "channel",
697693
description: Option<String> = "description",
698-
musl_root: Option<String> = "musl-root",
699694
rpath: Option<bool> = "rpath",
700695
verbose_tests: Option<bool> = "verbose-tests",
701696
optimize_tests: Option<bool> = "optimize-tests",
@@ -741,8 +736,6 @@ define_config! {
741736
sanitizers: Option<bool> = "sanitizers",
742737
profiler: Option<bool> = "profiler",
743738
crt_static: Option<bool> = "crt-static",
744-
musl_root: Option<String> = "musl-root",
745-
musl_libdir: Option<String> = "musl-libdir",
746739
wasi_root: Option<String> = "wasi-root",
747740
qemu_rootfs: Option<String> = "qemu-rootfs",
748741
no_std: Option<bool> = "no-std",
@@ -1077,7 +1070,6 @@ impl Config {
10771070
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
10781071
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
10791072
config.rustc_default_linker = rust.default_linker;
1080-
config.musl_root = rust.musl_root.map(PathBuf::from);
10811073
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
10821074
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
10831075
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
@@ -1131,8 +1123,6 @@ impl Config {
11311123
target.ranlib = cfg.ranlib.map(PathBuf::from);
11321124
target.linker = cfg.linker.map(PathBuf::from);
11331125
target.crt_static = cfg.crt_static;
1134-
target.musl_root = cfg.musl_root.map(PathBuf::from);
1135-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
11361126
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
11371127
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
11381128
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
@@ -1154,25 +1154,6 @@ impl Build {
11541154
}
11551155
}
11561156

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