Skip to content

Commit a7b2232

Browse files
authored
Auto merge of #36292 - japaric:musl-root, r=alexcrichton
rustbuild: per target musl-root config.toml now accepts a target.$TARGET.musl-root key that lets you override the "build" musl-root value, which is set via the --musl-root flag or via the build.musl-root key. With this change, it's now possible to compile std for several musl targets at once. Here's are the sample commands to do such thing: ``` $ configure \ --enable-rustbuild \ --target=x86_64-unknown-linux-musl,arm-unknown-linux-musleabi \ --musl-root=/musl/x86_64-unknown-linux-musl/ $ edit config.toml && tail config.toml [target.arm-unknown-linux-musleabi] musl-root = "/x-tools/arm-unknown-linux-musleabi/arm-unknown-linux-musleabi/sysroot/usr" $ make ``` r? @alexcrichton With this we should be able to start producing releases of std for arm musl targets
2 parents 9627e9e + 8cfc69e commit a7b2232

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
5959
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
6060
}
6161
}
62-
if let Some(ref p) = build.config.musl_root {
63-
if target.contains("musl") {
62+
if target.contains("musl") {
63+
if let Some(p) = build.musl_root(target) {
6464
cargo.env("MUSL_ROOT", p);
6565
}
6666
}

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub struct Config {
7676

7777
// misc
7878
pub channel: String,
79+
// Fallback musl-root for all targets
7980
pub musl_root: Option<PathBuf>,
8081
pub prefix: Option<String>,
8182
pub codegen_tests: bool,
@@ -89,6 +90,7 @@ pub struct Target {
8990
pub cc: Option<PathBuf>,
9091
pub cxx: Option<PathBuf>,
9192
pub ndk: Option<PathBuf>,
93+
pub musl_root: Option<PathBuf>,
9294
}
9395

9496
/// Structure of the `config.toml` file that configuration is read from.

src/bootstrap/config.toml.example

+6-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@
118118
# nightly features
119119
#channel = "dev"
120120

121-
# The root location of the MUSL installation directory. The library directory
122-
# will also need to contain libunwind.a for an unwinding implementation.
123-
#musl-root = "..."
124-
125121
# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
126122
# platforms to ensure that the compiler is usable by default from the build
127123
# directory (as it links to a number of dynamic libraries). This may not be
@@ -167,3 +163,9 @@
167163
# the NDK for the target lives. This is used to find the C compiler to link and
168164
# build native code.
169165
#android-ndk = "/path/to/ndk"
166+
167+
# The root location of the MUSL installation directory. The library directory
168+
# will also need to contain libunwind.a for an unwinding implementation. Note
169+
# that this option only makes sense for MUSL targets that produce statically
170+
# linked binaries
171+
#musl-root = "..."

src/bootstrap/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,13 @@ impl Build {
977977
}
978978
return base
979979
}
980+
981+
/// Returns the "musl root" for this `target`, if defined
982+
fn musl_root(&self, target: &str) -> Option<&Path> {
983+
self.config.target_config[target].musl_root.as_ref()
984+
.or(self.config.musl_root.as_ref())
985+
.map(|p| &**p)
986+
}
980987
}
981988

982989
impl<'a> Compiler<'a> {

src/bootstrap/sanity.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ pub fn check(build: &mut Build) {
111111

112112
// Make sure musl-root is valid if specified
113113
if target.contains("musl") && !target.contains("mips") {
114-
match build.config.musl_root {
115-
Some(ref root) => {
114+
match build.musl_root(target) {
115+
Some(root) => {
116116
if fs::metadata(root.join("lib/libc.a")).is_err() {
117117
panic!("couldn't find libc.a in musl dir: {}",
118118
root.join("lib").display());
@@ -123,8 +123,9 @@ pub fn check(build: &mut Build) {
123123
}
124124
}
125125
None => {
126-
panic!("when targeting MUSL the build.musl-root option \
127-
must be specified in config.toml")
126+
panic!("when targeting MUSL either the build.musl-root \
127+
option or the target.$TARGET.musl-root one must \
128+
be specified in config.toml")
128129
}
129130
}
130131
}

0 commit comments

Comments
 (0)