@@ -385,9 +385,6 @@ impl Step for Llvm {
385
385
|| target. contains ( "apple-watchos" )
386
386
|| target. contains ( "apple-visionos" )
387
387
{
388
- // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error.
389
- cfg. define ( "CMAKE_OSX_SYSROOT" , "/" ) ;
390
- cfg. define ( "CMAKE_OSX_DEPLOYMENT_TARGET" , "" ) ;
391
388
// Prevent cmake from adding -bundle to CFLAGS automatically, which leads to a compiler error because "-bitcode_bundle" also gets added.
392
389
cfg. define ( "LLVM_ENABLE_PLUGINS" , "OFF" ) ;
393
390
// Zlib fails to link properly, leading to a compiler error.
@@ -645,10 +642,17 @@ fn configure_cmake(
645
642
if !builder. is_builder_target ( target) {
646
643
cfg. define ( "CMAKE_CROSSCOMPILING" , "True" ) ;
647
644
645
+ // NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us.
646
+ // But it currently determines this based on the `CARGO_CFG_TARGET_OS` environment variable,
647
+ // which isn't set when compiling outside `build.rs` (like bootstrap is).
648
+ //
649
+ // So for now, we define `CMAKE_SYSTEM_NAME` ourselves, to panicking in `cmake-rs`.
648
650
if target. contains ( "netbsd" ) {
649
651
cfg. define ( "CMAKE_SYSTEM_NAME" , "NetBSD" ) ;
650
652
} else if target. contains ( "dragonfly" ) {
651
653
cfg. define ( "CMAKE_SYSTEM_NAME" , "DragonFly" ) ;
654
+ } else if target. contains ( "openbsd" ) {
655
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "OpenBSD" ) ;
652
656
} else if target. contains ( "freebsd" ) {
653
657
cfg. define ( "CMAKE_SYSTEM_NAME" , "FreeBSD" ) ;
654
658
} else if target. is_windows ( ) {
@@ -659,10 +663,27 @@ fn configure_cmake(
659
663
cfg. define ( "CMAKE_SYSTEM_NAME" , "SunOS" ) ;
660
664
} else if target. contains ( "linux" ) {
661
665
cfg. define ( "CMAKE_SYSTEM_NAME" , "Linux" ) ;
666
+ } else if target. contains ( "darwin" ) {
667
+ // macOS
668
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "Darwin" ) ;
669
+ } else if target. contains ( "ios" ) {
670
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "iOS" ) ;
671
+ } else if target. contains ( "tvos" ) {
672
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "tvOS" ) ;
673
+ } else if target. contains ( "visionos" ) {
674
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "visionOS" ) ;
675
+ } else if target. contains ( "watchos" ) {
676
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "watchOS" ) ;
677
+ } else if target. contains ( "none" ) {
678
+ // "none" should be the last branch
679
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "Generic" ) ;
662
680
} else {
663
681
builder. info ( & format ! (
664
682
"could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail" ,
665
683
) ) ;
684
+ // Fallback, set `CMAKE_SYSTEM_NAME` anyhow to avoid the logic `cmake-rs` tries, and
685
+ // to avoid CMAKE_SYSTEM_NAME being inferred from the host.
686
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "Generic" ) ;
666
687
}
667
688
668
689
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
@@ -672,7 +693,19 @@ fn configure_cmake(
672
693
// CMakeFiles (and then only in tests), and so far no issues have been
673
694
// reported, the system version is currently left unset.
674
695
675
- if target. contains ( "darwin" ) {
696
+ if target. contains ( "apple" ) {
697
+ if !target. contains ( "darwin" ) {
698
+ // FIXME(madsmtm): compiler-rt's CMake setup is kinda weird, it seems like they do
699
+ // version testing etc. for macOS (i.e. Darwin), even while building for iOS?
700
+ //
701
+ // So for now we set it to "Darwin" on all Apple platforms.
702
+ cfg. define ( "CMAKE_SYSTEM_NAME" , "Darwin" ) ;
703
+
704
+ // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error.
705
+ cfg. define ( "CMAKE_OSX_SYSROOT" , "/" ) ;
706
+ cfg. define ( "CMAKE_OSX_DEPLOYMENT_TARGET" , "" ) ;
707
+ }
708
+
676
709
// Make sure that CMake does not build universal binaries on macOS.
677
710
// Explicitly specify the one single target architecture.
678
711
if target. starts_with ( "aarch64" ) {
0 commit comments