Skip to content

Commit

Permalink
Rollup merge of #118528 - onur-ozkan:use-std-once-lock, r=clubby789
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthiaskrgr committed Dec 2, 2023
2 parents b384767 + b7e6da8 commit 99aaded
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::io::{BufRead, BufReader};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::OnceLock;
use std::time::{Duration, Instant};

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

pub use crate::Compiler;
// FIXME:
// - use std::lazy for `Lazy`
// - use std::cell for `OnceCell`
// Once they get stabilized and reach beta.

use clap::ValueEnum;
use once_cell::sync::{Lazy, OnceCell};
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
use once_cell::sync::Lazy;

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

let init_submodules_paths = |src: &PathBuf| {
let file = File::open(src.join(".gitmodules")).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::io::IsTerminal;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use std::sync::OnceLock;

use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
use crate::core::build_steps::llvm;
Expand All @@ -25,7 +26,6 @@ use crate::utils::cache::{Interned, INTERNER};
use crate::utils::channel::{self, GitInfo};
use crate::utils::helpers::{exe, output, t};
use build_helper::exit;
use once_cell::sync::OnceCell;
use semver::Version;
use serde::{Deserialize, Deserializer};
use serde_derive::Deserialize;
Expand Down Expand Up @@ -1907,7 +1907,7 @@ impl Config {
}

pub(crate) fn download_rustc_commit(&self) -> Option<&str> {
static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new();
static DOWNLOAD_RUSTC: OnceLock<Option<String>> = OnceLock::new();
if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
// avoid trying to actually download the commit
return self.download_rustc_commit.as_deref();
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use std::{
io::{BufRead, BufReader, BufWriter, ErrorKind, Write},
path::{Path, PathBuf},
process::{Command, Stdio},
sync::OnceLock,
};

use build_helper::ci::CiEnv;
use once_cell::sync::OnceCell;
use xz2::bufread::XzDecoder;

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

static SHOULD_FIX_BINS_AND_DYLIBS: OnceCell<bool> = OnceCell::new();
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();

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

// Only build `.nix-deps` once.
static NIX_DEPS_DIR: OnceCell<PathBuf> = OnceCell::new();
static NIX_DEPS_DIR: OnceLock<PathBuf> = OnceLock::new();
let mut nix_build_succeeded = true;
let nix_deps_dir = NIX_DEPS_DIR.get_or_init(|| {
// Run `nix-build` to "build" each dependency (which will likely reuse
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Output, Stdio};
use std::str;
use std::sync::OnceLock;

use build_helper::ci::{gha, CiEnv};
use build_helper::exit;
use build_helper::util::fail;
use filetime::FileTime;
use once_cell::sync::OnceCell;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;
Expand Down Expand Up @@ -906,7 +906,7 @@ impl Build {

/// Returns the sysroot of the snapshot compiler.
fn rustc_snapshot_sysroot(&self) -> &Path {
static SYSROOT_CACHE: OnceCell<PathBuf> = once_cell::sync::OnceCell::new();
static SYSROOT_CACHE: OnceLock<PathBuf> = OnceLock::new();
SYSROOT_CACHE.get_or_init(|| {
let mut rustc = Command::new(&self.initial_rustc);
rustc.args(&["--print", "sysroot"]);
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str;
use std::sync::OnceLock;
use std::time::{Instant, SystemTime, UNIX_EPOCH};

use crate::core::builder::Builder;
use crate::core::config::{Config, TargetSelection};
use crate::OnceCell;

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

Expand Down Expand Up @@ -444,7 +444,7 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
}

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

0 comments on commit 99aaded

Please sign in to comment.