diff --git a/Cargo.lock b/Cargo.lock index 3e9369861..d0751d1ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -394,7 +394,6 @@ dependencies = [ "humansize", "inquire", "jobserver", - "lazy_static", "libc", "log", "miow", @@ -582,7 +581,6 @@ dependencies = [ "futures-util", "hashbrown", "intern", - "lazy_static", "log", "native-tls", "postgres-native-tls", @@ -1395,7 +1393,6 @@ dependencies = [ "arc-swap", "bumpalo", "hashbrown", - "lazy_static", "parking_lot", "serde", ] @@ -2598,7 +2595,6 @@ dependencies = [ "itertools", "jemalloc-ctl", "jemallocator", - "lazy_static", "log", "lru", "mime", diff --git a/Cargo.toml b/Cargo.toml index 83903e6be..327c45d9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ chrono = "0.4" clap = "4.1" env_logger = "0.10" hashbrown = "0.14" -lazy_static = "1" log = "0.4" reqwest = "0.11" serde = "1" diff --git a/collector/Cargo.toml b/collector/Cargo.toml index efb87fd0f..94bc667dd 100644 --- a/collector/Cargo.toml +++ b/collector/Cargo.toml @@ -11,7 +11,6 @@ anyhow = { workspace = true } chrono = { workspace = true, features = ["serde"] } clap = { workspace = true, features = ["derive"] } env_logger = { workspace = true } -lazy_static = { workspace = true } log = { workspace = true } reqwest = { workspace = true, features = ["blocking", "json"] } serde = { workspace = true, features = ["derive"] } diff --git a/collector/src/compile/execute/mod.rs b/collector/src/compile/execute/mod.rs index 37df1919c..144c508c0 100644 --- a/collector/src/compile/execute/mod.rs +++ b/collector/src/compile/execute/mod.rs @@ -20,6 +20,7 @@ use std::path::{Path, PathBuf}; use std::pin::Pin; use std::process::{self, Command}; use std::str; +use std::sync::LazyLock; pub mod bencher; mod etw_parser; @@ -366,44 +367,42 @@ impl<'a> CargoProcess<'a> { } } -lazy_static::lazy_static! { - static ref FAKE_RUSTC: PathBuf = { - let mut fake_rustc = env::current_exe().unwrap(); - fake_rustc.pop(); - fake_rustc.push("rustc-fake"); - fake_rustc - }; - static ref FAKE_RUSTDOC: PathBuf = { - let mut fake_rustdoc = env::current_exe().unwrap(); - fake_rustdoc.pop(); - fake_rustdoc.push("rustdoc-fake"); - // link from rustc-fake to rustdoc-fake - if !fake_rustdoc.exists() { - #[cfg(unix)] - use std::os::unix::fs::symlink; - #[cfg(windows)] - use std::os::windows::fs::symlink_file as symlink; - - symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link"); - } - fake_rustdoc - }; - static ref FAKE_CLIPPY: PathBuf = { - let mut fake_clippy = env::current_exe().unwrap(); - fake_clippy.pop(); - fake_clippy.push("clippy-fake"); - // link from rustc-fake to rustdoc-fake - if !fake_clippy.exists() { - #[cfg(unix)] - use std::os::unix::fs::symlink; - #[cfg(windows)] - use std::os::windows::fs::symlink_file as symlink; - - symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link"); - } - fake_clippy - }; -} +static FAKE_RUSTC: LazyLock = LazyLock::new(|| { + let mut fake_rustc = env::current_exe().unwrap(); + fake_rustc.pop(); + fake_rustc.push("rustc-fake"); + fake_rustc +}); +static FAKE_RUSTDOC: LazyLock = LazyLock::new(|| { + let mut fake_rustdoc = env::current_exe().unwrap(); + fake_rustdoc.pop(); + fake_rustdoc.push("rustdoc-fake"); + // link from rustc-fake to rustdoc-fake + if !fake_rustdoc.exists() { + #[cfg(unix)] + use std::os::unix::fs::symlink; + #[cfg(windows)] + use std::os::windows::fs::symlink_file as symlink; + + symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link"); + } + fake_rustdoc +}); +static FAKE_CLIPPY: LazyLock = LazyLock::new(|| { + let mut fake_clippy = env::current_exe().unwrap(); + fake_clippy.pop(); + fake_clippy.push("clippy-fake"); + // link from rustc-fake to rustdoc-fake + if !fake_clippy.exists() { + #[cfg(unix)] + use std::os::unix::fs::symlink; + #[cfg(windows)] + use std::os::windows::fs::symlink_file as symlink; + + symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link"); + } + fake_clippy +}); /// Used to indicate if we need to retry a run. pub enum Retry { diff --git a/database/Cargo.toml b/database/Cargo.toml index 6ce1f3e94..7220aee1f 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -10,7 +10,6 @@ chrono = { workspace = true, features = ["serde"] } clap = { workspace = true, features = ["cargo"] } env_logger = { workspace = true } hashbrown = { workspace = true, features = ["serde"] } -lazy_static = { workspace = true } log = { workspace = true } reqwest = { workspace = true } serde = { workspace = true, features = ["derive"] } diff --git a/intern/Cargo.toml b/intern/Cargo.toml index 063393bb7..115117b36 100644 --- a/intern/Cargo.toml +++ b/intern/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] hashbrown = { workspace = true } -lazy_static = { workspace = true } serde = { workspace = true, features = ["derive"] } bumpalo = "3.2" diff --git a/intern/src/lib.rs b/intern/src/lib.rs index 67d1d01f2..ebde3d142 100644 --- a/intern/src/lib.rs +++ b/intern/src/lib.rs @@ -8,7 +8,7 @@ use std::alloc::Layout; use std::fmt; use std::ptr; use std::ptr::NonNull; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; #[allow(clippy::missing_safety_doc)] pub trait InternString { @@ -132,10 +132,13 @@ macro_rules! intern { }; } -lazy_static::lazy_static! { - static ref INTERNED: (ArcSwap>, Mutex<(HashSet, Bump)>) - = (ArcSwap::new(Arc::new(HashSet::new())), Mutex::new((HashSet::new(), Bump::new()))); -} +static INTERNED: LazyLock<(ArcSwap>, Mutex<(HashSet, Bump)>)> = + LazyLock::new(|| { + ( + ArcSwap::new(Arc::new(HashSet::new())), + Mutex::new((HashSet::new(), Bump::new())), + ) + }); pub fn preloaded(value: &str) -> Option { let set = INTERNED.0.load(); diff --git a/site/Cargo.toml b/site/Cargo.toml index a11f90246..da056d219 100644 --- a/site/Cargo.toml +++ b/site/Cargo.toml @@ -1,5 +1,9 @@ [package] -authors = ["Mark-Simulacrum ", "Nicholas Cameron ", "The rustc-perf contributors"] +authors = [ + "Mark-Simulacrum ", + "Nicholas Cameron ", + "The rustc-perf contributors", +] name = "site" version = "0.1.0" edition = "2021" @@ -9,7 +13,6 @@ anyhow = { workspace = true } chrono = { workspace = true } env_logger = { workspace = true } hashbrown = { workspace = true, features = ["serde"] } -lazy_static = { workspace = true } log = { workspace = true } reqwest = { workspace = true, features = ["blocking", "json"] } serde = { workspace = true, features = ["rc"] } @@ -41,7 +44,10 @@ mime = "0.3" prometheus = { version = "0.13", default-features = false } uuid = { version = "1.3.0", features = ["v4"] } tera = { version = "1.19", default-features = false } -rust-embed = { version = "6.6.0", features = ["include-exclude", "interpolate-folder-path"] } +rust-embed = { version = "6.6.0", features = [ + "include-exclude", + "interpolate-folder-path", +] } humansize = "2" lru = "0.12.0" ruzstd = "0.7.0" diff --git a/site/src/benchmark_metadata/mod.rs b/site/src/benchmark_metadata/mod.rs index a2303216b..2eaa94101 100644 --- a/site/src/benchmark_metadata/mod.rs +++ b/site/src/benchmark_metadata/mod.rs @@ -1,3 +1,5 @@ +use std::sync::LazyLock; + use hashbrown::HashMap; use rust_embed::RustEmbed; @@ -23,9 +25,8 @@ pub struct CompileBenchmarkMetadata { struct EmbeddedCompileBenchmarks; pub fn get_compile_benchmarks_metadata() -> &'static HashMap { - lazy_static::lazy_static! { - static ref METADATA: HashMap = load_compile_benchmark_metadata(); - } + static METADATA: LazyLock> = + LazyLock::new(load_compile_benchmark_metadata); &METADATA } diff --git a/site/src/github.rs b/site/src/github.rs index 1f56f9e8a..32ae35b75 100644 --- a/site/src/github.rs +++ b/site/src/github.rs @@ -3,6 +3,7 @@ pub mod comparison_summary; use crate::api::github::Commit; use crate::load::{MissingReason, SiteCtxt, TryCommit}; +use std::sync::LazyLock; use std::time::Duration; use serde::Deserialize; @@ -195,12 +196,10 @@ pub struct UnrolledCommit<'a> { pub sha: Option, } -lazy_static::lazy_static! { - static ref ROLLUP_PR_NUMBER: regex::Regex = - regex::Regex::new(r"^Auto merge of #(\d+)").unwrap(); - static ref ROLLEDUP_PR_NUMBER: regex::Regex = - regex::Regex::new(r"^Rollup merge of #(\d+)").unwrap(); -} +static ROLLUP_PR_NUMBER: LazyLock = + LazyLock::new(|| regex::Regex::new(r"^Auto merge of #(\d+)").unwrap()); +static ROLLEDUP_PR_NUMBER: LazyLock = + LazyLock::new(|| regex::Regex::new(r"^Rollup merge of #(\d+)").unwrap()); // Gets the pr number for the associated rollup PR message. Returns None if this is not a rollup PR pub async fn rollup_pr_number( diff --git a/site/src/load.rs b/site/src/load.rs index 1d1b8712e..82c5b4dae 100644 --- a/site/src/load.rs +++ b/site/src/load.rs @@ -1,12 +1,11 @@ use std::collections::{HashMap, HashSet}; use std::fs; use std::ops::RangeInclusive; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::Instant; use arc_swap::{ArcSwap, Guard}; use chrono::{Duration, Utc}; -use lazy_static::lazy_static; use log::error; use parking_lot::Mutex; use regex::Regex; @@ -218,10 +217,6 @@ impl SiteCtxt { .text() .await?; - lazy_static! { - static ref VERSION_REGEX: Regex = Regex::new(r"(\d+\.\d+.\d+)").unwrap(); - } - let conn = self.conn().await; let index = self.index.load(); @@ -292,9 +287,8 @@ impl SiteCtxt { /// Parses an artifact tag like `1.63.0` or `beta-2022-08-19` from a line taken from /// `https://static.rust-lang.org/manifests.txt`. fn parse_published_artifact_tag(line: &str) -> Option { - lazy_static! { - static ref VERSION_REGEX: Regex = Regex::new(r"(\d+\.\d+.\d+)").unwrap(); - } + static VERSION_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"(\d+\.\d+.\d+)").unwrap()); let mut parts = line.rsplit('/'); let name = parts.next(); diff --git a/site/src/request_handlers/dashboard.rs b/site/src/request_handlers/dashboard.rs index e70f311f7..8ed8c8cd5 100644 --- a/site/src/request_handlers/dashboard.rs +++ b/site/src/request_handlers/dashboard.rs @@ -1,6 +1,4 @@ -use std::sync::Arc; - -use lazy_static::lazy_static; +use std::sync::{Arc, LazyLock}; use crate::api::{dashboard, ServerResult}; use crate::benchmark_metadata::get_stable_benchmark_names; @@ -77,9 +75,7 @@ pub async fn handle_dashboard(ctxt: Arc) -> ServerResult>(), ); - lazy_static! { - static ref STABLE_BENCHMARKS: Vec = get_stable_benchmark_names(); - } + static STABLE_BENCHMARKS: LazyLock> = LazyLock::new(get_stable_benchmark_names); let compile_benchmark_query = selector::CompileBenchmarkQuery::default() .benchmark(selector::Selector::Subset(STABLE_BENCHMARKS.clone())) diff --git a/site/src/server.rs b/site/src/server.rs index 317ffdb7f..0a29b0ba2 100644 --- a/site/src/server.rs +++ b/site/src/server.rs @@ -5,7 +5,7 @@ use std::net::SocketAddr; use std::path::Path; use std::str::FromStr; use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use std::time::Instant; use std::{fmt, str}; @@ -257,9 +257,7 @@ impl Server { } async fn handle_push(&self, _req: Request) -> Response { - lazy_static::lazy_static! { - static ref LAST_UPDATE: Mutex> = Mutex::new(None); - } + static LAST_UPDATE: LazyLock>> = LazyLock::new(|| Mutex::new(None)); let last = *LAST_UPDATE.lock(); if let Some(last) = last { @@ -603,10 +601,9 @@ where } } -lazy_static::lazy_static! { - static ref VERSION_UUID: Uuid = Uuid::new_v4(); // random UUID used as ETag for cache revalidation - static ref TEMPLATES: ResourceResolver = ResourceResolver::new().expect("Cannot load resources"); -} +static VERSION_UUID: LazyLock = LazyLock::new(Uuid::new_v4); // random UUID used as ETag for cache revalidation +static TEMPLATES: LazyLock = + LazyLock::new(|| ResourceResolver::new().expect("Cannot load resources")); /// Handle the case where the path is to a static file async fn handle_fs_path(