mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #12616 - Eh2406:lazy_static, r=epage
stop using lazy_static ### What does this PR try to resolve? Remove the dependency on `lazy_static` and replace with `std::sync::OnceLock`. ### How should we test and review this PR? This was an internal re-factor, and the tests still pass. I did not test that the intended caching was still working.
This commit is contained in:
commit
71dafcaaa7
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -412,7 +412,6 @@ dependencies = [
|
|||||||
"git2",
|
"git2",
|
||||||
"glob",
|
"glob",
|
||||||
"itertools",
|
"itertools",
|
||||||
"lazy_static",
|
|
||||||
"pasetors",
|
"pasetors",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -2731,7 +2730,6 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo",
|
"cargo",
|
||||||
"cargo-util",
|
"cargo-util",
|
||||||
"lazy_static",
|
|
||||||
"proptest",
|
"proptest",
|
||||||
"varisat",
|
"varisat",
|
||||||
]
|
]
|
||||||
|
@ -54,7 +54,6 @@ im-rc = "15.1.0"
|
|||||||
indexmap = "2"
|
indexmap = "2"
|
||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
jobserver = "0.1.26"
|
jobserver = "0.1.26"
|
||||||
lazy_static = "1.4.0"
|
|
||||||
lazycell = "1.3.0"
|
lazycell = "1.3.0"
|
||||||
libc = "0.2.147"
|
libc = "0.2.147"
|
||||||
libgit2-sys = "0.16.1"
|
libgit2-sys = "0.16.1"
|
||||||
|
@ -19,7 +19,6 @@ flate2.workspace = true
|
|||||||
git2.workspace = true
|
git2.workspace = true
|
||||||
glob.workspace = true
|
glob.workspace = true
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
pasetors.workspace = true
|
pasetors.workspace = true
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
@ -12,6 +12,7 @@ use std::os;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::sync::OnceLock;
|
||||||
use std::time::{self, Duration};
|
use std::time::{self, Duration};
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
@ -1157,13 +1158,14 @@ impl RustcInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
fn rustc_info() -> &'static RustcInfo {
|
||||||
static ref RUSTC_INFO: RustcInfo = RustcInfo::new();
|
static RUSTC_INFO: OnceLock<RustcInfo> = OnceLock::new();
|
||||||
|
RUSTC_INFO.get_or_init(RustcInfo::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rustc host such as `x86_64-unknown-linux-gnu`.
|
/// The rustc host such as `x86_64-unknown-linux-gnu`.
|
||||||
pub fn rustc_host() -> &'static str {
|
pub fn rustc_host() -> &'static str {
|
||||||
&RUSTC_INFO.host
|
&rustc_info().host
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The host triple suitable for use in a cargo environment variable (uppercased).
|
/// 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 {
|
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
|
// 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
|
// nightly-only tests are disabled there. Otherwise, it could make it
|
||||||
// difficult to land changes which would need to be made simultaneously in
|
// 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() {
|
if env::var_os("RUSTUP_TOOLCHAIN").is_some() {
|
||||||
// Override the PATH to avoid executing the rustup wrapper thousands
|
// Override the PATH to avoid executing the rustup wrapper thousands
|
||||||
// of times. This makes the testsuite run substantially faster.
|
// of times. This makes the testsuite run substantially faster.
|
||||||
lazy_static::lazy_static! {
|
static RUSTC_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||||
static ref RUSTC_DIR: PathBuf = {
|
let rustc_dir = RUSTC_DIR.get_or_init(|| {
|
||||||
match ProcessBuilder::new("rustup")
|
match ProcessBuilder::new("rustup")
|
||||||
.args(&["which", "rustc"])
|
.args(&["which", "rustc"])
|
||||||
.exec_with_output()
|
.exec_with_output()
|
||||||
{
|
{
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
let s = str::from_utf8(&output.stdout).expect("utf8").trim();
|
let s = str::from_utf8(&output.stdout).expect("utf8").trim();
|
||||||
let mut p = PathBuf::from(s);
|
let mut p = PathBuf::from(s);
|
||||||
p.pop();
|
p.pop();
|
||||||
p
|
p
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
Err(e) => {
|
||||||
}
|
panic!("RUSTUP_TOOLCHAIN was set, but could not run rustup: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
let path = env::var_os("PATH").unwrap_or_default();
|
let path = env::var_os("PATH").unwrap_or_default();
|
||||||
let paths = env::split_paths(&path);
|
let paths = env::split_paths(&path);
|
||||||
let new_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);
|
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.
|
/// 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.
|
/// 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 {
|
pub fn slow_cpu_multiplier(main: u64) -> Duration {
|
||||||
lazy_static::lazy_static! {
|
static SLOW_CPU_MULTIPLIER: OnceLock<u64> = OnceLock::new();
|
||||||
static ref SLOW_CPU_MULTIPLIER: u64 =
|
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);
|
env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER")
|
||||||
}
|
.ok()
|
||||||
Duration::from_secs(*SLOW_CPU_MULTIPLIER * main)
|
.and_then(|m| m.parse().ok())
|
||||||
|
.unwrap_or(1)
|
||||||
|
});
|
||||||
|
Duration::from_secs(slow_cpu_multiplier * main)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -8,6 +8,5 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cargo.workspace = true
|
cargo.workspace = true
|
||||||
cargo-util.workspace = true
|
cargo-util.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
proptest.workspace = true
|
proptest.workspace = true
|
||||||
varisat.workspace = true
|
varisat.workspace = true
|
||||||
|
@ -7,6 +7,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::OnceLock;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@ -563,11 +564,11 @@ macro_rules! pkg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn registry_loc() -> SourceId {
|
fn registry_loc() -> SourceId {
|
||||||
lazy_static::lazy_static! {
|
static EXAMPLE_DOT_COM: OnceLock<SourceId> = OnceLock::new();
|
||||||
static ref EXAMPLE_DOT_COM: SourceId =
|
let example_dot = EXAMPLE_DOT_COM.get_or_init(|| {
|
||||||
SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap();
|
SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap()
|
||||||
}
|
});
|
||||||
*EXAMPLE_DOT_COM
|
*example_dot
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pkg<T: ToPkgId>(name: T) -> Summary {
|
pub fn pkg<T: ToPkgId>(name: T) -> Summary {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user