diff --git a/Cargo.lock b/Cargo.lock index 8ef15e938e5..97f616c7000 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,7 +412,6 @@ dependencies = [ "git2", "glob", "itertools", - "lazy_static", "pasetors", "serde", "serde_json", @@ -2731,7 +2730,6 @@ version = "0.0.0" dependencies = [ "cargo", "cargo-util", - "lazy_static", "proptest", "varisat", ] diff --git a/Cargo.toml b/Cargo.toml index 427b16669e6..c2da6e4c179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,6 @@ im-rc = "15.1.0" indexmap = "2" itertools = "0.10.0" jobserver = "0.1.26" -lazy_static = "1.4.0" lazycell = "1.3.0" libc = "0.2.147" libgit2-sys = "0.16.1" diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index 31cf2725de5..cfcf139de21 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -19,7 +19,6 @@ flate2.workspace = true git2.workspace = true glob.workspace = true itertools.workspace = true -lazy_static.workspace = true pasetors.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index a2fa54c601d..57dca45ce03 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -12,6 +12,7 @@ use std::os; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; use std::str; +use std::sync::OnceLock; use std::time::{self, Duration}; use anyhow::{bail, Result}; @@ -1157,13 +1158,14 @@ impl RustcInfo { } } -lazy_static::lazy_static! { - static ref RUSTC_INFO: RustcInfo = RustcInfo::new(); +fn rustc_info() -> &'static RustcInfo { + static RUSTC_INFO: OnceLock = OnceLock::new(); + RUSTC_INFO.get_or_init(RustcInfo::new) } /// The rustc host such as `x86_64-unknown-linux-gnu`. pub fn rustc_host() -> &'static str { - &RUSTC_INFO.host + &rustc_info().host } /// The host triple suitable for use in a cargo environment variable (uppercased). @@ -1172,7 +1174,7 @@ pub fn rustc_host_env() -> String { } pub fn is_nightly() -> bool { - let vv = &RUSTC_INFO.verbose_version; + let vv = &rustc_info().verbose_version; // CARGO_TEST_DISABLE_NIGHTLY is set in rust-lang/rust's CI so that all // nightly-only tests are disabled there. Otherwise, it could make it // difficult to land changes which would need to be made simultaneously in @@ -1225,28 +1227,27 @@ pub trait TestEnv: Sized { if env::var_os("RUSTUP_TOOLCHAIN").is_some() { // Override the PATH to avoid executing the rustup wrapper thousands // of times. This makes the testsuite run substantially faster. - lazy_static::lazy_static! { - static ref RUSTC_DIR: PathBuf = { - match ProcessBuilder::new("rustup") - .args(&["which", "rustc"]) - .exec_with_output() - { - Ok(output) => { - let s = str::from_utf8(&output.stdout).expect("utf8").trim(); - let mut p = PathBuf::from(s); - p.pop(); - p - } - Err(e) => { - panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e); - } + static RUSTC_DIR: OnceLock = OnceLock::new(); + let rustc_dir = RUSTC_DIR.get_or_init(|| { + match ProcessBuilder::new("rustup") + .args(&["which", "rustc"]) + .exec_with_output() + { + Ok(output) => { + let s = str::from_utf8(&output.stdout).expect("utf8").trim(); + let mut p = PathBuf::from(s); + p.pop(); + p } - }; - } + Err(e) => { + panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e); + } + } + }); let path = env::var_os("PATH").unwrap_or_default(); let paths = env::split_paths(&path); let new_path = - env::join_paths(std::iter::once(RUSTC_DIR.clone()).chain(paths)).unwrap(); + env::join_paths(std::iter::once(rustc_dir.clone()).chain(paths)).unwrap(); self = self.env("PATH", new_path); } @@ -1408,11 +1409,14 @@ pub fn is_coarse_mtime() -> bool { /// Architectures that do not have a modern processor, hardware emulation, etc. /// This provides a way for those setups to increase the cut off for all the time based test. pub fn slow_cpu_multiplier(main: u64) -> Duration { - lazy_static::lazy_static! { - static ref SLOW_CPU_MULTIPLIER: u64 = - env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER").ok().and_then(|m| m.parse().ok()).unwrap_or(1); - } - Duration::from_secs(*SLOW_CPU_MULTIPLIER * main) + static SLOW_CPU_MULTIPLIER: OnceLock = OnceLock::new(); + let slow_cpu_multiplier = SLOW_CPU_MULTIPLIER.get_or_init(|| { + env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER") + .ok() + .and_then(|m| m.parse().ok()) + .unwrap_or(1) + }); + Duration::from_secs(slow_cpu_multiplier * main) } #[cfg(windows)] diff --git a/crates/resolver-tests/Cargo.toml b/crates/resolver-tests/Cargo.toml index 033da4195ed..8750a3d972f 100644 --- a/crates/resolver-tests/Cargo.toml +++ b/crates/resolver-tests/Cargo.toml @@ -8,6 +8,5 @@ publish = false [dependencies] cargo.workspace = true cargo-util.workspace = true -lazy_static.workspace = true proptest.workspace = true varisat.workspace = true diff --git a/crates/resolver-tests/src/lib.rs b/crates/resolver-tests/src/lib.rs index cf56c376471..baab24371cb 100644 --- a/crates/resolver-tests/src/lib.rs +++ b/crates/resolver-tests/src/lib.rs @@ -7,6 +7,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::fmt; use std::fmt::Write; use std::rc::Rc; +use std::sync::OnceLock; use std::task::Poll; use std::time::Instant; @@ -563,11 +564,11 @@ macro_rules! pkg { } fn registry_loc() -> SourceId { - lazy_static::lazy_static! { - static ref EXAMPLE_DOT_COM: SourceId = - SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap(); - } - *EXAMPLE_DOT_COM + static EXAMPLE_DOT_COM: OnceLock = OnceLock::new(); + let example_dot = EXAMPLE_DOT_COM.get_or_init(|| { + SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap() + }); + *example_dot } pub fn pkg(name: T) -> Summary {