Skip to content

Commit 92e142c

Browse files
committed
get rid of lazy_static and use oncelock instead
1 parent a2b6b08 commit 92e142c

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
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
@@ -29,7 +29,6 @@ cc = "1.2.25"
2929

3030
[dev-dependencies]
3131
cc = "1.2.25"
32-
lazy_static = "1.5.0"
3332
rstest = { version = "0.25.0", default-features = false }
3433
tempfile = "3.20.0"
3534

tests/tests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::env;
22
use std::path::{Path, PathBuf};
33
use std::process::Command;
44

5-
use lazy_static::lazy_static;
65
use rstest::*;
6+
use std::sync::OnceLock;
77
use tempfile::TempDir;
88

99
#[fixture]
@@ -13,7 +13,7 @@ fn libtest() -> &'static str {
1313

1414
eprintln!("Building libtest");
1515
compile_test_lib("test");
16-
TMPDIR.path().to_str().unwrap()
16+
get_tmpdir().path().to_str().unwrap()
1717
}
1818

1919
#[fixture]
@@ -120,8 +120,10 @@ fn test_ld_path_restore(libtest: &str, _dt_needed_bin: &Path) {
120120
const EXE: &str = env!("CARGO_BIN_EXE_nix-ld");
121121
const TARGET: &str = env!("NIX_LD_TEST_TARGET");
122122

123-
lazy_static! {
124-
static ref TMPDIR: TempDir = tempfile::tempdir().expect("Failed to create temporary directory");
123+
static TMPDIR: OnceLock<TempDir> = OnceLock::new();
124+
125+
fn get_tmpdir() -> &'static TempDir {
126+
TMPDIR.get_or_init(|| tempfile::tempdir().expect("Failed to create temporary directory"))
125127
}
126128

127129
fn find_cc() -> String {
@@ -141,7 +143,7 @@ fn get_source_file(file: &str) -> PathBuf {
141143
fn compile_test_lib(name: &str) {
142144
let cc = find_cc();
143145
let source_path = get_source_file(&format!("tests/lib{}.c", name));
144-
let out_path = TMPDIR.path().join(format!("lib{}.so", name));
146+
let out_path = get_tmpdir().path().join(format!("lib{}.so", name));
145147

146148
let status = Command::new(cc)
147149
.arg("-fPIC")
@@ -158,9 +160,9 @@ fn compile_test_lib(name: &str) {
158160
fn compile_test_bin(name: &str, libs: &[&str]) -> PathBuf {
159161
let cc = find_cc();
160162
let source_path = get_source_file(&format!("tests/{}.c", name));
161-
let out_path = TMPDIR.path().join(name);
163+
let out_path = get_tmpdir().path().join(name);
162164

163-
let out_dir_arg = format!("-DOUT_DIR=\"{}\"", TMPDIR.path().to_str().unwrap());
165+
let out_dir_arg = format!("-DOUT_DIR=\"{}\"", get_tmpdir().path().to_str().unwrap());
164166
let dynamic_linker_arg = format!("-Wl,--dynamic-linker,{}", EXE);
165167

166168
let status = Command::new(cc)
@@ -169,7 +171,7 @@ fn compile_test_bin(name: &str, libs: &[&str]) -> PathBuf {
169171
.arg(out_dir_arg)
170172
.arg(dynamic_linker_arg)
171173
.arg("-L")
172-
.arg(TMPDIR.path())
174+
.arg(get_tmpdir().path())
173175
.args(libs.iter().map(|l| format!("-l{}", l)))
174176
.arg(source_path)
175177
.status()

0 commit comments

Comments
 (0)