Skip to content

Commit 680f4b6

Browse files
committed
bootstrap: cmake cmd configurable with config.toml
Signed-off-by: NODA Kai <[email protected]>
1 parent c102c5c commit 680f4b6

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ changelog-seen = 2
258258
# Defaults to the Python interpreter used to execute x.py
259259
#python = "python"
260260

261+
# Path to (or name of) the CMake 3 executable to build LLVM.
262+
#cmake = "cmake"
263+
261264
# Force Cargo to check that Cargo.lock describes the precise dependency
262265
# set that all the Cargo.toml files create, instead of updating it.
263266
#locked-deps = false

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub struct Config {
185185
pub npm: Option<PathBuf>,
186186
pub gdb: Option<PathBuf>,
187187
pub python: Option<PathBuf>,
188+
pub cmake: Option<PathBuf>,
188189
pub cargo_native_static: bool,
189190
pub configure_args: Vec<String>,
190191

@@ -474,6 +475,7 @@ define_config! {
474475
nodejs: Option<String> = "nodejs",
475476
npm: Option<String> = "npm",
476477
python: Option<String> = "python",
478+
cmake: Option<String> = "cmake",
477479
locked_deps: Option<bool> = "locked-deps",
478480
vendor: Option<bool> = "vendor",
479481
full_bootstrap: Option<bool> = "full-bootstrap",
@@ -793,6 +795,7 @@ impl Config {
793795
config.npm = build.npm.map(PathBuf::from);
794796
config.gdb = build.gdb.map(PathBuf::from);
795797
config.python = build.python.map(PathBuf::from);
798+
config.cmake = build.cmake.map(PathBuf::from);
796799
config.submodules = build.submodules;
797800
set(&mut config.low_priority, build.low_priority);
798801
set(&mut config.compiler_docs, build.compiler_docs);

src/bootstrap/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ impl Build {
645645
unsafe {
646646
job::setup(self);
647647
}
648+
if let Some(cmake) = self.config.cmake.as_ref() {
649+
env::set_var("CMAKE", cmake); // https://docs.rs/cmake/0.1.48/src/cmake/lib.rs.html#515
650+
}
648651

649652
self.maybe_update_submodules();
650653

src/bootstrap/sanity.rs

+38-13
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,31 @@ pub fn check(build: &mut Build) {
9292
.unwrap_or(true)
9393
})
9494
.any(|build_llvm_ourselves| build_llvm_ourselves);
95-
let need_cmake = building_llvm || build.config.any_sanitizers_enabled();
96-
if need_cmake {
97-
cmd_finder.must_have("cmake");
98-
}
95+
let need_default_cmake = if building_llvm || build.config.any_sanitizers_enabled() {
96+
let cmake_env_var = env::var_os("CMAKE");
97+
if let Some(explicit_name) = build.config.cmake.take() {
98+
if let Some(cmake_from_env) = cmake_env_var {
99+
if explicit_name != cmake_from_env {
100+
eprintln!(
101+
"env var CMAKE = {cmake_from_env:?} != {explicit_name:?} from config.toml"
102+
)
103+
}
104+
}
105+
build.config.cmake = cmd_finder.must_have(explicit_name).into();
106+
None
107+
} else {
108+
// _very_ simplified version of getenv_target_os("CMAKE") from
109+
// https://docs.rs/cmake/0.1.48/src/cmake/lib.rs.html#515
110+
if let Some(cmake_from_env) = cmake_env_var {
111+
cmd_finder.must_have(cmake_from_env)
112+
} else {
113+
cmd_finder.must_have("cmake")
114+
}
115+
.into()
116+
}
117+
} else {
118+
None
119+
};
99120

100121
build.config.python = build
101122
.config
@@ -201,14 +222,17 @@ pub fn check(build: &mut Build) {
201222
}
202223
}
203224

204-
if need_cmake && target.contains("msvc") {
205-
// There are three builds of cmake on windows: MSVC, MinGW, and
206-
// Cygwin. The Cygwin build does not have generators for Visual
207-
// Studio, so detect that here and error.
208-
let out = output(Command::new("cmake").arg("--help"));
209-
if !out.contains("Visual Studio") {
210-
panic!(
211-
"
225+
if target.contains("msvc") {
226+
if let Some(ref cmake_path) =
227+
need_default_cmake.as_ref().or(build.config.cmake.as_ref())
228+
{
229+
// There are three builds of cmake on windows: MSVC, MinGW, and
230+
// Cygwin. The Cygwin build does not have generators for Visual
231+
// Studio, so detect that here and error.
232+
let out = output(Command::new(cmake_path).arg("--help"));
233+
if !out.contains("Visual Studio") {
234+
panic!(
235+
"
212236
cmake does not support Visual Studio generators.
213237
214238
This is likely due to it being an msys/cygwin build of cmake,
@@ -220,7 +244,8 @@ package instead of cmake:
220244
221245
$ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
222246
"
223-
);
247+
);
248+
}
224249
}
225250
}
226251
}

0 commit comments

Comments
 (0)