Skip to content

Commit

Permalink
Update bootstrap to edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Feb 25, 2025
1 parent ad27045 commit 65b917c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bootstrap"
version = "0.0.0"
edition = "2021"
edition = "2024"
build = "build.rs"
default-run = "bootstrap"

Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/src/bin/sccache-plus-cl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ use std::process::{self, Command};
fn main() {
let target = env::var("SCCACHE_TARGET").unwrap();
// Locate the actual compiler that we're invoking
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());

// SAFETY: we're in main, there are no other threads
unsafe {
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
}

let mut cfg = cc::Build::new();
cfg.cargo_metadata(false)
.out_dir("/")
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn rustfmt(
rustfmt: &Path,
paths: &[PathBuf],
check: bool,
) -> impl FnMut(bool) -> RustfmtStatus {
) -> impl FnMut(bool) -> RustfmtStatus + use<> {
let mut cmd = Command::new(rustfmt);
// Avoid the submodule config paths from coming into play. We only allow a single global config
// for the workspace for now.
Expand Down
51 changes: 34 additions & 17 deletions src/bootstrap/src/utils/cc_detect/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ use crate::{Build, Config, Flags};
fn test_cc2ar_env_specific() {
let triple = "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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("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")));
}

#[test]
fn test_cc2ar_musl() {
let triple = "x86_64-unknown-linux-musl";
env::remove_var("AR_x86_64_unknown_linux_musl");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -33,8 +37,10 @@ fn test_cc2ar_musl() {
#[test]
fn test_cc2ar_openbsd() {
let triple = "x86_64-unknown-openbsd";
env::remove_var("AR_x86_64_unknown_openbsd");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/cc");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -45,8 +51,10 @@ fn test_cc2ar_openbsd() {
#[test]
fn test_cc2ar_vxworks() {
let triple = "armv7-wrs-vxworks";
env::remove_var("AR_armv7_wrs_vxworks");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -57,8 +65,10 @@ fn test_cc2ar_vxworks() {
#[test]
fn test_cc2ar_nto_i586() {
let triple = "i586-unknown-nto-something";
env::remove_var("AR_i586_unknown_nto_something");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -69,8 +79,10 @@ fn test_cc2ar_nto_i586() {
#[test]
fn test_cc2ar_nto_aarch64() {
let triple = "aarch64-unknown-nto-something";
env::remove_var("AR_aarch64_unknown_nto_something");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -81,8 +93,10 @@ fn test_cc2ar_nto_aarch64() {
#[test]
fn test_cc2ar_nto_x86_64() {
let triple = "x86_64-unknown-nto-something";
env::remove_var("AR_x86_64_unknown_nto_something");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand All @@ -94,8 +108,10 @@ fn test_cc2ar_nto_x86_64() {
#[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")]
fn test_cc2ar_nto_unknown() {
let triple = "powerpc-unknown-nto-something";
env::remove_var("AR_powerpc_unknown_nto_something");
env::remove_var("AR");
// SAFETY: bootstrap tests run on a single thread
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 cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
Expand Down Expand Up @@ -177,7 +193,8 @@ fn test_default_compiler_wasi() {
let build = Build::new(Config { ..Config::parse(Flags::parse(&["check".to_owned()])) });
let target = TargetSelection::from_user("wasm32-wasi");
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();
if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) {
let expected = {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub fn output(cmd: &mut Command) -> String {
/// to finish and then return its output. This allows the spawned process
/// to do work without immediately blocking bootstrap.
#[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() {
Ok(child) => child,
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/src/utils/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ pub unsafe fn setup(_build: &mut crate::Build) {}
#[cfg(all(unix, not(target_os = "haiku")))]
pub unsafe fn setup(build: &mut crate::Build) {
if build.config.low_priority {
libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
unsafe {
libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
}
}
}

Expand Down

0 comments on commit 65b917c

Please sign in to comment.