Skip to content

Commit

Permalink
bootstrap: cmake cmd configurable with config.toml
Browse files Browse the repository at this point in the history
Signed-off-by: NODA Kai <[email protected]>
  • Loading branch information
nodakai committed Apr 19, 2022
1 parent c102c5c commit 680f4b6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub struct Config {
pub npm: Option<PathBuf>,
pub gdb: Option<PathBuf>,
pub python: Option<PathBuf>,
pub cmake: Option<PathBuf>,
pub cargo_native_static: bool,
pub configure_args: Vec<String>,

Expand Down Expand Up @@ -474,6 +475,7 @@ define_config! {
nodejs: Option<String> = "nodejs",
npm: Option<String> = "npm",
python: Option<String> = "python",
cmake: Option<String> = "cmake",
locked_deps: Option<bool> = "locked-deps",
vendor: Option<bool> = "vendor",
full_bootstrap: Option<bool> = "full-bootstrap",
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
51 changes: 38 additions & 13 deletions src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -220,7 +244,8 @@ package instead of cmake:
$ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
"
);
);
}
}
}
}
Expand Down

0 comments on commit 680f4b6

Please sign in to comment.