Skip to content

bootstrap: Move musl-root fallback out of sanity check #144316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
26 changes: 18 additions & 8 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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
Expand Down
Loading