@@ -2,8 +2,8 @@ use std::env;
2
2
use std:: path:: { Path , PathBuf } ;
3
3
use std:: process:: Command ;
4
4
5
- use lazy_static:: lazy_static;
6
5
use rstest:: * ;
6
+ use std:: sync:: OnceLock ;
7
7
use tempfile:: TempDir ;
8
8
9
9
#[ fixture]
@@ -13,7 +13,7 @@ fn libtest() -> &'static str {
13
13
14
14
eprintln ! ( "Building libtest" ) ;
15
15
compile_test_lib ( "test" ) ;
16
- TMPDIR . path ( ) . to_str ( ) . unwrap ( )
16
+ get_tmpdir ( ) . path ( ) . to_str ( ) . unwrap ( )
17
17
}
18
18
19
19
#[ fixture]
@@ -120,8 +120,10 @@ fn test_ld_path_restore(libtest: &str, _dt_needed_bin: &Path) {
120
120
const EXE : & str = env ! ( "CARGO_BIN_EXE_nix-ld" ) ;
121
121
const TARGET : & str = env ! ( "NIX_LD_TEST_TARGET" ) ;
122
122
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" ) )
125
127
}
126
128
127
129
fn find_cc ( ) -> String {
@@ -141,7 +143,7 @@ fn get_source_file(file: &str) -> PathBuf {
141
143
fn compile_test_lib ( name : & str ) {
142
144
let cc = find_cc ( ) ;
143
145
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) ) ;
145
147
146
148
let status = Command :: new ( cc)
147
149
. arg ( "-fPIC" )
@@ -158,9 +160,9 @@ fn compile_test_lib(name: &str) {
158
160
fn compile_test_bin ( name : & str , libs : & [ & str ] ) -> PathBuf {
159
161
let cc = find_cc ( ) ;
160
162
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) ;
162
164
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( ) ) ;
164
166
let dynamic_linker_arg = format ! ( "-Wl,--dynamic-linker,{}" , EXE ) ;
165
167
166
168
let status = Command :: new ( cc)
@@ -169,7 +171,7 @@ fn compile_test_bin(name: &str, libs: &[&str]) -> PathBuf {
169
171
. arg ( out_dir_arg)
170
172
. arg ( dynamic_linker_arg)
171
173
. arg ( "-L" )
172
- . arg ( TMPDIR . path ( ) )
174
+ . arg ( get_tmpdir ( ) . path ( ) )
173
175
. args ( libs. iter ( ) . map ( |l| format ! ( "-l{}" , l) ) )
174
176
. arg ( source_path)
175
177
. status ( )
0 commit comments