Skip to content

Commit c93efd1

Browse files
committed
bootstrap: Always set CMAKE_SYSTEM_NAME when cross-compiling
To avoid a panic in cmake-rs that was introduced in: rust-lang/cmake-rs#158
1 parent 673b519 commit c93efd1

File tree

1 file changed

+21
-0
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+21
-0
lines changed

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

+21
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,17 @@ fn configure_cmake(
677677
if !builder.is_builder_target(target) {
678678
cfg.define("CMAKE_CROSSCOMPILING", "True");
679679

680+
// NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us.
681+
// But it currently determines this basd on the `CARGO_CFG_TARGET_OS` environment variable,
682+
// which isn't set when compiling outside `build.rs` (like bootstrap is).
683+
//
684+
// So for now, we define `CMAKE_SYSTEM_NAME` ourselves, to panicking in `cmake-rs`.
680685
if target.contains("netbsd") {
681686
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
682687
} else if target.contains("dragonfly") {
683688
cfg.define("CMAKE_SYSTEM_NAME", "DragonFly");
689+
} else if target.contains("openbsd") {
690+
cfg.define("CMAKE_SYSTEM_NAME", "OpenBSD");
684691
} else if target.contains("freebsd") {
685692
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
686693
} else if target.is_windows() {
@@ -691,10 +698,24 @@ fn configure_cmake(
691698
cfg.define("CMAKE_SYSTEM_NAME", "SunOS");
692699
} else if target.contains("linux") {
693700
cfg.define("CMAKE_SYSTEM_NAME", "Linux");
701+
} else if target.contains("darwin") {
702+
cfg.define("CMAKE_SYSTEM_NAME", "Darwin");
703+
} else if target.contains("ios") {
704+
cfg.define("CMAKE_SYSTEM_NAME", "iOS");
705+
} else if target.contains("tvos") {
706+
cfg.define("CMAKE_SYSTEM_NAME", "tvOS");
707+
} else if target.contains("visionos") {
708+
cfg.define("CMAKE_SYSTEM_NAME", "visionOS");
709+
} else if target.contains("watchos") {
710+
cfg.define("CMAKE_SYSTEM_NAME", "watchOS");
711+
} else if target.contains("none") {
712+
// Last branch
713+
cfg.define("CMAKE_SYSTEM_NAME", "Generic");
694714
} else {
695715
builder.info(&format!(
696716
"could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail",
697717
));
718+
cfg.define("CMAKE_SYSTEM_NAME", "Generic");
698719
}
699720

700721
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in

0 commit comments

Comments
 (0)