Skip to content

Commit 9cf05b8

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 c83504f commit 9cf05b8

File tree

1 file changed

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

1 file changed

+24
-0
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,17 @@ fn configure_cmake(
645645
if !builder.is_builder_target(target) {
646646
cfg.define("CMAKE_CROSSCOMPILING", "True");
647647

648+
// NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us.
649+
// But it currently determines this based on the `CARGO_CFG_TARGET_OS` environment variable,
650+
// which isn't set when compiling outside `build.rs` (like bootstrap is).
651+
//
652+
// So for now, we define `CMAKE_SYSTEM_NAME` ourselves, to panicking in `cmake-rs`.
648653
if target.contains("netbsd") {
649654
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
650655
} else if target.contains("dragonfly") {
651656
cfg.define("CMAKE_SYSTEM_NAME", "DragonFly");
657+
} else if target.contains("openbsd") {
658+
cfg.define("CMAKE_SYSTEM_NAME", "OpenBSD");
652659
} else if target.contains("freebsd") {
653660
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
654661
} else if target.is_windows() {
@@ -659,10 +666,27 @@ fn configure_cmake(
659666
cfg.define("CMAKE_SYSTEM_NAME", "SunOS");
660667
} else if target.contains("linux") {
661668
cfg.define("CMAKE_SYSTEM_NAME", "Linux");
669+
} else if target.contains("darwin") {
670+
// macOS
671+
cfg.define("CMAKE_SYSTEM_NAME", "Darwin");
672+
} else if target.contains("ios") {
673+
cfg.define("CMAKE_SYSTEM_NAME", "iOS");
674+
} else if target.contains("tvos") {
675+
cfg.define("CMAKE_SYSTEM_NAME", "tvOS");
676+
} else if target.contains("visionos") {
677+
cfg.define("CMAKE_SYSTEM_NAME", "visionOS");
678+
} else if target.contains("watchos") {
679+
cfg.define("CMAKE_SYSTEM_NAME", "watchOS");
680+
} else if target.contains("none") {
681+
// "none" should be the last branch
682+
cfg.define("CMAKE_SYSTEM_NAME", "Generic");
662683
} else {
663684
builder.info(&format!(
664685
"could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail",
665686
));
687+
// Fallback, set `CMAKE_SYSTEM_NAME` anyhow to avoid the logic `cmake-rs` tries, and
688+
// to avoid CMAKE_SYSTEM_NAME being inferred from the host.
689+
cfg.define("CMAKE_SYSTEM_NAME", "Generic");
666690
}
667691

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

0 commit comments

Comments
 (0)