1
Fork 0

Auto merge of #137612 - Kobzol:bootstrap-2024, r=onur-ozkan

Update bootstrap to edition 2024

The stage0 compiler now supports edition 2024, so we can update bootstrap to it. I manually reviewed all the changes from `cargo fix --edition` and reverted most of them (`if let` -> `matches` changes and two unneeded usages of `use <>`).

r? `@onur-ozkan`

try-job: dist-x86_64-msvc
This commit is contained in:
bors 2025-03-12 11:05:40 +00:00
commit 0998d4095b
6 changed files with 83 additions and 53 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "bootstrap" name = "bootstrap"
version = "0.0.0" version = "0.0.0"
edition = "2021" edition = "2024"
build = "build.rs" build = "build.rs"
default-run = "bootstrap" default-run = "bootstrap"

View file

@ -4,8 +4,13 @@ use std::process::{self, Command};
fn main() { fn main() {
let target = env::var("SCCACHE_TARGET").unwrap(); let target = env::var("SCCACHE_TARGET").unwrap();
// Locate the actual compiler that we're invoking // Locate the actual compiler that we're invoking
// SAFETY: we're in main, there are no other threads
unsafe {
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap()); env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap()); env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
}
let mut cfg = cc::Build::new(); let mut cfg = cc::Build::new();
cfg.cargo_metadata(false) cfg.cargo_metadata(false)
.out_dir("/") .out_dir("/")

View file

@ -27,7 +27,7 @@ fn rustfmt(
rustfmt: &Path, rustfmt: &Path,
paths: &[PathBuf], paths: &[PathBuf],
check: bool, check: bool,
) -> impl FnMut(bool) -> RustfmtStatus { ) -> impl FnMut(bool) -> RustfmtStatus + use<> {
let mut cmd = Command::new(rustfmt); let mut cmd = Command::new(rustfmt);
// Avoid the submodule config paths from coming into play. We only allow a single global config // Avoid the submodule config paths from coming into play. We only allow a single global config
// for the workspace for now. // for the workspace for now.

View file

@ -9,20 +9,24 @@ use crate::{Build, Config, Flags};
fn test_cc2ar_env_specific() { fn test_cc2ar_env_specific() {
let triple = "x86_64-unknown-linux-gnu"; let triple = "x86_64-unknown-linux-gnu";
let key = "AR_x86_64_unknown_linux_gnu"; let key = "AR_x86_64_unknown_linux_gnu";
env::set_var(key, "custom-ar"); // SAFETY: bootstrap tests run on a single thread
unsafe { env::set_var(key, "custom-ar") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar); let result = cc2ar(cc, target, default_ar);
env::remove_var(key); // SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var(key) };
assert_eq!(result, Some(PathBuf::from("custom-ar"))); assert_eq!(result, Some(PathBuf::from("custom-ar")));
} }
#[test] #[test]
fn test_cc2ar_musl() { fn test_cc2ar_musl() {
let triple = "x86_64-unknown-linux-musl"; let triple = "x86_64-unknown-linux-musl";
env::remove_var("AR_x86_64_unknown_linux_musl"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_x86_64_unknown_linux_musl") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -33,8 +37,10 @@ fn test_cc2ar_musl() {
#[test] #[test]
fn test_cc2ar_openbsd() { fn test_cc2ar_openbsd() {
let triple = "x86_64-unknown-openbsd"; let triple = "x86_64-unknown-openbsd";
env::remove_var("AR_x86_64_unknown_openbsd"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_x86_64_unknown_openbsd") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/cc"); let cc = Path::new("/usr/bin/cc");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -45,8 +51,10 @@ fn test_cc2ar_openbsd() {
#[test] #[test]
fn test_cc2ar_vxworks() { fn test_cc2ar_vxworks() {
let triple = "armv7-wrs-vxworks"; let triple = "armv7-wrs-vxworks";
env::remove_var("AR_armv7_wrs_vxworks"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_armv7_wrs_vxworks") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -57,8 +65,10 @@ fn test_cc2ar_vxworks() {
#[test] #[test]
fn test_cc2ar_nto_i586() { fn test_cc2ar_nto_i586() {
let triple = "i586-unknown-nto-something"; let triple = "i586-unknown-nto-something";
env::remove_var("AR_i586_unknown_nto_something"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_i586_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -69,8 +79,10 @@ fn test_cc2ar_nto_i586() {
#[test] #[test]
fn test_cc2ar_nto_aarch64() { fn test_cc2ar_nto_aarch64() {
let triple = "aarch64-unknown-nto-something"; let triple = "aarch64-unknown-nto-something";
env::remove_var("AR_aarch64_unknown_nto_something"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_aarch64_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -81,8 +93,10 @@ fn test_cc2ar_nto_aarch64() {
#[test] #[test]
fn test_cc2ar_nto_x86_64() { fn test_cc2ar_nto_x86_64() {
let triple = "x86_64-unknown-nto-something"; let triple = "x86_64-unknown-nto-something";
env::remove_var("AR_x86_64_unknown_nto_something"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_x86_64_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -94,8 +108,10 @@ fn test_cc2ar_nto_x86_64() {
#[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")] #[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")]
fn test_cc2ar_nto_unknown() { fn test_cc2ar_nto_unknown() {
let triple = "powerpc-unknown-nto-something"; let triple = "powerpc-unknown-nto-something";
env::remove_var("AR_powerpc_unknown_nto_something"); // SAFETY: bootstrap tests run on a single thread
env::remove_var("AR"); unsafe { env::remove_var("AR_powerpc_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple); let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang"); let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar"); let default_ar = PathBuf::from("default-ar");
@ -177,7 +193,8 @@ fn test_default_compiler_wasi() {
let build = Build::new(Config { ..Config::parse(Flags::parse(&["check".to_owned()])) }); let build = Build::new(Config { ..Config::parse(Flags::parse(&["check".to_owned()])) });
let target = TargetSelection::from_user("wasm32-wasi"); let target = TargetSelection::from_user("wasm32-wasi");
let wasi_sdk = PathBuf::from("/wasi-sdk"); let wasi_sdk = PathBuf::from("/wasi-sdk");
env::set_var("WASI_SDK_PATH", &wasi_sdk); // SAFETY: bootstrap tests run on a single thread
unsafe { env::set_var("WASI_SDK_PATH", &wasi_sdk) };
let mut cfg = cc::Build::new(); let mut cfg = cc::Build::new();
if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) { if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) {
let expected = { let expected = {
@ -190,7 +207,10 @@ fn test_default_compiler_wasi() {
"default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set" "default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set"
); );
} }
// SAFETY: bootstrap tests run on a single thread
unsafe {
env::remove_var("WASI_SDK_PATH"); env::remove_var("WASI_SDK_PATH");
}
} }
#[test] #[test]

View file

@ -286,7 +286,7 @@ pub fn output(cmd: &mut Command) -> String {
/// to finish and then return its output. This allows the spawned process /// to finish and then return its output. This allows the spawned process
/// to do work without immediately blocking bootstrap. /// to do work without immediately blocking bootstrap.
#[track_caller] #[track_caller]
pub fn start_process(cmd: &mut Command) -> impl FnOnce() -> String { pub fn start_process(cmd: &mut Command) -> impl FnOnce() -> String + use<> {
let child = match cmd.stderr(Stdio::inherit()).stdout(Stdio::piped()).spawn() { let child = match cmd.stderr(Stdio::inherit()).stdout(Stdio::piped()).spawn() {
Ok(child) => child, Ok(child) => child,
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")), Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),

View file

@ -7,8 +7,10 @@ pub unsafe fn setup(_build: &mut crate::Build) {}
#[cfg(all(unix, not(target_os = "haiku")))] #[cfg(all(unix, not(target_os = "haiku")))]
pub unsafe fn setup(build: &mut crate::Build) { pub unsafe fn setup(build: &mut crate::Build) {
if build.config.low_priority { if build.config.low_priority {
unsafe {
libc::setpriority(libc::PRIO_PGRP as _, 0, 10); libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
} }
}
} }
/// Job management on Windows for bootstrapping /// Job management on Windows for bootstrapping
@ -59,6 +61,8 @@ mod for_windows {
use crate::Build; use crate::Build;
pub unsafe fn setup(build: &mut Build) { pub unsafe fn setup(build: &mut Build) {
// SAFETY: pretty much everything below is unsafe
unsafe {
// Enable the Windows Error Reporting dialog which msys disables, // Enable the Windows Error Reporting dialog which msys disables,
// so we can JIT debug rustc // so we can JIT debug rustc
let mode = SetErrorMode(THREAD_ERROR_MODE::default()); let mode = SetErrorMode(THREAD_ERROR_MODE::default());
@ -92,6 +96,7 @@ mod for_windows {
CloseHandle(job).ok(); CloseHandle(job).ok();
return; return;
} }
}
// Note: we intentionally leak the job object handle. When our process exits // Note: we intentionally leak the job object handle. When our process exits
// (normally or abnormally) it will close the handle implicitly, causing all // (normally or abnormally) it will close the handle implicitly, causing all