-
Notifications
You must be signed in to change notification settings - Fork 13.4k
bootstrap: make cmake executable configurable with config.toml #85728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of this logic probably belongs in config.rs, not here. We should always have build.config.cmake as the source of truth for the cmake path, and support setting it only via config.toml. (If it is set in the environment and not equal to the config.toml value, it should be a panic! at config parse time). Here, we should just have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a couple of comments, let me start with minor ones (since major ones are going to take more time to write)
I'll find time to add more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think panic! is probably best.
Looking into our use of cmake a little more, it looks like we only ever actually invoke it through the cmake crate, so if users are supplying configuration to us via env variables, the cmake crate would already be picking that up appropriately. In sanity checking, we do use "cmake" without doing the same env-variable lookup that the cmake crate does. (Target-specific cmake binaries do not feel particularly likely to be actually necessary, as it's really a host tool). I'm not too worried about env-variables overriding bootstrap's configuration in the cmake crate - that seems unlikely to be an issue in practice, given how bootstrap itself isn't using cmake directly (except for sanity checks). Given that CMAKE isn't a "standard" env variable (or at least I've seen no evidence of that), I'm not really worried about supporting setting it as an alternative to editing config.toml, either. So I think the value of config.cmake probably comes down to:
After we load that, we want to put it in our own environment (set_var("CMAKE")) so that the cmake crate picks it up, at least as things stand today. Just before doing that I think it makes sense to check that it's not set to a different value (mostly just as a sanity check, but it doesn't make sense for this to be in sanity.rs). Pretty much all of that logic should go into config.rs. |
||
|
||
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 | ||
" | ||
); | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.