311 lines
14 KiB
Diff
311 lines
14 KiB
Diff
From ce1d0500b190f39c5bd9c34deed8b8d8af537c90 Mon Sep 17 00:00:00 2001
|
|
From: Samuel Holland <samuel@sholland.org>
|
|
Date: Sat, 21 Dec 2019 16:46:22 +0100
|
|
Subject: [PATCH 04/18] Remove -nostdlib and musl_root from musl targets
|
|
|
|
---
|
|
config.toml.example | 3 ---
|
|
src/bootstrap/cc_detect.rs | 27 +++-----------------
|
|
src/bootstrap/compile.rs | 22 +---------------
|
|
src/bootstrap/config.rs | 7 ------
|
|
src/bootstrap/configure.py | 28 ---------------------
|
|
src/bootstrap/lib.rs | 8 ------
|
|
src/bootstrap/sanity.rs | 24 ------------------
|
|
src/librustc_target/spec/linux_musl_base.rs | 16 ------------
|
|
8 files changed, 4 insertions(+), 131 deletions(-)
|
|
|
|
diff --git a/config.toml.example b/config.toml.example
|
|
index e832570e..81cc3a99 100644
|
|
--- a/config.toml.example
|
|
+++ b/config.toml.example
|
|
@@ -340,9 +340,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
|
|
diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs
|
|
index a4cb81d3..b4247e74 100644
|
|
--- a/src/bootstrap/cc_detect.rs
|
|
+++ b/src/bootstrap/cc_detect.rs
|
|
@@ -86,7 +86,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();
|
|
@@ -109,7 +109,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
|
|
@@ -136,8 +136,7 @@ pub fn find(build: &mut Build) {
|
|
fn set_compiler(cfg: &mut cc::Build,
|
|
compiler: Language,
|
|
target: Interned<String>,
|
|
- config: Option<&Target>,
|
|
- build: &Build) {
|
|
+ config: Option<&Target>) {
|
|
match &*target {
|
|
// When compiling for android we may have the NDK configured in the
|
|
// config.toml in which case we look there. Otherwise the default
|
|
@@ -177,26 +176,6 @@ fn set_compiler(cfg: &mut cc::Build,
|
|
}
|
|
}
|
|
|
|
- "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 8e5fe252..47372c97 100644
|
|
--- a/src/bootstrap/compile.rs
|
|
+++ b/src/bootstrap/compile.rs
|
|
@@ -130,18 +130,7 @@ fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target:
|
|
target_deps.push(target);
|
|
};
|
|
|
|
- // Copies the crt(1,i,n).o startup objects
|
|
- //
|
|
- // Since musl supports fully static linking, we can cross link for it even
|
|
- // with a glibc-targeting toolchain, given we have the appropriate startup
|
|
- // files. As those shipped with glibc won't work, copy the ones provided by
|
|
- // musl so we have them on linux-gnu hosts.
|
|
- if target.contains("musl") {
|
|
- let srcdir = builder.musl_root(target).unwrap().join("lib");
|
|
- for &obj in &["crt1.o", "crti.o", "crtn.o"] {
|
|
- copy_and_stamp(&srcdir, obj);
|
|
- }
|
|
- } 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(&srcdir, "crt1.o");
|
|
}
|
|
@@ -227,15 +216,6 @@ pub fn std_cargo(builder: &Builder<'_>,
|
|
.arg("--manifest-path")
|
|
.arg(builder.src.join("src/libtest/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_root(target) {
|
|
- let root = format!("native={}/lib", 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 d1bdfa0a..51b2bc62 100644
|
|
--- a/src/bootstrap/config.rs
|
|
+++ b/src/bootstrap/config.rs
|
|
@@ -131,8 +131,6 @@ pub struct Config {
|
|
pub print_step_timings: bool,
|
|
pub missing_tools: bool,
|
|
|
|
- // Fallback musl-root for all targets
|
|
- pub musl_root: Option<PathBuf>,
|
|
pub prefix: Option<PathBuf>,
|
|
pub sysconfdir: Option<PathBuf>,
|
|
pub datadir: Option<PathBuf>,
|
|
@@ -167,7 +165,6 @@ pub struct Target {
|
|
pub linker: Option<PathBuf>,
|
|
pub ndk: Option<PathBuf>,
|
|
pub crt_static: Option<bool>,
|
|
- pub musl_root: Option<PathBuf>,
|
|
pub wasi_root: Option<PathBuf>,
|
|
pub qemu_rootfs: Option<PathBuf>,
|
|
pub no_std: bool,
|
|
@@ -307,7 +304,6 @@ struct Rust {
|
|
parallel_compiler: Option<bool>,
|
|
default_linker: Option<String>,
|
|
channel: Option<String>,
|
|
- musl_root: Option<String>,
|
|
rpath: Option<bool>,
|
|
verbose_tests: Option<bool>,
|
|
optimize_tests: Option<bool>,
|
|
@@ -342,7 +338,6 @@ struct TomlTarget {
|
|
llvm_filecheck: Option<String>,
|
|
android_ndk: Option<String>,
|
|
crt_static: Option<bool>,
|
|
- musl_root: Option<String>,
|
|
wasi_root: Option<String>,
|
|
qemu_rootfs: Option<String>,
|
|
}
|
|
@@ -562,7 +557,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);
|
|
@@ -600,7 +594,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.clone();
|
|
- target.musl_root = cfg.musl_root.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 bb6041d7..73f3781c 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 39cb804c..8e36118a 100644
|
|
--- a/src/bootstrap/lib.rs
|
|
+++ b/src/bootstrap/lib.rs
|
|
@@ -828,14 +828,6 @@ impl Build {
|
|
}
|
|
}
|
|
|
|
- /// Returns the "musl root" for this `target`, if defined
|
|
- fn musl_root(&self, target: Interned<String>) -> Option<&Path> {
|
|
- self.config.target_config.get(&target)
|
|
- .and_then(|t| t.musl_root.as_ref())
|
|
- .or(self.config.musl_root.as_ref())
|
|
- .map(|p| &**p)
|
|
- }
|
|
-
|
|
/// Returns the sysroot for the wasi target, if defined
|
|
fn wasi_root(&self, target: Interned<String>) -> Option<&Path> {
|
|
self.config.target_config.get(&target)
|
|
diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs
|
|
index bffe748f..3b109548 100644
|
|
--- a/src/bootstrap/sanity.rs
|
|
+++ b/src/bootstrap/sanity.rs
|
|
@@ -187,30 +187,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_root(*target) {
|
|
- Some(root) => {
|
|
- if fs::metadata(root.join("lib/libc.a")).is_err() {
|
|
- panic!("couldn't find libc.a in musl dir: {}",
|
|
- root.join("lib").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/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs
|
|
index e294e639..58ae91a9 100644
|
|
--- a/src/librustc_target/spec/linux_musl_base.rs
|
|
+++ b/src/librustc_target/spec/linux_musl_base.rs
|
|
@@ -3,28 +3,12 @@ use crate::spec::{LinkerFlavor, TargetOptions};
|
|
pub fn opts() -> TargetOptions {
|
|
let mut base = super::linux_base::opts();
|
|
|
|
- // Make sure that the linker/gcc really don't pull in anything, including
|
|
- // default objects, libs, etc.
|
|
- base.pre_link_args_crt.insert(LinkerFlavor::Gcc, Vec::new());
|
|
- base.pre_link_args_crt.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string());
|
|
-
|
|
// At least when this was tested, the linker would not add the
|
|
// `GNU_EH_FRAME` program header to executables generated, which is required
|
|
// when unwinding to locate the unwinding information. I'm not sure why this
|
|
// argument is *not* necessary for normal builds, but it can't hurt!
|
|
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--eh-frame-hdr".to_string());
|
|
|
|
- // When generating a statically linked executable there's generally some
|
|
- // small setup needed which is listed in these files. These are provided by
|
|
- // a musl toolchain and are linked by default by the `musl-gcc` script. Note
|
|
- // that `gcc` also does this by default, it just uses some different files.
|
|
- //
|
|
- // Each target directory for musl has these object files included in it so
|
|
- // they'll be included from there.
|
|
- base.pre_link_objects_exe_crt.push("crt1.o".to_string());
|
|
- base.pre_link_objects_exe_crt.push("crti.o".to_string());
|
|
- base.post_link_objects_crt.push("crtn.o".to_string());
|
|
-
|
|
// 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.24.0
|
|
|