bootstrap: Move musl-root fallback out of sanity check

Previously, the musl root would only be set to the fallback /usr by
the sanity check, which isn't ran for the bootstrap tests.

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
This commit is contained in:
Jens Reidel 2025-07-22 19:00:32 +02:00
parent c0b282f0cc
commit a9fd8d041b
No known key found for this signature in database
GPG key ID: 23C1E5F512C12303
2 changed files with 18 additions and 14 deletions

View file

@ -338,12 +338,6 @@ than building it.
// Make sure musl-root is valid.
if target.contains("musl") && !target.contains("unikraft") {
// If this is a native target (host is also musl) and no musl-root is given,
// fall back to the system toolchain in /usr before giving up
if build.musl_root(*target).is_none() && build.config.is_host_target(*target) {
let target = build.config.target_config.entry(*target).or_default();
target.musl_root = Some("/usr".into());
}
match build.musl_libdir(*target) {
Some(libdir) => {
if fs::metadata(libdir.join("libc.a")).is_err() {

View file

@ -1329,23 +1329,33 @@ impl Build {
}
}
/// Returns the "musl root" for this `target`, if defined
/// Returns the "musl root" for this `target`, if defined.
///
/// If this is a native target (host is also musl) and no musl-root is given,
/// it falls back to the system toolchain in /usr.
fn musl_root(&self, target: TargetSelection) -> Option<&Path> {
self.config
let configured_root = self
.config
.target_config
.get(&target)
.and_then(|t| t.musl_root.as_ref())
.or(self.config.musl_root.as_ref())
.map(|p| &**p)
.map(|p| &**p);
if self.config.is_host_target(target) && configured_root.is_none() {
return Some(Path::new("/usr"));
} else {
configured_root
}
}
/// Returns the "musl libdir" for this `target`.
fn musl_libdir(&self, target: TargetSelection) -> 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"))
self.config
.target_config
.get(&target)
.and_then(|t| t.musl_libdir.clone())
.or_else(|| self.musl_root(target).map(|root| root.join("lib")))
}
/// Returns the `lib` directory for the WASI target specified, if