Skip to content

Commit fc7db0e

Browse files
authored
Rollup merge of rust-lang#135836 - ferrocene:ja-gh135782-build-crt-only-for-musl, r=onur-ozkan
bootstrap: only build `crt{begin,end}.o` when compiling to MUSL only MUSL needs those objects and trying to compile them to other targets, e.g. Windows or macOS, will produce C compilation errors check the target before shelling out to the C compiler and tweak `make_run` to skip the actual C compilation when the target is not MUSL fixes rust-lang#135782 see the linked issue for additional context
2 parents a5ec446 + 88260f4 commit fc7db0e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn copy_self_contained_objects(
339339
// to using gcc from a glibc-targeting toolchain for linking.
340340
// To do that we have to distribute musl startup objects as a part of Rust toolchain
341341
// and link with them manually in the self-contained mode.
342-
if target.contains("musl") && !target.contains("unikraft") {
342+
if target.needs_crt_begin_end() {
343343
let srcdir = builder.musl_libdir(target).unwrap_or_else(|| {
344344
panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple)
345345
});

src/bootstrap/src/core/build_steps/llvm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,9 @@ impl Step for CrtBeginEnd {
12951295
}
12961296

12971297
fn make_run(run: RunConfig<'_>) {
1298-
run.builder.ensure(CrtBeginEnd { target: run.target });
1298+
if run.target.needs_crt_begin_end() {
1299+
run.builder.ensure(CrtBeginEnd { target: run.target });
1300+
}
12991301
}
13001302

13011303
/// Build crtbegin.o/crtend.o for musl target.

src/bootstrap/src/core/config/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ impl TargetSelection {
575575
env::var("OSTYPE").is_ok_and(|v| v.to_lowercase().contains("cygwin"))
576576
}
577577

578+
pub fn needs_crt_begin_end(&self) -> bool {
579+
self.contains("musl") && !self.contains("unikraft")
580+
}
581+
578582
/// Path to the file defining the custom target, if any.
579583
pub fn filepath(&self) -> Option<&Path> {
580584
self.file.as_ref().map(Path::new)

0 commit comments

Comments
 (0)