Skip to content

Commit 71bd5c3

Browse files
committed
Remove musl_root and CRT fallback from musl targets
1 parent db60aef commit 71bd5c3

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
@@ -1583,7 +1583,7 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15831583
/// Various toolchain components used during linking are used from rustc distribution
15841584
/// instead of being found somewhere on the host system.
15851585
/// We only provide such support for a very limited number of targets.
1586-
fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
1586+
fn self_contained(sess: &Session, _crate_type: CrateType) -> bool {
15871587
if let Some(self_contained) = sess.opts.cg.link_self_contained {
15881588
if sess.target.link_self_contained == LinkSelfContainedDefault::False {
15891589
sess.emit_err(errors::UnsupportedLinkSelfContained);
@@ -1594,10 +1594,6 @@ fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
15941594
match sess.target.link_self_contained {
15951595
LinkSelfContainedDefault::False => false,
15961596
LinkSelfContainedDefault::True => true,
1597-
// FIXME: Find a better heuristic for "native musl toolchain is available",
1598-
// based on host and linker path, for example.
1599-
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
1600-
LinkSelfContainedDefault::Musl => sess.crt_static(Some(crate_type)),
16011597
LinkSelfContainedDefault::Mingw => {
16021598
sess.host == sess.target
16031599
&& 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
@@ -540,14 +540,6 @@ changelog-seen = 2
540540
# behavior -- this may lead to miscompilations or other bugs.
541541
#description = <none> (string)
542542

543-
# The root location of the musl installation directory. The library directory
544-
# will also need to contain libunwind.a for an unwinding implementation. Note
545-
# that this option only makes sense for musl targets that produce statically
546-
# linked binaries.
547-
#
548-
# Defaults to /usr on musl hosts. Has no default otherwise.
549-
#musl-root = <platform specific> (path)
550-
551543
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
552544
# platforms to ensure that the compiler is usable by default from the build
553545
# directory (as it links to a number of dynamic libraries). This may not be
@@ -729,15 +721,6 @@ changelog-seen = 2
729721
# only use static libraries. If unset, the target's default linkage is used.
730722
#crt-static = <platform-specific> (bool)
731723

732-
# The root location of the musl installation directory. The library directory
733-
# will also need to contain libunwind.a for an unwinding implementation. Note
734-
# that this option only makes sense for musl targets that produce statically
735-
# linked binaries.
736-
#musl-root = build.musl-root (path)
737-
738-
# The full path to the musl libdir.
739-
#musl-libdir = musl-root/lib
740-
741724
# The root location of the `wasm32-wasi` sysroot. Only used for the
742725
# `wasm32-wasi` target. If you are building wasm32-wasi target, make sure to
743726
# 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
@@ -194,26 +191,6 @@ fn set_compiler(
194191
}
195192
}
196193

197-
"mips-unknown-linux-musl" => {
198-
if cfg.get_compiler().path().to_str() == Some("gcc") {
199-
cfg.compiler("mips-linux-musl-gcc");
200-
}
201-
}
202-
"mipsel-unknown-linux-musl" => {
203-
if cfg.get_compiler().path().to_str() == Some("gcc") {
204-
cfg.compiler("mipsel-linux-musl-gcc");
205-
}
206-
}
207-
208-
t if t.contains("musl") => {
209-
if let Some(root) = build.musl_root(target) {
210-
let guess = root.join("bin/musl-gcc");
211-
if guess.exists() {
212-
cfg.compiler(guess);
213-
}
214-
}
215-
}
216-
217194
_ => {}
218195
}
219196
}

src/bootstrap/compile.rs

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

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

347-
// Help the libc crate compile by assisting it in finding various
348-
// sysroot native libraries.
349-
if target.contains("musl") {
350-
if let Some(p) = builder.musl_libdir(target) {
351-
let root = format!("native={}", p.to_str().unwrap());
352-
cargo.rustflag("-L").rustflag(&root);
353-
}
354-
}
355-
356316
if target.ends_with("-wasi") {
357317
if let Some(p) = builder.wasi_root(target) {
358318
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
@@ -199,8 +199,6 @@ pub struct Config {
199199
pub print_step_rusage: bool,
200200
pub missing_tools: bool,
201201

202-
// Fallback musl-root for all targets
203-
pub musl_root: Option<PathBuf>,
204202
pub prefix: Option<PathBuf>,
205203
pub sysconfdir: Option<PathBuf>,
206204
pub datadir: Option<PathBuf>,
@@ -440,8 +438,6 @@ pub struct Target {
440438
pub sanitizers: Option<bool>,
441439
pub profiler: Option<bool>,
442440
pub crt_static: Option<bool>,
443-
pub musl_root: Option<PathBuf>,
444-
pub musl_libdir: Option<PathBuf>,
445441
pub wasi_root: Option<PathBuf>,
446442
pub qemu_rootfs: Option<PathBuf>,
447443
pub no_std: bool,
@@ -734,7 +730,6 @@ define_config! {
734730
default_linker: Option<String> = "default-linker",
735731
channel: Option<String> = "channel",
736732
description: Option<String> = "description",
737-
musl_root: Option<String> = "musl-root",
738733
rpath: Option<bool> = "rpath",
739734
verbose_tests: Option<bool> = "verbose-tests",
740735
optimize_tests: Option<bool> = "optimize-tests",
@@ -781,8 +776,6 @@ define_config! {
781776
sanitizers: Option<bool> = "sanitizers",
782777
profiler: Option<bool> = "profiler",
783778
crt_static: Option<bool> = "crt-static",
784-
musl_root: Option<String> = "musl-root",
785-
musl_libdir: Option<String> = "musl-libdir",
786779
wasi_root: Option<String> = "wasi-root",
787780
qemu_rootfs: Option<String> = "qemu-rootfs",
788781
no_std: Option<bool> = "no-std",
@@ -1187,7 +1180,6 @@ impl Config {
11871180
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
11881181
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
11891182
config.rustc_default_linker = rust.default_linker;
1190-
config.musl_root = rust.musl_root.map(PathBuf::from);
11911183
config.save_toolstates = rust.save_toolstates.map(PathBuf::from);
11921184
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings));
11931185
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
@@ -1251,8 +1243,6 @@ impl Config {
12511243
target.ranlib = cfg.ranlib.map(PathBuf::from);
12521244
target.linker = cfg.linker.map(PathBuf::from);
12531245
target.crt_static = cfg.crt_static;
1254-
target.musl_root = cfg.musl_root.map(PathBuf::from);
1255-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
12561246
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
12571247
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
12581248
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
@@ -1181,25 +1181,6 @@ impl Build {
11811181
}
11821182
}
11831183

1184-
/// Returns the "musl root" for this `target`, if defined
1185-
fn musl_root(&self, target: TargetSelection) -> Option<&Path> {
1186-
self.config
1187-
.target_config
1188-
.get(&target)
1189-
.and_then(|t| t.musl_root.as_ref())
1190-
.or_else(|| self.config.musl_root.as_ref())
1191-
.map(|p| &**p)
1192-
}
1193-
1194-
/// Returns the "musl libdir" for this `target`.
1195-
fn musl_libdir(&self, target: TargetSelection) -> Option<PathBuf> {
1196-
let t = self.config.target_config.get(&target)?;
1197-
if let libdir @ Some(_) = &t.musl_libdir {
1198-
return libdir.clone();
1199-
}
1200-
self.musl_root(target).map(|root| root.join("lib"))
1201-
}
1202-
12031184
/// Returns the sysroot for the wasi target, if defined
12041185
fn wasi_root(&self, target: TargetSelection) -> Option<&Path> {
12051186
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

@@ -205,28 +204,6 @@ than building it.
205204
}
206205
}
207206

208-
// Make sure musl-root is valid
209-
if target.contains("musl") {
210-
// If this is a native target (host is also musl) and no musl-root is given,
211-
// fall back to the system toolchain in /usr before giving up
212-
if build.musl_root(*target).is_none() && build.config.build == *target {
213-
let target = build.config.target_config.entry(*target).or_default();
214-
target.musl_root = Some("/usr".into());
215-
}
216-
match build.musl_libdir(*target) {
217-
Some(libdir) => {
218-
if fs::metadata(libdir.join("libc.a")).is_err() {
219-
panic!("couldn't find libc.a in musl libdir: {}", libdir.display());
220-
}
221-
}
222-
None => panic!(
223-
"when targeting MUSL either the rust.musl-root \
224-
option or the target.$TARGET.musl-root option must \
225-
be specified in config.toml"
226-
),
227-
}
228-
}
229-
230207
// Some environments don't want or need these tools, such as when testing Miri.
231208
// FIXME: it would be better to refactor this code to split necessary setup from pure sanity
232209
// checks, and have a regular flag for skipping the latter. Also see

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
@@ -58,8 +58,6 @@ COPY scripts/sccache.sh /scripts/
5858
RUN sh /scripts/sccache.sh
5959

6060
ENV RUST_CONFIGURE_ARGS \
61-
--musl-root-i586=/musl-i586 \
62-
--musl-root-i686=/musl-i686 \
6361
--disable-docs
6462

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

0 commit comments

Comments
 (0)