Auto merge of #73456 - tmiasko:musl-libdir, r=Mark-Simulacrum
bootstrap: Configurable musl libdir Make it possible to customize the location of musl libdir using musl-libdir in config.toml, e.g., to use lib64 instead of lib.
This commit is contained in:
commit
16957bd4d3
@ -378,7 +378,7 @@
|
||||
# nightly features
|
||||
#channel = "dev"
|
||||
|
||||
# The root location of the MUSL installation directory.
|
||||
# The root location of the musl installation directory.
|
||||
#musl-root = "..."
|
||||
|
||||
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
|
||||
@ -521,12 +521,15 @@
|
||||
# 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
|
||||
# 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
|
||||
# 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 = "..."
|
||||
|
||||
|
@ -177,7 +177,7 @@ fn copy_self_contained_objects(
|
||||
// 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_root(target).unwrap().join("lib");
|
||||
let srcdir = builder.musl_libdir(target).unwrap();
|
||||
for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
|
||||
copy_and_stamp(
|
||||
builder,
|
||||
@ -266,8 +266,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, ca
|
||||
// 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());
|
||||
if let Some(p) = builder.musl_libdir(target) {
|
||||
let root = format!("native={}", p.to_str().unwrap());
|
||||
cargo.rustflag("-L").rustflag(&root);
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,7 @@ pub struct Target {
|
||||
pub ndk: Option<PathBuf>,
|
||||
pub crt_static: Option<bool>,
|
||||
pub musl_root: Option<PathBuf>,
|
||||
pub musl_libdir: Option<PathBuf>,
|
||||
pub wasi_root: Option<PathBuf>,
|
||||
pub qemu_rootfs: Option<PathBuf>,
|
||||
pub no_std: bool,
|
||||
@ -363,6 +364,7 @@ struct TomlTarget {
|
||||
android_ndk: Option<String>,
|
||||
crt_static: Option<bool>,
|
||||
musl_root: Option<String>,
|
||||
musl_libdir: Option<String>,
|
||||
wasi_root: Option<String>,
|
||||
qemu_rootfs: Option<String>,
|
||||
no_std: Option<bool>,
|
||||
@ -631,6 +633,7 @@ impl Config {
|
||||
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);
|
||||
|
||||
|
@ -888,6 +888,15 @@ impl Build {
|
||||
.map(|p| &**p)
|
||||
}
|
||||
|
||||
/// Returns the "musl libdir" for this `target`.
|
||||
fn musl_libdir(&self, target: Interned<String>) -> Option<PathBuf> {
|
||||
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: Interned<String>) -> Option<&Path> {
|
||||
self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p)
|
||||
|
@ -199,10 +199,10 @@ pub fn check(build: &mut Build) {
|
||||
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());
|
||||
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!(
|
||||
|
Loading…
Reference in New Issue
Block a user