Skip to content

Commit 5c20ef4

Browse files
committed
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.
1 parent 2935d29 commit 5c20ef4

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
@@ -359,7 +359,7 @@
359359
# nightly features
360360
#channel = "dev"
361361

362-
# The root location of the MUSL installation directory.
362+
# The root location of the musl installation directory.
363363
#musl-root = "..."
364364

365365
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
@@ -502,12 +502,15 @@
502502
# only use static libraries. If unset, the target's default linkage is used.
503503
#crt-static = false
504504

505-
# The root location of the MUSL installation directory. The library directory
505+
# The root location of the musl installation directory. The library directory
506506
# will also need to contain libunwind.a for an unwinding implementation. Note
507-
# that this option only makes sense for MUSL targets that produce statically
507+
# that this option only makes sense for musl targets that produce statically
508508
# linked binaries
509509
#musl-root = "..."
510510

511+
# The full path to the musl libdir.
512+
#musl-libdir = musl-root/lib
513+
511514
# The root location of the `wasm32-wasi` sysroot.
512515
#wasi-root = "..."
513516

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn copy_third_party_objects(
133133
// To do that we have to distribute musl startup objects as a part of Rust toolchain
134134
// and link with them manually in the self-contained mode.
135135
if target.contains("musl") {
136-
let srcdir = builder.musl_root(target).unwrap().join("lib");
136+
let srcdir = builder.musl_libdir(target).unwrap();
137137
for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
138138
copy_and_stamp(&srcdir, obj);
139139
}
@@ -219,8 +219,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, ca
219219
// Help the libc crate compile by assisting it in finding various
220220
// sysroot native libraries.
221221
if target.contains("musl") {
222-
if let Some(p) = builder.musl_root(target) {
223-
let root = format!("native={}/lib", p.to_str().unwrap());
222+
if let Some(p) = builder.musl_libdir(target) {
223+
let root = format!("native={}", p.to_str().unwrap());
224224
cargo.rustflag("-L").rustflag(&root);
225225
}
226226
}

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
@@ -877,6 +877,15 @@ impl Build {
877877
.map(|p| &**p)
878878
}
879879

880+
/// Returns the "musl libdir" for this `target`.
881+
fn musl_libdir(&self, target: Interned<String>) -> Option<PathBuf> {
882+
let t = self.config.target_config.get(&target)?;
883+
if let libdir @ Some(_) = &t.musl_libdir {
884+
return libdir.clone();
885+
}
886+
self.musl_root(target).map(|root| root.join("lib"))
887+
}
888+
880889
/// Returns the sysroot for the wasi target, if defined
881890
fn wasi_root(&self, target: Interned<String>) -> Option<&Path> {
882891
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)