Skip to content

Commit 16957bd

Browse files
committed
Auto merge of rust-lang#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.
2 parents e070765 + 5c20ef4 commit 16957bd

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

config.toml.example

+6-3
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
# nightly features
379379
#channel = "dev"
380380

381-
# The root location of the MUSL installation directory.
381+
# The root location of the musl installation directory.
382382
#musl-root = "..."
383383

384384
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
@@ -521,12 +521,15 @@
521521
# only use static libraries. If unset, the target's default linkage is used.
522522
#crt-static = false
523523

524-
# The root location of the MUSL installation directory. The library directory
524+
# The root location of the musl installation directory. The library directory
525525
# will also need to contain libunwind.a for an unwinding implementation. Note
526-
# that this option only makes sense for MUSL targets that produce statically
526+
# that this option only makes sense for musl targets that produce statically
527527
# linked binaries
528528
#musl-root = "..."
529529

530+
# The full path to the musl libdir.
531+
#musl-libdir = musl-root/lib
532+
530533
# The root location of the `wasm32-wasi` sysroot.
531534
#wasi-root = "..."
532535

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn copy_self_contained_objects(
177177
// To do that we have to distribute musl startup objects as a part of Rust toolchain
178178
// and link with them manually in the self-contained mode.
179179
if target.contains("musl") {
180-
let srcdir = builder.musl_root(target).unwrap().join("lib");
180+
let srcdir = builder.musl_libdir(target).unwrap();
181181
for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
182182
copy_and_stamp(
183183
builder,
@@ -266,8 +266,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, ca
266266
// Help the libc crate compile by assisting it in finding various
267267
// sysroot native libraries.
268268
if target.contains("musl") {
269-
if let Some(p) = builder.musl_root(target) {
270-
let root = format!("native={}/lib", p.to_str().unwrap());
269+
if let Some(p) = builder.musl_libdir(target) {
270+
let root = format!("native={}", p.to_str().unwrap());
271271
cargo.rustflag("-L").rustflag(&root);
272272
}
273273
}

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub struct Target {
173173
pub ndk: Option<PathBuf>,
174174
pub crt_static: Option<bool>,
175175
pub musl_root: Option<PathBuf>,
176+
pub musl_libdir: Option<PathBuf>,
176177
pub wasi_root: Option<PathBuf>,
177178
pub qemu_rootfs: Option<PathBuf>,
178179
pub no_std: bool,
@@ -363,6 +364,7 @@ struct TomlTarget {
363364
android_ndk: Option<String>,
364365
crt_static: Option<bool>,
365366
musl_root: Option<String>,
367+
musl_libdir: Option<String>,
366368
wasi_root: Option<String>,
367369
qemu_rootfs: Option<String>,
368370
no_std: Option<bool>,
@@ -631,6 +633,7 @@ impl Config {
631633
target.linker = cfg.linker.clone().map(PathBuf::from);
632634
target.crt_static = cfg.crt_static;
633635
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
636+
target.musl_libdir = cfg.musl_libdir.clone().map(PathBuf::from);
634637
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
635638
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
636639

src/bootstrap/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,15 @@ impl Build {
888888
.map(|p| &**p)
889889
}
890890

891+
/// Returns the "musl libdir" for this `target`.
892+
fn musl_libdir(&self, target: Interned<String>) -> Option<PathBuf> {
893+
let t = self.config.target_config.get(&target)?;
894+
if let libdir @ Some(_) = &t.musl_libdir {
895+
return libdir.clone();
896+
}
897+
self.musl_root(target).map(|root| root.join("lib"))
898+
}
899+
891900
/// Returns the sysroot for the wasi target, if defined
892901
fn wasi_root(&self, target: Interned<String>) -> Option<&Path> {
893902
self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p)

src/bootstrap/sanity.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ pub fn check(build: &mut Build) {
199199
let target = build.config.target_config.entry(target.clone()).or_default();
200200
target.musl_root = Some("/usr".into());
201201
}
202-
match build.musl_root(*target) {
203-
Some(root) => {
204-
if fs::metadata(root.join("lib/libc.a")).is_err() {
205-
panic!("couldn't find libc.a in musl dir: {}", root.join("lib").display());
202+
match build.musl_libdir(*target) {
203+
Some(libdir) => {
204+
if fs::metadata(libdir.join("libc.a")).is_err() {
205+
panic!("couldn't find libc.a in musl libdir: {}", libdir.display());
206206
}
207207
}
208208
None => panic!(

0 commit comments

Comments
 (0)