Skip to content

Prefer cmake3 to cmake when bootstrapping. #71262

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def download(path, url, probably_big, verbose):
def _download(path, url, probably_big, verbose, exception):
if probably_big or verbose:
print("downloading {}".format(url))
# see http://serverfault.com/questions/301128/how-to-download
# See http://serverfault.com/questions/301128/how-to-download.
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
Expand All @@ -79,7 +79,7 @@ def _download(path, url, probably_big, verbose, exception):
else:
option = "-s"
run(["curl", option,
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
"--retry", "3", "-Sf", "-o", path, url],
verbose=verbose,
Expand Down Expand Up @@ -131,7 +131,7 @@ def run(args, verbose=False, exception=False, **kwargs):
if verbose:
print("running: " + ' '.join(args))
sys.stdout.flush()
# Use Popen here instead of call() as it apparently allows powershell on
# Use `Popen` here instead of `call()` as it apparently allows powershell on
# Windows to not lock up waiting for input presumably.
ret = subprocess.Popen(args, **kwargs)
code = ret.wait()
Expand Down Expand Up @@ -660,6 +660,7 @@ def bootstrap_binary(self):

def build_bootstrap(self):
"""Build bootstrap"""

build_dir = os.path.join(self.build_dir, "bootstrap")
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
Expand All @@ -680,7 +681,7 @@ def build_bootstrap(self):
env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \
(os.pathsep + env["LIBRARY_PATH"]) \
if "LIBRARY_PATH" in env else ""
# preserve existing RUSTFLAGS
# Preserve existing `RUSTFLAGS`.
env.setdefault("RUSTFLAGS", "")
env["RUSTFLAGS"] += " -Cdebuginfo=2"

Expand Down Expand Up @@ -748,7 +749,7 @@ def update_submodule(self, module, checked_out, recorded_submodules):
"--init", "--recursive", "--progress", module],
cwd=self.rust_root, verbose=self.verbose, exception=True)
except RuntimeError:
# Some versions of git don't support --progress.
# Some versions of Git don't support `--progress`.
run(["git", "submodule", "update",
"--init", "--recursive", module],
cwd=self.rust_root, verbose=self.verbose)
Expand All @@ -763,7 +764,7 @@ def update_submodules(self):
self.get_toml('submodules') == "false":
return

# check the existence of 'git' command
# Check for the existence of the `git` executable.
try:
subprocess.check_output(['git', '--version'])
except (subprocess.CalledProcessError, OSError):
Expand Down Expand Up @@ -878,7 +879,7 @@ def bootstrap(help_triggered):
args = [a for a in sys.argv if a != '-h' and a != '--help']
args, _ = parser.parse_known_args(args)

# Configure initial bootstrap
# Configure initial bootstrap.
build = RustBuild()
build.rust_root = args.src or os.path.abspath(os.path.join(__file__, '../../..'))
build.verbose = args.verbose
Expand Down Expand Up @@ -944,7 +945,7 @@ def main():
"""Entry point for the bootstrap process"""
start_time = time()

# x.py help <cmd> ...
# `x.py help <cmd> ...`
if len(sys.argv) > 1 and sys.argv[1] == 'help':
sys.argv = [sys.argv[0], '-h'] + sys.argv[2:]

Expand Down
44 changes: 29 additions & 15 deletions src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Sanity checking performed by rustbuild before actually executing anything.
//! Sanity-checking performed by rustbuild before actually executing anything.
//!
//! This module contains the implementation of ensuring that the build
//! environment looks reasonable before progressing. This will verify that
Expand Down Expand Up @@ -41,10 +41,10 @@ impl Finder {
let mut cmd_exe = cmd.clone();
cmd_exe.push(".exe");

if target.is_file() // some/path/git
|| path.join(&cmd_exe).exists() // some/path/git.exe
if target.is_file() // `some/path/git`
|| path.join(&cmd_exe).exists() // `some/path/git.exe`
|| target.join(&cmd_exe).exists()
// some/path/git/git.exe
// `some/path/git/git.exe`
{
return Some(target);
}
Expand All @@ -68,7 +68,7 @@ pub fn check(build: &mut Build) {
// being unable to identify the files properly. See
// https://github.com/rust-lang/rust/issues/34959 for more details.
if cfg!(windows) && path.to_string_lossy().contains('\"') {
panic!("PATH contains invalid character '\"'");
panic!("`PATH` contains invalid character '\"'");
}

let mut cmd_finder = Finder::new();
Expand All @@ -78,7 +78,7 @@ pub fn check(build: &mut Build) {
cmd_finder.must_have("git");
}

// We need cmake, but only if we're actually building LLVM or sanitizers.
// We need CMake, but only if we're actually building LLVM or sanitizers.
let building_llvm = build
.hosts
.iter()
Expand All @@ -92,7 +92,17 @@ pub fn check(build: &mut Build) {
})
.any(|build_llvm_ourselves| build_llvm_ourselves);
if building_llvm || build.config.sanitizers {
cmd_finder.must_have("cmake");
// Choose CMake executable with the following priority:
// 1. `CMAKE` env var, if set.
// 2. `cmake3`, if it exists.
// 3. `cmake`.
if let Some(cmake_path) = env::var_os("CMAKE") {
cmd_finder.must_have(cmake_path);
} else if cmd_finder.maybe_have("cmake3").is_some() {
env::set_var("CMAKE", "cmake3");
} else {
cmd_finder.must_have("cmake");
}
}

// Ninja is currently only used for LLVM itself.
Expand All @@ -105,7 +115,7 @@ pub fn check(build: &mut Build) {
}
}

// If ninja isn't enabled but we're building for MSVC then we try
// If Ninja isn't enabled but we're building for MSVC then we try
// doubly hard to enable it. It was realized in #43767 that the msbuild
// CMake generator for MSVC doesn't respect configuration options like
// disabling LLVM assertions, which can often be quite important!
Expand Down Expand Up @@ -182,7 +192,7 @@ pub fn check(build: &mut Build) {
// Externally configured LLVM requires FileCheck to exist
let filecheck = build.llvm_filecheck(build.build);
if !filecheck.starts_with(&build.out) && !filecheck.exists() && build.config.codegen_tests {
panic!("FileCheck executable {:?} does not exist", filecheck);
panic!("FileCheck executable `{:?}` does not exist", filecheck);
}

for target in &build.targets {
Expand Down Expand Up @@ -210,13 +220,16 @@ pub fn check(build: &mut Build) {
match build.musl_root(*target) {
Some(root) => {
if fs::metadata(root.join("lib/libc.a")).is_err() {
panic!("couldn't find libc.a in musl dir: {}", root.join("lib").display());
panic!(
"couldn't find `libc.a` in musl dir: {}",
root.join("lib").display()
);
}
}
None => panic!(
"when targeting MUSL either the rust.musl-root \
option or the target.$TARGET.musl-root option must \
be specified in config.toml"
"when targeting MUSL, either the `rust.musl-root` \
option or the `target.$TARGET.musl-root` option must \
be specified in `config.toml`"
),
}
}
Expand All @@ -225,7 +238,8 @@ pub fn check(build: &mut Build) {
// 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"));
let cmake_path = env::var("CMAKE").unwrap_or("cmake".into());
let out = output(Command::new(cmake_path).arg("--help"));
if !out.contains("Visual Studio") {
panic!(
"
Expand Down Expand Up @@ -254,7 +268,7 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
if stage0.contains("\ndev:") {
panic!(
"bootstrapping from a dev compiler in a stable release, but \
should only be bootstrapping from a released compiler!"
should only be bootstrapping from a released compiler!"
);
}
}
Expand Down