Skip to content

Commit 9de8d18

Browse files
authored
chore: switch once_cell crate to standard library (#2499)
1 parent 77ce75c commit 9de8d18

File tree

9 files changed

+22
-27
lines changed

9 files changed

+22
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ memmap2 = "0.9.4"
6767
mime = "0.3"
6868
number_prefix = "0.4"
6969
object = "0.37"
70-
once_cell = "1.19"
7170
opendal = { version = "0.54.0", optional = true, default-features = false }
7271
openssl = { version = "0.10.72", optional = true }
7372
rand = "0.8.4"

src/compiler/c.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use crate::util::{
3030
};
3131
use async_trait::async_trait;
3232
use fs_err as fs;
33-
use once_cell::sync::Lazy;
3433
use std::borrow::Cow;
3534
use std::collections::{HashMap, HashSet};
3635
use std::ffi::{OsStr, OsString};
@@ -40,7 +39,7 @@ use std::io;
4039
use std::ops::ControlFlow;
4140
use std::path::{Path, PathBuf};
4241
use std::process;
43-
use std::sync::Arc;
42+
use std::sync::{Arc, LazyLock};
4443

4544
use crate::errors::*;
4645

@@ -1425,7 +1424,7 @@ impl pkg::ToolchainPackager for CToolchainPackager {
14251424
pub const CACHE_VERSION: &[u8] = b"11";
14261425

14271426
/// Environment variables that are factored into the cache key.
1428-
static CACHED_ENV_VARS: Lazy<HashSet<&'static OsStr>> = Lazy::new(|| {
1427+
static CACHED_ENV_VARS: LazyLock<HashSet<&'static OsStr>> = LazyLock::new(|| {
14291428
[
14301429
// SCCACHE_C_CUSTOM_CACHE_BUSTER has no particular meaning behind it,
14311430
// serving as a way for the user to factor custom data into the hash.

src/compiler/preprocessor_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ use std::{
2424
hash::Hash,
2525
io::Write,
2626
path::{Path, PathBuf},
27+
sync::LazyLock,
2728
time::SystemTime,
2829
};
2930

3031
use anyhow::Context;
3132
use chrono::Datelike;
32-
use once_cell::sync::Lazy;
3333
use serde::{Deserialize, Serialize};
3434

3535
use crate::{
@@ -352,7 +352,7 @@ impl PreprocessorCacheEntry {
352352
}
353353

354354
/// Environment variables that are factored into the preprocessor cache entry cached key.
355-
static CACHED_ENV_VARS: Lazy<HashSet<&'static OsStr>> = Lazy::new(|| {
355+
static CACHED_ENV_VARS: LazyLock<HashSet<&'static OsStr>> = LazyLock::new(|| {
356356
[
357357
// SCCACHE_C_CUSTOM_CACHE_BUSTER has no particular meaning behind it,
358358
// serving as a way for the user to factor custom data into the hash.

src/compiler/rust.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use async_trait::async_trait;
3333
use filetime::FileTime;
3434
use fs_err as fs;
3535
use log::Level::Trace;
36-
use once_cell::sync::Lazy;
3736
#[cfg(feature = "dist-client")]
3837
use semver::Version;
3938
#[cfg(feature = "dist-client")]
@@ -56,9 +55,9 @@ use std::iter;
5655
use std::path::{Path, PathBuf};
5756
use std::pin::Pin;
5857
use std::process;
59-
use std::sync::Arc;
6058
#[cfg(feature = "dist-client")]
6159
use std::sync::Mutex;
60+
use std::sync::{Arc, LazyLock};
6261
use std::time;
6362

6463
use crate::errors::*;
@@ -232,8 +231,8 @@ pub struct CrateTypes {
232231
}
233232

234233
/// Emit types that we will cache.
235-
static ALLOWED_EMIT: Lazy<HashSet<&'static str>> =
236-
Lazy::new(|| ["link", "metadata", "dep-info"].iter().copied().collect());
234+
static ALLOWED_EMIT: LazyLock<HashSet<&'static str>> =
235+
LazyLock::new(|| ["link", "metadata", "dep-info"].iter().copied().collect());
237236

238237
/// Version number for cache key.
239238
const CACHE_VERSION: &[u8] = b"6";

src/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::cache::CacheMode;
1616
use directories::ProjectDirs;
1717
use fs::File;
1818
use fs_err as fs;
19-
use once_cell::sync::Lazy;
2019
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
2120
use serde::ser::Serializer;
2221
use serde::{
@@ -30,13 +29,13 @@ use std::io::{Read, Write};
3029
use std::path::{Path, PathBuf};
3130
use std::result::Result as StdResult;
3231
use std::str::FromStr;
33-
use std::sync::Mutex;
32+
use std::sync::{LazyLock, Mutex};
3433
use std::{collections::HashMap, fmt};
3534

3635
pub use crate::cache::PreprocessorCacheModeConfig;
3736
use crate::errors::*;
3837

39-
static CACHED_CONFIG_PATH: Lazy<PathBuf> = Lazy::new(CachedConfig::file_config_path);
38+
static CACHED_CONFIG_PATH: LazyLock<PathBuf> = LazyLock::new(CachedConfig::file_config_path);
4039
static CACHED_CONFIG: Mutex<Option<CachedFileConfig>> = Mutex::new(None);
4140

4241
const ORGANIZATION: &str = "Mozilla";

src/dist/http.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ mod server {
254254
use crate::util::{new_reqwest_blocking_client, num_cpus};
255255
use byteorder::{BigEndian, ReadBytesExt};
256256
use flate2::read::ZlibDecoder as ZlibReadDecoder;
257-
use once_cell::sync::Lazy;
258257
use rand::{RngCore, rngs::OsRng};
259258
use rouille::accept;
260259
use serde::Serialize;
@@ -263,8 +262,8 @@ mod server {
263262
use std::io::Read;
264263
use std::net::SocketAddr;
265264
use std::result::Result as StdResult;
266-
use std::sync::Mutex;
267265
use std::sync::atomic;
266+
use std::sync::{LazyLock, Mutex};
268267
use std::thread;
269268
use std::time::Duration;
270269

@@ -401,8 +400,9 @@ mod server {
401400
pub type ServerAuthCheck = Box<dyn Fn(&str) -> Option<ServerId> + Send + Sync>;
402401

403402
const JWT_KEY_LENGTH: usize = 256 / 8;
404-
static JWT_HEADER: Lazy<jwt::Header> = Lazy::new(|| jwt::Header::new(jwt::Algorithm::HS256));
405-
static JWT_VALIDATION: Lazy<jwt::Validation> = Lazy::new(|| {
403+
static JWT_HEADER: LazyLock<jwt::Header> =
404+
LazyLock::new(|| jwt::Header::new(jwt::Algorithm::HS256));
405+
static JWT_VALIDATION: LazyLock<jwt::Validation> = LazyLock::new(|| {
406406
let mut validation = jwt::Validation::new(jwt::Algorithm::HS256);
407407
validation.leeway = 0;
408408
validation.validate_exp = false;

tests/helpers/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ use assert_cmd::assert::OutputAssertExt;
55
use chrono::Local;
66
use fs_err as fs;
77
use log::trace;
8-
use once_cell::sync::Lazy;
98
use std::convert::Infallible;
109
use std::ffi::OsString;
1110
use std::io::Write;
1211
use std::path::{Path, PathBuf};
1312
use std::process::{Command, Stdio};
13+
use std::sync::LazyLock;
1414

15-
pub static CRATE_DIR: Lazy<PathBuf> =
16-
Lazy::new(|| Path::new(file!()).parent().unwrap().join("../test-crate"));
17-
pub static CARGO: Lazy<OsString> = Lazy::new(|| std::env::var_os("CARGO").unwrap());
18-
pub static SCCACHE_BIN: Lazy<&Path> = Lazy::new(|| Path::new(env!("CARGO_BIN_EXE_sccache")));
15+
pub static CRATE_DIR: LazyLock<PathBuf> =
16+
LazyLock::new(|| Path::new(file!()).parent().unwrap().join("../test-crate"));
17+
pub static CARGO: LazyLock<OsString> = LazyLock::new(|| std::env::var_os("CARGO").unwrap());
18+
pub static SCCACHE_BIN: LazyLock<&Path> =
19+
LazyLock::new(|| Path::new(env!("CARGO_BIN_EXE_sccache")));
1920

2021
/// Ensures the logger is only initialized once. Panics if initialization fails.
21-
static LOGGER: Lazy<Result<(), Infallible>> = Lazy::new(|| {
22+
static LOGGER: LazyLock<Result<(), Infallible>> = LazyLock::new(|| {
2223
env_logger::Builder::new()
2324
.format(|f, record| {
2425
writeln!(

tests/randomize_readdir/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use libc::dirent as dirent64;
4848
use libc::dirent64;
4949
use libc::{c_char, c_int, c_void, dirent, dlsym, DIR, RTLD_NEXT};
5050
use log::{error, info};
51-
use once_cell::sync::OnceCell;
5251
use rand::seq::SliceRandom;
5352
use rand::thread_rng;
5453
use simplelog::{Config, LevelFilter, WriteLogger};
@@ -57,7 +56,7 @@ use std::env;
5756
use std::ffi::CStr;
5857
use std::fs::File;
5958
use std::process;
60-
use std::sync::RwLock;
59+
use std::sync::{OnceLock, RwLock};
6160

6261
type Opendir = unsafe extern "C" fn(dirname: *const c_char) -> *mut DIR;
6362
type Fdopendir = unsafe extern "C" fn(fd: c_int) -> *mut DIR;
@@ -173,7 +172,7 @@ impl State {
173172
}
174173
}
175174

176-
static STATE: OnceCell<State> = OnceCell::new();
175+
static STATE: OnceLock<State> = OnceLock::new();
177176

178177
fn load_next<Prototype: Copy>(name: &[u8]) -> Prototype {
179178
unsafe {

0 commit comments

Comments
 (0)