replace once_cell::sync::OnceCell with std OnceLock

Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
onur-ozkan 2023-12-02 12:44:23 +03:00
parent 0919ad1838
commit b7e6da80af
5 changed files with 14 additions and 15 deletions

View File

@ -10,6 +10,7 @@
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;
@ -25,12 +26,10 @@
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"]
@ -496,7 +495,7 @@ pub fn path(self, path: &str) -> Self {
///
/// [`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();

View File

@ -17,6 +17,7 @@
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;
@ -25,7 +26,6 @@
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;
@ -1907,7 +1907,7 @@ pub(crate) fn download_rustc(&self) -> bool {
}
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();

View File

@ -5,10 +5,10 @@
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;
@ -16,7 +16,7 @@
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<(), ()> {
@ -131,7 +131,7 @@ fn fix_bin_or_dylib(&self, fname: &Path) {
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

View File

@ -25,12 +25,12 @@
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;
@ -906,7 +906,7 @@ fn rustc_snapshot_libdir(&self) -> PathBuf {
/// 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"]);

View File

@ -11,11 +11,11 @@
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};
@ -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('.')) {