Skip to content

Commit 9ceef4e

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36972 - nastevens:fix-rustbuild-per-target-musl-root, r=alexcrichton
Fix rustbuild per-target musl root In rust-lang#36292, support was added to target musl libc for ARM targets using rustbuild. Specifically, that change allowed the addition of per-target `musl-root` options in the rustbuild `config.toml` so that multiple targets depending on musl could be built. However, that implementation contained a couple of omissions: the `musl-root` option was added to the config, but was never added to the TOML parsing, and therefore was not actually being loaded from `config.toml`. This PR rectifies that. Using these changes and a heavily modified version of the buildbot Docker container, I have been able to build rust targeting `armv7-unknown-linux-musleabihf` and have successfully run the binaries on a Raspberry Pi 3. I'm also planning to test `arm-unknown-linux-musleabi` and `arm-unknown-linux-musleabihf` systems, but have no reason to believe that this change would not simply work on those targets.
2 parents a19e22e + 7937f6c commit 9ceef4e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ pub fn std_link(build: &Build,
9090
add_to_sysroot(&out_dir, &libdir);
9191

9292
if target.contains("musl") && !target.contains("mips") {
93-
copy_musl_third_party_objects(build, &libdir);
93+
copy_musl_third_party_objects(build, target, &libdir);
9494
}
9595
}
9696

9797
/// Copies the crt(1,i,n).o startup objects
9898
///
9999
/// Only required for musl targets that statically link to libc
100-
fn copy_musl_third_party_objects(build: &Build, into: &Path) {
100+
fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) {
101101
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
102-
copy(&build.config.musl_root.as_ref().unwrap().join("lib").join(obj), &into.join(obj));
102+
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
103103
}
104104
}
105105

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct TomlTarget {
158158
cc: Option<String>,
159159
cxx: Option<String>,
160160
android_ndk: Option<String>,
161+
musl_root: Option<String>,
161162
}
162163

163164
impl Config {
@@ -268,6 +269,7 @@ impl Config {
268269
}
269270
target.cxx = cfg.cxx.clone().map(PathBuf::from);
270271
target.cc = cfg.cc.clone().map(PathBuf::from);
272+
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
271273

272274
config.target_config.insert(triple.clone(), target);
273275
}

src/bootstrap/sanity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ pub fn check(build: &mut Build) {
146146
}
147147
}
148148
None => {
149-
panic!("when targeting MUSL either the build.musl-root \
150-
option or the target.$TARGET.musl-root one must \
149+
panic!("when targeting MUSL either the rust.musl-root \
150+
option or the target.$TARGET.musl-root option must \
151151
be specified in config.toml")
152152
}
153153
}

0 commit comments

Comments
 (0)