Skip to content

Commit 99aaded

Browse files
authored
Rollup merge of #118528 - onur-ozkan:use-std-once-lock, r=clubby789
replace `once_cell::sync::OnceCell` with std `OnceLock` > https://github.com/rust-lang/rust/blob/0919ad18381f6f4fcaddc809e786553e028bbde0/src/bootstrap/src/core/builder.rs#L28-L33 Partially resolves that.
2 parents b384767 + b7e6da8 commit 99aaded

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/bootstrap/src/core/builder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::io::{BufRead, BufReader};
1010
use std::ops::Deref;
1111
use std::path::{Path, PathBuf};
1212
use std::process::Command;
13+
use std::sync::OnceLock;
1314
use std::time::{Duration, Instant};
1415

1516
use crate::core::build_steps::llvm;
@@ -25,12 +26,10 @@ use crate::EXTRA_CHECK_CFGS;
2526
use crate::{Build, CLang, DocTests, GitRepo, Mode};
2627

2728
pub use crate::Compiler;
28-
// FIXME:
29-
// - use std::lazy for `Lazy`
30-
// - use std::cell for `OnceCell`
31-
// Once they get stabilized and reach beta.
29+
3230
use clap::ValueEnum;
33-
use once_cell::sync::{Lazy, OnceCell};
31+
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
32+
use once_cell::sync::Lazy;
3433

3534
#[cfg(test)]
3635
#[path = "../tests/builder.rs"]
@@ -496,7 +495,7 @@ impl<'a> ShouldRun<'a> {
496495
///
497496
/// [`path`]: ShouldRun::path
498497
pub fn paths(mut self, paths: &[&str]) -> Self {
499-
static SUBMODULES_PATHS: OnceCell<Vec<String>> = OnceCell::new();
498+
static SUBMODULES_PATHS: OnceLock<Vec<String>> = OnceLock::new();
500499

501500
let init_submodules_paths = |src: &PathBuf| {
502501
let file = File::open(src.join(".gitmodules")).unwrap();

src/bootstrap/src/core/config/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::io::IsTerminal;
1717
use std::path::{Path, PathBuf};
1818
use std::process::Command;
1919
use std::str::FromStr;
20+
use std::sync::OnceLock;
2021

2122
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
2223
use crate::core::build_steps::llvm;
@@ -25,7 +26,6 @@ use crate::utils::cache::{Interned, INTERNER};
2526
use crate::utils::channel::{self, GitInfo};
2627
use crate::utils::helpers::{exe, output, t};
2728
use build_helper::exit;
28-
use once_cell::sync::OnceCell;
2929
use semver::Version;
3030
use serde::{Deserialize, Deserializer};
3131
use serde_derive::Deserialize;
@@ -1907,7 +1907,7 @@ impl Config {
19071907
}
19081908

19091909
pub(crate) fn download_rustc_commit(&self) -> Option<&str> {
1910-
static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new();
1910+
static DOWNLOAD_RUSTC: OnceLock<Option<String>> = OnceLock::new();
19111911
if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
19121912
// avoid trying to actually download the commit
19131913
return self.download_rustc_commit.as_deref();

src/bootstrap/src/core/download.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ use std::{
55
io::{BufRead, BufReader, BufWriter, ErrorKind, Write},
66
path::{Path, PathBuf},
77
process::{Command, Stdio},
8+
sync::OnceLock,
89
};
910

1011
use build_helper::ci::CiEnv;
11-
use once_cell::sync::OnceCell;
1212
use xz2::bufread::XzDecoder;
1313

1414
use crate::core::build_steps::llvm::detect_llvm_sha;
1515
use crate::core::config::RustfmtMetadata;
1616
use crate::utils::helpers::{check_run, exe, program_out_of_date};
1717
use crate::{t, Config};
1818

19-
static SHOULD_FIX_BINS_AND_DYLIBS: OnceCell<bool> = OnceCell::new();
19+
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
2020

2121
/// `Config::try_run` wrapper for this module to avoid warnings on `try_run`, since we don't have access to a `builder` yet.
2222
fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> {
@@ -131,7 +131,7 @@ impl Config {
131131
println!("attempting to patch {}", fname.display());
132132

133133
// Only build `.nix-deps` once.
134-
static NIX_DEPS_DIR: OnceCell<PathBuf> = OnceCell::new();
134+
static NIX_DEPS_DIR: OnceLock<PathBuf> = OnceLock::new();
135135
let mut nix_build_succeeded = true;
136136
let nix_deps_dir = NIX_DEPS_DIR.get_or_init(|| {
137137
// Run `nix-build` to "build" each dependency (which will likely reuse

src/bootstrap/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ use std::io;
2525
use std::path::{Path, PathBuf};
2626
use std::process::{Command, Output, Stdio};
2727
use std::str;
28+
use std::sync::OnceLock;
2829

2930
use build_helper::ci::{gha, CiEnv};
3031
use build_helper::exit;
3132
use build_helper::util::fail;
3233
use filetime::FileTime;
33-
use once_cell::sync::OnceCell;
3434
use sha2::digest::Digest;
3535
use termcolor::{ColorChoice, StandardStream, WriteColor};
3636
use utils::channel::GitInfo;
@@ -906,7 +906,7 @@ impl Build {
906906

907907
/// Returns the sysroot of the snapshot compiler.
908908
fn rustc_snapshot_sysroot(&self) -> &Path {
909-
static SYSROOT_CACHE: OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
909+
static SYSROOT_CACHE: OnceLock<PathBuf> = OnceLock::new();
910910
SYSROOT_CACHE.get_or_init(|| {
911911
let mut rustc = Command::new(&self.initial_rustc);
912912
rustc.args(&["--print", "sysroot"]);

src/bootstrap/src/utils/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use std::io;
1111
use std::path::{Path, PathBuf};
1212
use std::process::{Command, Stdio};
1313
use std::str;
14+
use std::sync::OnceLock;
1415
use std::time::{Instant, SystemTime, UNIX_EPOCH};
1516

1617
use crate::core::builder::Builder;
1718
use crate::core::config::{Config, TargetSelection};
18-
use crate::OnceCell;
1919

2020
pub use crate::utils::dylib::{dylib_path, dylib_path_var};
2121

@@ -444,7 +444,7 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
444444
}
445445

446446
pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
447-
static LLD_NO_THREADS: OnceCell<(&'static str, &'static str)> = OnceCell::new();
447+
static LLD_NO_THREADS: OnceLock<(&'static str, &'static str)> = OnceLock::new();
448448
let (windows, other) = LLD_NO_THREADS.get_or_init(|| {
449449
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
450450
let newer = match (out.find(char::is_numeric), out.find('.')) {

0 commit comments

Comments
 (0)