From 0a1838a73c17f715f74e5a30f89ed4a30f83aa94 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 21 Mar 2025 13:30:56 +0100 Subject: [PATCH 1/6] bootstrap: bump cc to 1.2.17 and cmake to 0.1.54 --- src/bootstrap/Cargo.lock | 8 ++++---- src/bootstrap/Cargo.toml | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index 890e64e2babbc..17ee4d610f958 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.22" +version = "1.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" +checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" dependencies = [ "shlex", ] @@ -150,9 +150,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "cmake" -version = "0.1.48" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0" dependencies = [ "cc", ] diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index d3e2b9e05e99c..23aa87a74075b 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -32,10 +32,8 @@ test = false # Most of the time updating these dependencies requires modifications to the # bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565); # otherwise, some targets will fail. That's why these dependencies are explicitly pinned. -# -# Do not upgrade this crate unless https://github.com/rust-lang/cc-rs/issues/1317 is fixed. -cc = "=1.1.22" -cmake = "=0.1.48" +cc = "=1.2.17" +cmake = "=0.1.54" build_helper = { path = "../build_helper" } clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] } From 5ec64d73055920fb09ad75d30f486b24a70a6ca9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 24 Mar 2025 13:08:25 +0100 Subject: [PATCH 2/6] bootstrap: Always set CMAKE_SYSTEM_NAME when cross-compiling To avoid a panic in cmake-rs that was introduced in: https://github.com/rust-lang/cmake-rs/pull/158 --- src/bootstrap/src/core/build_steps/llvm.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 9ae1825fae897..0bc879c7d713a 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -645,10 +645,17 @@ fn configure_cmake( if !builder.is_builder_target(target) { cfg.define("CMAKE_CROSSCOMPILING", "True"); + // NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us. + // But it currently determines this based on the `CARGO_CFG_TARGET_OS` environment variable, + // which isn't set when compiling outside `build.rs` (like bootstrap is). + // + // So for now, we define `CMAKE_SYSTEM_NAME` ourselves, to panicking in `cmake-rs`. if target.contains("netbsd") { cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); } else if target.contains("dragonfly") { cfg.define("CMAKE_SYSTEM_NAME", "DragonFly"); + } else if target.contains("openbsd") { + cfg.define("CMAKE_SYSTEM_NAME", "OpenBSD"); } else if target.contains("freebsd") { cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); } else if target.is_windows() { @@ -659,10 +666,27 @@ fn configure_cmake( cfg.define("CMAKE_SYSTEM_NAME", "SunOS"); } else if target.contains("linux") { cfg.define("CMAKE_SYSTEM_NAME", "Linux"); + } else if target.contains("darwin") { + // macOS + cfg.define("CMAKE_SYSTEM_NAME", "Darwin"); + } else if target.contains("ios") { + cfg.define("CMAKE_SYSTEM_NAME", "iOS"); + } else if target.contains("tvos") { + cfg.define("CMAKE_SYSTEM_NAME", "tvOS"); + } else if target.contains("visionos") { + cfg.define("CMAKE_SYSTEM_NAME", "visionOS"); + } else if target.contains("watchos") { + cfg.define("CMAKE_SYSTEM_NAME", "watchOS"); + } else if target.contains("none") { + // "none" should be the last branch + cfg.define("CMAKE_SYSTEM_NAME", "Generic"); } else { builder.info(&format!( "could not determine CMAKE_SYSTEM_NAME from the target `{target}`, build may fail", )); + // Fallback, set `CMAKE_SYSTEM_NAME` anyhow to avoid the logic `cmake-rs` tries, and + // to avoid CMAKE_SYSTEM_NAME being inferred from the host. + cfg.define("CMAKE_SYSTEM_NAME", "Generic"); } // When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in From 2667352834aca7c6058fa0b04be5818248dae345 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 24 Mar 2025 11:05:41 +0100 Subject: [PATCH 3/6] bootstrap: Fix CMAKE_OSX_ARCHITECTURES on all Apple platforms --- src/bootstrap/src/core/build_steps/llvm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 0bc879c7d713a..41d3ca2c4cd40 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -696,7 +696,7 @@ fn configure_cmake( // CMakeFiles (and then only in tests), and so far no issues have been // reported, the system version is currently left unset. - if target.contains("darwin") { + if target.contains("apple") { // Make sure that CMake does not build universal binaries on macOS. // Explicitly specify the one single target architecture. if target.starts_with("aarch64") { From 02ee3aee7f3f0543f825bbbc13ecc588a2fa68a5 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 24 Mar 2025 22:42:23 +0100 Subject: [PATCH 4/6] bootstrap: Set CMAKE_SYSTEM_NAME=Darwin on Apple platforms compiler-rt's CMake setup seems to have special logic for Apple platforms that works poorly when this is not set. --- src/bootstrap/src/core/build_steps/llvm.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 41d3ca2c4cd40..de91b5d1eb5bb 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -697,6 +697,14 @@ fn configure_cmake( // reported, the system version is currently left unset. if target.contains("apple") { + if !target.contains("darwin") { + // FIXME(madsmtm): compiler-rt's CMake setup is kinda weird, it seems like they do + // version testing etc. for macOS (i.e. Darwin), even while building for iOS? + // + // So for now we set it to "Darwin" on all Apple platforms. + cfg.define("CMAKE_SYSTEM_NAME", "Darwin"); + } + // Make sure that CMake does not build universal binaries on macOS. // Explicitly specify the one single target architecture. if target.starts_with("aarch64") { From 1f675d3a69b8342c8c2b24598105d06bb513b312 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 24 Mar 2025 22:58:39 +0100 Subject: [PATCH 5/6] bootstrap: Override CMAKE_OSX_SYSROOT when building compiler-rt Similarly to what was previously done for the `llvm` step. --- src/bootstrap/src/core/build_steps/llvm.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index de91b5d1eb5bb..e21804fa3c07f 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -385,9 +385,6 @@ impl Step for Llvm { || target.contains("apple-watchos") || target.contains("apple-visionos") { - // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error. - cfg.define("CMAKE_OSX_SYSROOT", "/"); - cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", ""); // Prevent cmake from adding -bundle to CFLAGS automatically, which leads to a compiler error because "-bitcode_bundle" also gets added. cfg.define("LLVM_ENABLE_PLUGINS", "OFF"); // Zlib fails to link properly, leading to a compiler error. @@ -703,6 +700,10 @@ fn configure_cmake( // // So for now we set it to "Darwin" on all Apple platforms. cfg.define("CMAKE_SYSTEM_NAME", "Darwin"); + + // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error. + cfg.define("CMAKE_OSX_SYSROOT", "/"); + cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", ""); } // Make sure that CMake does not build universal binaries on macOS. From 81ac7b4e26d7976956211e5dd209b37c162f1577 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 25 Mar 2025 11:03:06 +0100 Subject: [PATCH 6/6] bootstrap: Update download-ci-llvm-stamp This PR makes a fairly large version update to CMake and cc, so it is likely that LLVM is built differently. --- src/bootstrap/download-ci-llvm-stamp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index d2c0d380fb40b..e157ff233bbf7 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/134740 +Last change is for: https://github.com/rust-lang/rust/pull/138784