From 1e13488d9fc661f8f489609dcfc6ed8b61957ca3 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Fri, 8 Sep 2017 22:11:14 -0500 Subject: [PATCH 06/15] Remove musl_root and CRT fallback from musl targets --- config.toml.example | 12 -------- src/bootstrap/cc_detect.rs | 27 ++---------------- src/bootstrap/compile.rs | 28 +------------------ src/bootstrap/config.rs | 10 ------- src/bootstrap/configure.py | 28 ------------------- src/bootstrap/lib.rs | 19 ------------- src/bootstrap/sanity.rs | 22 --------------- .../dist-i586-gnu-i586-i686-musl/Dockerfile | 2 -- .../host-x86_64/dist-various-1/Dockerfile | 9 ------ .../host-x86_64/dist-various-2/Dockerfile | 3 +- .../host-x86_64/dist-x86_64-musl/Dockerfile | 1 - .../host-x86_64/test-various/Dockerfile | 1 - src/librustc_codegen_ssa/back/link.rs | 6 +--- src/librustc_target/spec/crt_objects.rs | 18 ------------ src/librustc_target/spec/linux_musl_base.rs | 5 ---- 15 files changed, 5 insertions(+), 186 deletions(-) diff --git a/config.toml.example b/config.toml.example index 36587cc0784..c74dd740868 100644 --- a/config.toml.example +++ b/config.toml.example @@ -385,9 +385,6 @@ # nightly features #channel = "dev" -# The root location of the musl installation directory. -#musl-root = "..." - # By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix # platforms to ensure that the compiler is usable by default from the build # directory (as it links to a number of dynamic libraries). This may not be @@ -530,15 +527,6 @@ # only use static libraries. If unset, the target's default linkage is used. #crt-static = false -# The root location of the musl installation directory. The library directory -# will also need to contain libunwind.a for an unwinding implementation. Note -# that this option only makes sense for musl targets that produce statically -# linked binaries -#musl-root = "..." - -# The full path to the musl libdir. -#musl-libdir = musl-root/lib - # The root location of the `wasm32-wasi` sysroot. #wasi-root = "..." diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index 7ff00d85dd2..ae80d8a5963 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -42,8 +42,6 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option { Some(PathBuf::from(ar)) } else if target.contains("msvc") { None - } else if target.contains("musl") { - Some(PathBuf::from("ar")) } else if target.contains("openbsd") { Some(PathBuf::from("ar")) } else if target.contains("vxworks") { @@ -98,7 +96,7 @@ pub fn find(build: &mut Build) { if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { cfg.compiler(cc); } else { - set_compiler(&mut cfg, Language::C, target, config, build); + set_compiler(&mut cfg, Language::C, target, config); } let compiler = cfg.get_compiler(); @@ -126,7 +124,7 @@ pub fn find(build: &mut Build) { cfg.compiler(cxx); true } else if build.hosts.contains(&target) || build.build == target { - set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); + set_compiler(&mut cfg, Language::CPlusPlus, target, config); true } else { false @@ -155,7 +153,6 @@ fn set_compiler( compiler: Language, target: TargetSelection, config: Option<&Target>, - build: &Build, ) { match &*target.triple { // When compiling for android we may have the NDK configured in the @@ -198,26 +195,6 @@ fn set_compiler( } } - "mips-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mips-linux-musl-gcc"); - } - } - "mipsel-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mipsel-linux-musl-gcc"); - } - } - - t if t.contains("musl") => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { - cfg.compiler(guess); - } - } - } - _ => {} } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 373e240cb8e..0be09300f7c 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -166,24 +166,7 @@ fn copy_self_contained_objects( // Copies the CRT objects. // - // rustc historically provides a more self-contained installation for musl targets - // not requiring the presence of a native musl toolchain. For example, it can fall back - // to using gcc from a glibc-targeting toolchain for linking. - // To do that we have to distribute musl startup objects as a part of Rust toolchain - // and link with them manually in the self-contained mode. - if target.contains("musl") { - let srcdir = builder.musl_libdir(target).unwrap(); - for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - } else if target.ends_with("-wasi") { + if target.ends_with("-wasi") { let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi"); copy_and_stamp( builder, @@ -258,15 +241,6 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car .arg("--manifest-path") .arg(builder.src.join("library/test/Cargo.toml")); - // Help the libc crate compile by assisting it in finding various - // sysroot native libraries. - if target.contains("musl") { - if let Some(p) = builder.musl_libdir(target) { - let root = format!("native={}", p.to_str().unwrap()); - cargo.rustflag("-L").rustflag(&root); - } - } - if target.ends_with("-wasi") { if let Some(p) = builder.wasi_root(target) { let root = format!("native={}/lib/wasm32-wasi", p.to_str().unwrap()); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 8b8b01b1153..d4469ed1f96 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -137,8 +137,6 @@ pub struct Config { pub print_step_timings: bool, pub missing_tools: bool, - // Fallback musl-root for all targets - pub musl_root: Option, pub prefix: Option, pub sysconfdir: Option, pub datadir: Option, @@ -235,8 +233,6 @@ pub struct Target { pub linker: Option, pub ndk: Option, pub crt_static: Option, - pub musl_root: Option, - pub musl_libdir: Option, pub wasi_root: Option, pub qemu_rootfs: Option, pub no_std: bool, @@ -390,7 +386,6 @@ struct Rust { parallel_compiler: Option, default_linker: Option, channel: Option, - musl_root: Option, rpath: Option, verbose_tests: Option, optimize_tests: Option, @@ -427,8 +422,6 @@ struct TomlTarget { llvm_filecheck: Option, android_ndk: Option, crt_static: Option, - musl_root: Option, - musl_libdir: Option, wasi_root: Option, qemu_rootfs: Option, no_std: Option, @@ -659,7 +652,6 @@ impl Config { set(&mut config.llvm_tools_enabled, rust.llvm_tools); config.rustc_parallel = rust.parallel_compiler.unwrap_or(false); config.rustc_default_linker = rust.default_linker.clone(); - config.musl_root = rust.musl_root.clone().map(PathBuf::from); config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from); set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); @@ -699,8 +691,6 @@ impl Config { target.ranlib = cfg.ranlib.clone().map(PathBuf::from); target.linker = cfg.linker.clone().map(PathBuf::from); target.crt_static = cfg.crt_static; - target.musl_root = cfg.musl_root.clone().map(PathBuf::from); - target.musl_libdir = cfg.musl_libdir.clone().map(PathBuf::from); target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 47673ce1e87..33004e317ce 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -109,34 +109,6 @@ v("aarch64-linux-android-ndk", "target.aarch64-linux-android.android-ndk", "aarch64-linux-android NDK standalone path") v("x86_64-linux-android-ndk", "target.x86_64-linux-android.android-ndk", "x86_64-linux-android NDK standalone path") -v("musl-root", "target.x86_64-unknown-linux-musl.musl-root", - "MUSL root installation directory (deprecated)") -v("musl-root-x86_64", "target.x86_64-unknown-linux-musl.musl-root", - "x86_64-unknown-linux-musl install directory") -v("musl-root-i586", "target.i586-unknown-linux-musl.musl-root", - "i586-unknown-linux-musl install directory") -v("musl-root-i686", "target.i686-unknown-linux-musl.musl-root", - "i686-unknown-linux-musl install directory") -v("musl-root-arm", "target.arm-unknown-linux-musleabi.musl-root", - "arm-unknown-linux-musleabi install directory") -v("musl-root-armhf", "target.arm-unknown-linux-musleabihf.musl-root", - "arm-unknown-linux-musleabihf install directory") -v("musl-root-armv5te", "target.armv5te-unknown-linux-musleabi.musl-root", - "armv5te-unknown-linux-musleabi install directory") -v("musl-root-armv7", "target.armv7-unknown-linux-musleabi.musl-root", - "armv7-unknown-linux-musleabi install directory") -v("musl-root-armv7hf", "target.armv7-unknown-linux-musleabihf.musl-root", - "armv7-unknown-linux-musleabihf install directory") -v("musl-root-aarch64", "target.aarch64-unknown-linux-musl.musl-root", - "aarch64-unknown-linux-musl install directory") -v("musl-root-mips", "target.mips-unknown-linux-musl.musl-root", - "mips-unknown-linux-musl install directory") -v("musl-root-mipsel", "target.mipsel-unknown-linux-musl.musl-root", - "mipsel-unknown-linux-musl install directory") -v("musl-root-mips64", "target.mips64-unknown-linux-muslabi64.musl-root", - "mips64-unknown-linux-muslabi64 install directory") -v("musl-root-mips64el", "target.mips64el-unknown-linux-muslabi64.musl-root", - "mips64el-unknown-linux-muslabi64 install directory") v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs", "rootfs in qemu testing, you probably don't want to use this") v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs", diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 77316c734b8..b92da611a51 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -875,25 +875,6 @@ impl Build { } } - /// Returns the "musl root" for this `target`, if defined - fn musl_root(&self, target: TargetSelection) -> Option<&Path> { - self.config - .target_config - .get(&target) - .and_then(|t| t.musl_root.as_ref()) - .or_else(|| self.config.musl_root.as_ref()) - .map(|p| &**p) - } - - /// Returns the "musl libdir" for this `target`. - fn musl_libdir(&self, target: TargetSelection) -> Option { - let t = self.config.target_config.get(&target)?; - if let libdir @ Some(_) = &t.musl_libdir { - return libdir.clone(); - } - self.musl_root(target).map(|root| root.join("lib")) - } - /// Returns the sysroot for the wasi target, if defined fn wasi_root(&self, target: TargetSelection) -> Option<&Path> { self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p) diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index f89bef50de9..e22638c533e 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -195,28 +195,6 @@ pub fn check(build: &mut Build) { } } - // Make sure musl-root is valid - if target.contains("musl") { - // If this is a native target (host is also musl) and no musl-root is given, - // fall back to the system toolchain in /usr before giving up - if build.musl_root(*target).is_none() && build.config.build == *target { - let target = build.config.target_config.entry(target.clone()).or_default(); - target.musl_root = Some("/usr".into()); - } - match build.musl_libdir(*target) { - Some(libdir) => { - if fs::metadata(libdir.join("libc.a")).is_err() { - panic!("couldn't find libc.a in musl libdir: {}", libdir.display()); - } - } - None => panic!( - "when targeting MUSL either the rust.musl-root \ - option or the target.$TARGET.musl-root option must \ - be specified in config.toml" - ), - } - } - if target.contains("msvc") { // There are three builds of cmake on windows: MSVC, MinGW, and // Cygwin. The Cygwin build does not have generators for Visual diff --git a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile index 162d7a1345c..48f025fd542 100644 --- a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile @@ -30,8 +30,6 @@ COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ - --musl-root-i586=/musl-i586 \ - --musl-root-i686=/musl-i686 \ --disable-docs # Newer binutils broke things on some vms/distros (i.e., linking against diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index fdd777e824b..2b3d090c1ae 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -180,15 +180,6 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \ CC_riscv64gc_unknown_none_elf=false ENV RUST_CONFIGURE_ARGS \ - --musl-root-armv5te=/musl-armv5te \ - --musl-root-arm=/musl-arm \ - --musl-root-armhf=/musl-armhf \ - --musl-root-armv7hf=/musl-armv7hf \ - --musl-root-aarch64=/musl-aarch64 \ - --musl-root-mips=/musl-mips \ - --musl-root-mipsel=/musl-mipsel \ - --musl-root-mips64=/musl-mips64 \ - --musl-root-mips64el=/musl-mips64el \ --disable-docs ENV SCRIPT \ diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index 3081f29aef2..223547bf8cd 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -107,7 +107,6 @@ ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi RUN ln -s /usr/include/asm-generic /usr/local/include/asm ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs \ - --set target.wasm32-wasi.wasi-root=/wasm32-wasi \ - --musl-root-armv7=/musl-armv7 + --set target.wasm32-wasi.wasi-root=/wasm32-wasi ENV SCRIPT python3 ../x.py dist --target $TARGETS diff --git a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile index ab6515cd1fa..5203d604150 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile @@ -31,7 +31,6 @@ RUN sh /scripts/sccache.sh ENV HOSTS=x86_64-unknown-linux-musl ENV RUST_CONFIGURE_ARGS \ - --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --enable-extended \ --enable-lld \ --set target.x86_64-unknown-linux-musl.crt-static=false \ diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index c55a284e137..a808a915fcb 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -29,7 +29,6 @@ COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ - --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --set build.nodejs=/node-v14.4.0-linux-x64/bin/node \ --set rust.lld diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 70bc9d5e980..b35fe073d26 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1288,16 +1288,12 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind { /// Whether we link to our own CRT objects instead of relying on gcc to pull them. /// We only provide such support for a very limited number of targets. -fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool { +fn crt_objects_fallback(sess: &Session, _crate_type: CrateType) -> bool { if let Some(self_contained) = sess.opts.debugging_opts.link_self_contained { return self_contained; } match sess.target.target.options.crt_objects_fallback { - // FIXME: Find a better heuristic for "native musl toolchain is available", - // based on host and linker path, for example. - // (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237). - Some(CrtObjectsFallback::Musl) => sess.crt_static(Some(crate_type)), // FIXME: Find some heuristic for "native mingw toolchain is available", // likely based on `get_crt_libs_path` (https://github.com/rust-lang/rust/pull/67429). Some(CrtObjectsFallback::Mingw) => { diff --git a/src/librustc_target/spec/crt_objects.rs b/src/librustc_target/spec/crt_objects.rs index 8991691a9a3..b7e47afd942 100644 --- a/src/librustc_target/spec/crt_objects.rs +++ b/src/librustc_target/spec/crt_objects.rs @@ -61,21 +61,6 @@ pub(super) fn all(obj: &str) -> CrtObjects { ]) } -pub(super) fn pre_musl_fallback() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o"]), - (LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o"]), - (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o"]), - (LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o"]), - (LinkOutputKind::DynamicDylib, &["crti.o"]), - (LinkOutputKind::StaticDylib, &["crti.o"]), - ]) -} - -pub(super) fn post_musl_fallback() -> CrtObjects { - all("crtn.o") -} - pub(super) fn pre_mingw_fallback() -> CrtObjects { new(&[ (LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]), @@ -115,7 +100,6 @@ pub(super) fn post_wasi_fallback() -> CrtObjects { /// Which logic to use to determine whether to fall back to the "self-contained" mode or not. #[derive(Clone, Copy, PartialEq, Hash, Debug)] pub enum CrtObjectsFallback { - Musl, Mingw, Wasm, } @@ -125,7 +109,6 @@ impl FromStr for CrtObjectsFallback { fn from_str(s: &str) -> Result { Ok(match s { - "musl" => CrtObjectsFallback::Musl, "mingw" => CrtObjectsFallback::Mingw, "wasm" => CrtObjectsFallback::Wasm, _ => return Err(()), @@ -136,7 +119,6 @@ impl FromStr for CrtObjectsFallback { impl ToJson for CrtObjectsFallback { fn to_json(&self) -> Json { match *self { - CrtObjectsFallback::Musl => "musl", CrtObjectsFallback::Mingw => "mingw", CrtObjectsFallback::Wasm => "wasm", } diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs index b90e91d2901..c5f5f99a96d 100644 --- a/src/librustc_target/spec/linux_musl_base.rs +++ b/src/librustc_target/spec/linux_musl_base.rs @@ -1,13 +1,8 @@ -use crate::spec::crt_objects::{self, CrtObjectsFallback}; use crate::spec::TargetOptions; pub fn opts() -> TargetOptions { let mut base = super::linux_base::opts(); - base.pre_link_objects_fallback = crt_objects::pre_musl_fallback(); - base.post_link_objects_fallback = crt_objects::post_musl_fallback(); - base.crt_objects_fallback = Some(CrtObjectsFallback::Musl); - // These targets statically link libc by default base.crt_static_default = true; // These targets allow the user to choose between static and dynamic linking. -- 2.26.2