Skip to content

Commit d8935d1

Browse files
chore: remove lazy_static in favor of LazyLock
1 parent a1e430c commit d8935d1

10 files changed

Lines changed: 60 additions & 74 deletions

File tree

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
@@ -14,7 +14,6 @@ path = "src/main.rs"
1414
anyhow = { workspace = true }
1515
clap = { workspace = true, features = ["env", "color"] }
1616
itertools = { workspace = true }
17-
lazy_static = "1.4.0"
1817
log = { workspace = true }
1918
rand = "0.8.5"
2019
rayon = "1.10"

src/cli/run/helpers/parse_git_remote.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use std::sync::LazyLock;
2+
13
use anyhow::{Result, anyhow};
2-
use lazy_static::lazy_static;
34

4-
lazy_static! {
5-
static ref REMOTE_REGEX: regex::Regex = regex::Regex::new(
6-
r"(?P<domain>[^/@\.]+\.\w+)[:/](?P<owner>[^/]+)/(?P<repository>[^/]+?)(\.git)?/?$"
5+
static REMOTE_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {
6+
regex::Regex::new(
7+
r"(?P<domain>[^/@\.]+\.\w+)[:/](?P<owner>[^/]+)/(?P<repository>[^/]+?)(\.git)?/?$",
78
)
8-
.unwrap();
9-
}
9+
.unwrap()
10+
});
1011

1112
#[derive(Debug)]
1213
pub struct GitRemote {

src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ pub use local_logger::clean_logger;
2020
pub use project_config::{ProjectConfig, ProjectOptions, Target, TargetOptions, WalltimeOptions};
2121
pub use runner_mode::RunnerMode;
2222

23-
use lazy_static::lazy_static;
2423
use semver::Version;
24+
use std::sync::LazyLock;
2525

2626
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
2727
pub const MONGODB_TRACER_VERSION: &str = "cs-mongo-tracer-v0.2.0";
2828

2929
pub const VALGRIND_CODSPEED_VERSION: Version = Version::new(3, 26, 0);
3030
pub const VALGRIND_CODSPEED_DEB_REVISION_SUFFIX: &str = "0codspeed0";
31-
lazy_static! {
32-
pub static ref VALGRIND_CODSPEED_VERSION_STRING: String =
33-
format!("{VALGRIND_CODSPEED_VERSION}.codspeed");
34-
pub static ref VALGRIND_CODSPEED_DEB_VERSION: String =
35-
format!("{VALGRIND_CODSPEED_VERSION}-{VALGRIND_CODSPEED_DEB_REVISION_SUFFIX}");
36-
}
31+
pub static VALGRIND_CODSPEED_VERSION_STRING: LazyLock<String> =
32+
LazyLock::new(|| format!("{VALGRIND_CODSPEED_VERSION}.codspeed"));
33+
pub static VALGRIND_CODSPEED_DEB_VERSION: LazyLock<String> = LazyLock::new(|| {
34+
format!("{VALGRIND_CODSPEED_VERSION}-{VALGRIND_CODSPEED_DEB_REVISION_SUFFIX}")
35+
});

src/local_logger/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use std::{
99
use crate::prelude::*;
1010
use console::{Style, style};
1111
use indicatif::{ProgressBar, ProgressStyle};
12-
use lazy_static::lazy_static;
1312
use log::Log;
1413
use simplelog::{CombinedLogger, SharedLogger};
1514
use std::io::Write;
15+
use std::sync::LazyLock;
1616

1717
use crate::logger::{GroupEvent, JsonEvent, get_group_event, get_json_event};
1818

@@ -24,15 +24,16 @@ pub(crate) const SPINNER_TICKS: &[&str] = &[" ", ". ", "..", " ."];
2424
/// Interval between spinner animation ticks (milliseconds)
2525
pub(crate) const TICK_INTERVAL_MS: u64 = 300;
2626

27-
lazy_static! {
28-
pub static ref SPINNER: Arc<Mutex<Option<ProgressBar>>> = Arc::new(Mutex::new(None));
29-
pub static ref IS_TTY: bool = std::io::IsTerminal::is_terminal(&std::io::stdout());
30-
static ref CURRENT_GROUP_NAME: Arc<Mutex<Option<String>>> = Arc::new(Mutex::new(None));
27+
pub static SPINNER: LazyLock<Arc<Mutex<Option<ProgressBar>>>> =
28+
LazyLock::new(|| Arc::new(Mutex::new(None)));
29+
pub static IS_TTY: LazyLock<bool> =
30+
LazyLock::new(|| std::io::IsTerminal::is_terminal(&std::io::stdout()));
31+
static CURRENT_GROUP_NAME: LazyLock<Arc<Mutex<Option<String>>>> =
32+
LazyLock::new(|| Arc::new(Mutex::new(None)));
3133

32-
/// Log records deferred while the rolling buffer owns the terminal.
33-
/// Flushed in `draw_frame` before each redraw.
34-
static ref DEFERRED_LOGS: Mutex<Vec<DeferredLog>> = Mutex::new(Vec::new());
35-
}
34+
/// Log records deferred while the rolling buffer owns the terminal.
35+
/// Flushed in `draw_frame` before each redraw.
36+
static DEFERRED_LOGS: LazyLock<Mutex<Vec<DeferredLog>>> = LazyLock::new(|| Mutex::new(Vec::new()));
3637

3738
/// A snapshot of a log record that can be stored across the rolling-buffer
3839
/// lifetime (the original `log::Record` borrows data and cannot be kept).

src/local_logger/rolling_buffer/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ use super::{
77
CODSPEED_U8_COLOR_CODE, IS_TTY, SPINNER, SPINNER_TICKS, TICK_INTERVAL_MS, format_checkmark,
88
};
99
use console::{Term, style};
10-
use lazy_static::lazy_static;
10+
use std::sync::LazyLock;
1111

1212
const INDENT: &str = " ";
1313

14-
lazy_static! {
15-
/// Global shared rolling buffer, set by `activate_rolling_buffer` and
16-
/// consumed by `log_tee` in `run_command_with_log_pipe`.
17-
pub(crate) static ref ROLLING_BUFFER: Mutex<Option<RollingBuffer>> =
18-
Mutex::new(None);
19-
}
14+
/// Global shared rolling buffer, set by `activate_rolling_buffer` and
15+
/// consumed by `log_tee` in `run_command_with_log_pipe`.
16+
pub(crate) static ROLLING_BUFFER: LazyLock<Mutex<Option<RollingBuffer>>> =
17+
LazyLock::new(|| Mutex::new(None));
2018

2119
/// Stop signal for the tick thread.
2220
///

src/request_client.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use lazy_static::lazy_static;
1+
use std::sync::LazyLock;
2+
23
use reqwest::ClientBuilder;
34
use reqwest_middleware::{ClientBuilder as ClientWithMiddlewareBuilder, ClientWithMiddleware};
45
use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff};
@@ -7,33 +8,23 @@ const UPLOAD_RETRY_COUNT: u32 = 3;
78
const OIDC_RETRY_COUNT: u32 = 10;
89
const USER_AGENT: &str = "codspeed-runner";
910

10-
lazy_static! {
11-
pub static ref REQUEST_CLIENT: ClientWithMiddleware = ClientWithMiddlewareBuilder::new(
12-
ClientBuilder::new()
13-
.user_agent(USER_AGENT)
14-
.build()
15-
.unwrap()
16-
)
17-
.with(RetryTransientMiddleware::new_with_policy(
18-
ExponentialBackoff::builder().build_with_max_retries(UPLOAD_RETRY_COUNT)
19-
))
20-
.build();
21-
22-
// Client without retry middleware for streaming uploads (can't be cloned)
23-
pub static ref STREAMING_CLIENT: reqwest::Client = ClientBuilder::new()
24-
.user_agent(USER_AGENT)
11+
pub static REQUEST_CLIENT: LazyLock<ClientWithMiddleware> = LazyLock::new(|| {
12+
ClientWithMiddlewareBuilder::new(ClientBuilder::new().user_agent(USER_AGENT).build().unwrap())
13+
.with(RetryTransientMiddleware::new_with_policy(
14+
ExponentialBackoff::builder().build_with_max_retries(UPLOAD_RETRY_COUNT),
15+
))
2516
.build()
26-
.unwrap();
17+
});
2718

28-
// Client with retry middleware for OIDC token requests
29-
pub static ref OIDC_CLIENT: ClientWithMiddleware = ClientWithMiddlewareBuilder::new(
30-
ClientBuilder::new()
31-
.user_agent(USER_AGENT)
32-
.build()
33-
.unwrap()
34-
)
35-
.with(RetryTransientMiddleware::new_with_policy(
36-
ExponentialBackoff::builder().build_with_max_retries(OIDC_RETRY_COUNT)
37-
))
38-
.build();
39-
}
19+
/// Client without retry middleware for streaming uploads (can't be cloned)
20+
pub static STREAMING_CLIENT: LazyLock<reqwest::Client> =
21+
LazyLock::new(|| ClientBuilder::new().user_agent(USER_AGENT).build().unwrap());
22+
23+
/// Client with retry middleware for OIDC token requests
24+
pub static OIDC_CLIENT: LazyLock<ClientWithMiddleware> = LazyLock::new(|| {
25+
ClientWithMiddlewareBuilder::new(ClientBuilder::new().user_agent(USER_AGENT).build().unwrap())
26+
.with(RetryTransientMiddleware::new_with_policy(
27+
ExponentialBackoff::builder().build_with_max_retries(OIDC_RETRY_COUNT),
28+
))
29+
.build()
30+
});

src/run_environment/github_actions/provider.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use std::sync::LazyLock;
2+
13
use async_trait::async_trait;
24
use git2::Repository;
3-
use lazy_static::lazy_static;
45
use regex::Regex;
56
use serde::Deserialize;
67
use serde_json::Value;
@@ -63,9 +64,8 @@ struct OIDCResponse {
6364
value: Option<String>,
6465
}
6566

66-
lazy_static! {
67-
static ref PR_REF_REGEX: Regex = Regex::new(r"^refs/pull/(?P<pr_number>\d+)/merge$").unwrap();
68-
}
67+
static PR_REF_REGEX: LazyLock<Regex> =
68+
LazyLock::new(|| Regex::new(r"^refs/pull/(?P<pr_number>\d+)/merge$").unwrap());
6969

7070
impl TryFrom<&OrchestratorConfig> for GitHubActionsProvider {
7171
type Error = Error;

src/run_environment/gitlab_ci/logger.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use std::sync::LazyLock;
2+
13
use console::style;
2-
use lazy_static::lazy_static;
34
use log::{Level, LevelFilter, Log};
45
use regex::Regex;
56
use simplelog::SharedLogger;
@@ -15,10 +16,8 @@ use crate::{
1516
run_environment::logger::should_provider_logger_handle_record,
1617
};
1718

18-
lazy_static! {
19-
static ref GITLAB_SECTION_ID_SANITIZE_REGEX: Regex =
20-
Regex::new(r"[^\d\w\-_]").expect("Failed to compile GitLab SectionId regex");
21-
}
19+
static GITLAB_SECTION_ID_SANITIZE_REGEX: LazyLock<Regex> =
20+
LazyLock::new(|| Regex::new(r"[^\d\w\-_]").expect("Failed to compile GitLab SectionId regex"));
2221

2322
/// Unicode Escape character
2423
///

src/system/check.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use lazy_static::lazy_static;
21
use std::collections::HashSet;
2+
use std::sync::LazyLock;
33

44
use crate::prelude::*;
55

66
use super::SystemInfo;
77

8-
lazy_static! {
9-
static ref SUPPORTED_SYSTEMS: HashSet<(&'static str, &'static str, &'static str)> = {
8+
static SUPPORTED_SYSTEMS: LazyLock<HashSet<(&'static str, &'static str, &'static str)>> =
9+
LazyLock::new(|| {
1010
HashSet::from([
1111
("ubuntu", "22.04", "x86_64"),
1212
("ubuntu", "24.04", "x86_64"),
@@ -15,8 +15,7 @@ lazy_static! {
1515
("debian", "12", "x86_64"),
1616
("debian", "12", "aarch64"),
1717
])
18-
};
19-
}
18+
});
2019

2120
/// Checks if the provided system info is supported
2221
///

0 commit comments

Comments
 (0)