Skip to content

Commit

Permalink
bootstrap: Configurable musl libdir
Browse files Browse the repository at this point in the history
Make it possible to customize the location of musl libdir using
musl-libdir in config.toml, e.g., to use lib64 instead of lib.
  • Loading branch information
tmiasko committed Jun 18, 2020
1 parent 2935d29 commit 5c20ef4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
9 changes: 6 additions & 3 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,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
Expand Down Expand Up @@ -502,12 +502,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 = "..."

Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn copy_third_party_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(&srcdir, obj);
}
Expand Down Expand Up @@ -219,8 +219,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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,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)
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 5c20ef4

Please sign in to comment.