diff --git a/config.toml.example b/config.toml.example index 6e53d9b442f16..ecc3e0ef77ff0 100644 --- a/config.toml.example +++ b/config.toml.example @@ -258,6 +258,9 @@ changelog-seen = 2 # Defaults to the Python interpreter used to execute x.py #python = "python" +# Path to (or name of) the CMake 3 executable to build LLVM. +#cmake = "cmake" + # Force Cargo to check that Cargo.lock describes the precise dependency # set that all the Cargo.toml files create, instead of updating it. #locked-deps = false diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index d7c29f6900a53..6df43bab11517 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -185,6 +185,7 @@ pub struct Config { pub npm: Option, pub gdb: Option, pub python: Option, + pub cmake: Option, pub cargo_native_static: bool, pub configure_args: Vec, @@ -474,6 +475,7 @@ define_config! { nodejs: Option = "nodejs", npm: Option = "npm", python: Option = "python", + cmake: Option = "cmake", locked_deps: Option = "locked-deps", vendor: Option = "vendor", full_bootstrap: Option = "full-bootstrap", @@ -793,6 +795,7 @@ impl Config { config.npm = build.npm.map(PathBuf::from); config.gdb = build.gdb.map(PathBuf::from); config.python = build.python.map(PathBuf::from); + config.cmake = build.cmake.map(PathBuf::from); config.submodules = build.submodules; set(&mut config.low_priority, build.low_priority); set(&mut config.compiler_docs, build.compiler_docs); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 59102ad9f50b8..b39950729a484 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -645,6 +645,9 @@ impl Build { unsafe { job::setup(self); } + if let Some(cmake) = self.config.cmake.as_ref() { + env::set_var("CMAKE", cmake); // https://docs.rs/cmake/0.1.48/src/cmake/lib.rs.html#515 + } self.maybe_update_submodules(); diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index c96e6f9a3678f..dc0a8b691d45b 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -92,10 +92,31 @@ pub fn check(build: &mut Build) { .unwrap_or(true) }) .any(|build_llvm_ourselves| build_llvm_ourselves); - let need_cmake = building_llvm || build.config.any_sanitizers_enabled(); - if need_cmake { - cmd_finder.must_have("cmake"); - } + let need_default_cmake = if building_llvm || build.config.any_sanitizers_enabled() { + let cmake_env_var = env::var_os("CMAKE"); + if let Some(explicit_name) = build.config.cmake.take() { + if let Some(cmake_from_env) = cmake_env_var { + if explicit_name != cmake_from_env { + eprintln!( + "env var CMAKE = {cmake_from_env:?} != {explicit_name:?} from config.toml" + ) + } + } + build.config.cmake = cmd_finder.must_have(explicit_name).into(); + None + } else { + // _very_ simplified version of getenv_target_os("CMAKE") from + // https://docs.rs/cmake/0.1.48/src/cmake/lib.rs.html#515 + if let Some(cmake_from_env) = cmake_env_var { + cmd_finder.must_have(cmake_from_env) + } else { + cmd_finder.must_have("cmake") + } + .into() + } + } else { + None + }; build.config.python = build .config @@ -201,14 +222,17 @@ pub fn check(build: &mut Build) { } } - if need_cmake && target.contains("msvc") { - // There are three builds of cmake on windows: MSVC, MinGW, and - // Cygwin. The Cygwin build does not have generators for Visual - // Studio, so detect that here and error. - let out = output(Command::new("cmake").arg("--help")); - if !out.contains("Visual Studio") { - panic!( - " + if target.contains("msvc") { + if let Some(ref cmake_path) = + need_default_cmake.as_ref().or(build.config.cmake.as_ref()) + { + // There are three builds of cmake on windows: MSVC, MinGW, and + // Cygwin. The Cygwin build does not have generators for Visual + // Studio, so detect that here and error. + let out = output(Command::new(cmake_path).arg("--help")); + if !out.contains("Visual Studio") { + panic!( + " cmake does not support Visual Studio generators. This is likely due to it being an msys/cygwin build of cmake, @@ -220,7 +244,8 @@ package instead of cmake: $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake " - ); + ); + } } } }