Skip to content

Commit 0998d40

Browse files
committed
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
2 parents 57a4736 + ed5877e commit 0998d40

File tree

6 files changed

+83
-53
lines changed

6 files changed

+83
-53
lines changed

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bootstrap"
33
version = "0.0.0"
4-
edition = "2021"
4+
edition = "2024"
55
build = "build.rs"
66
default-run = "bootstrap"
77

src/bootstrap/src/bin/sccache-plus-cl.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ use std::process::{self, Command};
44
fn main() {
55
let target = env::var("SCCACHE_TARGET").unwrap();
66
// Locate the actual compiler that we're invoking
7-
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
8-
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
7+
8+
// SAFETY: we're in main, there are no other threads
9+
unsafe {
10+
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
11+
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
12+
}
13+
914
let mut cfg = cc::Build::new();
1015
cfg.cargo_metadata(false)
1116
.out_dir("/")

src/bootstrap/src/core/build_steps/format.rs

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

src/bootstrap/src/utils/cc_detect/tests.rs

+38-18
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ use crate::{Build, Config, Flags};
99
fn test_cc2ar_env_specific() {
1010
let triple = "x86_64-unknown-linux-gnu";
1111
let key = "AR_x86_64_unknown_linux_gnu";
12-
env::set_var(key, "custom-ar");
12+
// SAFETY: bootstrap tests run on a single thread
13+
unsafe { env::set_var(key, "custom-ar") };
1314
let target = TargetSelection::from_user(triple);
1415
let cc = Path::new("/usr/bin/clang");
1516
let default_ar = PathBuf::from("default-ar");
1617
let result = cc2ar(cc, target, default_ar);
17-
env::remove_var(key);
18+
// SAFETY: bootstrap tests run on a single thread
19+
unsafe { env::remove_var(key) };
1820
assert_eq!(result, Some(PathBuf::from("custom-ar")));
1921
}
2022

2123
#[test]
2224
fn test_cc2ar_musl() {
2325
let triple = "x86_64-unknown-linux-musl";
24-
env::remove_var("AR_x86_64_unknown_linux_musl");
25-
env::remove_var("AR");
26+
// SAFETY: bootstrap tests run on a single thread
27+
unsafe { env::remove_var("AR_x86_64_unknown_linux_musl") };
28+
// SAFETY: bootstrap tests run on a single thread
29+
unsafe { env::remove_var("AR") };
2630
let target = TargetSelection::from_user(triple);
2731
let cc = Path::new("/usr/bin/clang");
2832
let default_ar = PathBuf::from("default-ar");
@@ -33,8 +37,10 @@ fn test_cc2ar_musl() {
3337
#[test]
3438
fn test_cc2ar_openbsd() {
3539
let triple = "x86_64-unknown-openbsd";
36-
env::remove_var("AR_x86_64_unknown_openbsd");
37-
env::remove_var("AR");
40+
// SAFETY: bootstrap tests run on a single thread
41+
unsafe { env::remove_var("AR_x86_64_unknown_openbsd") };
42+
// SAFETY: bootstrap tests run on a single thread
43+
unsafe { env::remove_var("AR") };
3844
let target = TargetSelection::from_user(triple);
3945
let cc = Path::new("/usr/bin/cc");
4046
let default_ar = PathBuf::from("default-ar");
@@ -45,8 +51,10 @@ fn test_cc2ar_openbsd() {
4551
#[test]
4652
fn test_cc2ar_vxworks() {
4753
let triple = "armv7-wrs-vxworks";
48-
env::remove_var("AR_armv7_wrs_vxworks");
49-
env::remove_var("AR");
54+
// SAFETY: bootstrap tests run on a single thread
55+
unsafe { env::remove_var("AR_armv7_wrs_vxworks") };
56+
// SAFETY: bootstrap tests run on a single thread
57+
unsafe { env::remove_var("AR") };
5058
let target = TargetSelection::from_user(triple);
5159
let cc = Path::new("/usr/bin/clang");
5260
let default_ar = PathBuf::from("default-ar");
@@ -57,8 +65,10 @@ fn test_cc2ar_vxworks() {
5765
#[test]
5866
fn test_cc2ar_nto_i586() {
5967
let triple = "i586-unknown-nto-something";
60-
env::remove_var("AR_i586_unknown_nto_something");
61-
env::remove_var("AR");
68+
// SAFETY: bootstrap tests run on a single thread
69+
unsafe { env::remove_var("AR_i586_unknown_nto_something") };
70+
// SAFETY: bootstrap tests run on a single thread
71+
unsafe { env::remove_var("AR") };
6272
let target = TargetSelection::from_user(triple);
6373
let cc = Path::new("/usr/bin/clang");
6474
let default_ar = PathBuf::from("default-ar");
@@ -69,8 +79,10 @@ fn test_cc2ar_nto_i586() {
6979
#[test]
7080
fn test_cc2ar_nto_aarch64() {
7181
let triple = "aarch64-unknown-nto-something";
72-
env::remove_var("AR_aarch64_unknown_nto_something");
73-
env::remove_var("AR");
82+
// SAFETY: bootstrap tests run on a single thread
83+
unsafe { env::remove_var("AR_aarch64_unknown_nto_something") };
84+
// SAFETY: bootstrap tests run on a single thread
85+
unsafe { env::remove_var("AR") };
7486
let target = TargetSelection::from_user(triple);
7587
let cc = Path::new("/usr/bin/clang");
7688
let default_ar = PathBuf::from("default-ar");
@@ -81,8 +93,10 @@ fn test_cc2ar_nto_aarch64() {
8193
#[test]
8294
fn test_cc2ar_nto_x86_64() {
8395
let triple = "x86_64-unknown-nto-something";
84-
env::remove_var("AR_x86_64_unknown_nto_something");
85-
env::remove_var("AR");
96+
// SAFETY: bootstrap tests run on a single thread
97+
unsafe { env::remove_var("AR_x86_64_unknown_nto_something") };
98+
// SAFETY: bootstrap tests run on a single thread
99+
unsafe { env::remove_var("AR") };
86100
let target = TargetSelection::from_user(triple);
87101
let cc = Path::new("/usr/bin/clang");
88102
let default_ar = PathBuf::from("default-ar");
@@ -94,8 +108,10 @@ fn test_cc2ar_nto_x86_64() {
94108
#[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")]
95109
fn test_cc2ar_nto_unknown() {
96110
let triple = "powerpc-unknown-nto-something";
97-
env::remove_var("AR_powerpc_unknown_nto_something");
98-
env::remove_var("AR");
111+
// SAFETY: bootstrap tests run on a single thread
112+
unsafe { env::remove_var("AR_powerpc_unknown_nto_something") };
113+
// SAFETY: bootstrap tests run on a single thread
114+
unsafe { env::remove_var("AR") };
99115
let target = TargetSelection::from_user(triple);
100116
let cc = Path::new("/usr/bin/clang");
101117
let default_ar = PathBuf::from("default-ar");
@@ -177,7 +193,8 @@ fn test_default_compiler_wasi() {
177193
let build = Build::new(Config { ..Config::parse(Flags::parse(&["check".to_owned()])) });
178194
let target = TargetSelection::from_user("wasm32-wasi");
179195
let wasi_sdk = PathBuf::from("/wasi-sdk");
180-
env::set_var("WASI_SDK_PATH", &wasi_sdk);
196+
// SAFETY: bootstrap tests run on a single thread
197+
unsafe { env::set_var("WASI_SDK_PATH", &wasi_sdk) };
181198
let mut cfg = cc::Build::new();
182199
if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) {
183200
let expected = {
@@ -190,7 +207,10 @@ fn test_default_compiler_wasi() {
190207
"default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set"
191208
);
192209
}
193-
env::remove_var("WASI_SDK_PATH");
210+
// SAFETY: bootstrap tests run on a single thread
211+
unsafe {
212+
env::remove_var("WASI_SDK_PATH");
213+
}
194214
}
195215

196216
#[test]

src/bootstrap/src/utils/helpers.rs

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

src/bootstrap/src/utils/job.rs

+35-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ pub unsafe fn setup(_build: &mut crate::Build) {}
77
#[cfg(all(unix, not(target_os = "haiku")))]
88
pub unsafe fn setup(build: &mut crate::Build) {
99
if build.config.low_priority {
10-
libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
10+
unsafe {
11+
libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
12+
}
1113
}
1214
}
1315

@@ -59,38 +61,41 @@ mod for_windows {
5961
use crate::Build;
6062

6163
pub unsafe fn setup(build: &mut Build) {
62-
// Enable the Windows Error Reporting dialog which msys disables,
63-
// so we can JIT debug rustc
64-
let mode = SetErrorMode(THREAD_ERROR_MODE::default());
65-
let mode = THREAD_ERROR_MODE(mode);
66-
SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
64+
// SAFETY: pretty much everything below is unsafe
65+
unsafe {
66+
// Enable the Windows Error Reporting dialog which msys disables,
67+
// so we can JIT debug rustc
68+
let mode = SetErrorMode(THREAD_ERROR_MODE::default());
69+
let mode = THREAD_ERROR_MODE(mode);
70+
SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
6771

68-
// Create a new job object for us to use
69-
let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
72+
// Create a new job object for us to use
73+
let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
7074

71-
// Indicate that when all handles to the job object are gone that all
72-
// process in the object should be killed. Note that this includes our
73-
// entire process tree by default because we've added ourselves and our
74-
// children will reside in the job by default.
75-
let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
76-
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
77-
if build.config.low_priority {
78-
info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
79-
info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
80-
}
81-
let r = SetInformationJobObject(
82-
job,
83-
JobObjectExtendedLimitInformation,
84-
&info as *const _ as *const c_void,
85-
size_of_val(&info) as u32,
86-
);
87-
assert!(r.is_ok(), "{}", io::Error::last_os_error());
75+
// Indicate that when all handles to the job object are gone that all
76+
// process in the object should be killed. Note that this includes our
77+
// entire process tree by default because we've added ourselves and our
78+
// children will reside in the job by default.
79+
let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
80+
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
81+
if build.config.low_priority {
82+
info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
83+
info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
84+
}
85+
let r = SetInformationJobObject(
86+
job,
87+
JobObjectExtendedLimitInformation,
88+
&info as *const _ as *const c_void,
89+
size_of_val(&info) as u32,
90+
);
91+
assert!(r.is_ok(), "{}", io::Error::last_os_error());
8892

89-
// Assign our process to this job object.
90-
let r = AssignProcessToJobObject(job, GetCurrentProcess());
91-
if r.is_err() {
92-
CloseHandle(job).ok();
93-
return;
93+
// Assign our process to this job object.
94+
let r = AssignProcessToJobObject(job, GetCurrentProcess());
95+
if r.is_err() {
96+
CloseHandle(job).ok();
97+
return;
98+
}
9499
}
95100

96101
// Note: we intentionally leak the job object handle. When our process exits

0 commit comments

Comments
 (0)