9
9
// except according to those terms.
10
10
11
11
use std:: env;
12
+ use std:: ffi:: OsString ;
12
13
use std:: fs;
13
14
use std:: path:: { Path , PathBuf } ;
14
15
use std:: process:: Command ;
@@ -25,6 +26,16 @@ macro_rules! warning {
25
26
}
26
27
}
27
28
29
+ fn read_and_watch_env ( name : & str ) -> Result < String , env:: VarError > {
30
+ println ! ( "cargo:rerun-if-env-changed={}" , name) ;
31
+ env:: var ( name)
32
+ }
33
+
34
+ fn read_and_watch_env_os ( name : & str ) -> Option < OsString > {
35
+ println ! ( "cargo:rerun-if-env-changed={}" , name) ;
36
+ env:: var_os ( name)
37
+ }
38
+
28
39
// TODO: split main functions and remove following allow.
29
40
#[ allow( clippy:: cognitive_complexity) ]
30
41
fn main ( ) {
@@ -70,7 +81,7 @@ fn main() {
70
81
println ! ( "cargo:rustc-cfg=prefixed" ) ;
71
82
}
72
83
73
- if let Some ( jemalloc) = env :: var_os ( "JEMALLOC_OVERRIDE" ) {
84
+ if let Some ( jemalloc) = read_and_watch_env_os ( "JEMALLOC_OVERRIDE" ) {
74
85
info ! ( "jemalloc override set" ) ;
75
86
let jemalloc = PathBuf :: from ( jemalloc) ;
76
87
assert ! (
@@ -176,7 +187,7 @@ fn main() {
176
187
malloc_conf += "background_thread:false" ;
177
188
}
178
189
179
- if let Ok ( malloc_conf_opts) = env :: var ( "JEMALLOC_SYS_WITH_MALLOC_CONF" ) {
190
+ if let Ok ( malloc_conf_opts) = read_and_watch_env ( "JEMALLOC_SYS_WITH_MALLOC_CONF" ) {
180
191
malloc_conf += & format ! (
181
192
"{}{}" ,
182
193
if malloc_conf. is_empty( ) { "" } else { "," } ,
@@ -189,22 +200,22 @@ fn main() {
189
200
cmd. arg ( format ! ( "--with-malloc-conf={}" , malloc_conf) ) ;
190
201
}
191
202
192
- if let Ok ( lg_page) = env :: var ( "JEMALLOC_SYS_WITH_LG_PAGE" ) {
203
+ if let Ok ( lg_page) = read_and_watch_env ( "JEMALLOC_SYS_WITH_LG_PAGE" ) {
193
204
info ! ( "--with-lg-page={}" , lg_page) ;
194
205
cmd. arg ( format ! ( "--with-lg-page={}" , lg_page) ) ;
195
206
}
196
207
197
- if let Ok ( lg_hugepage) = env :: var ( "JEMALLOC_SYS_WITH_LG_HUGEPAGE" ) {
208
+ if let Ok ( lg_hugepage) = read_and_watch_env ( "JEMALLOC_SYS_WITH_LG_HUGEPAGE" ) {
198
209
info ! ( "--with-lg-hugepage={}" , lg_hugepage) ;
199
210
cmd. arg ( format ! ( "--with-lg-hugepage={}" , lg_hugepage) ) ;
200
211
}
201
212
202
- if let Ok ( lg_quantum) = env :: var ( "JEMALLOC_SYS_WITH_LG_QUANTUM" ) {
213
+ if let Ok ( lg_quantum) = read_and_watch_env ( "JEMALLOC_SYS_WITH_LG_QUANTUM" ) {
203
214
info ! ( "--with-lg-quantum={}" , lg_quantum) ;
204
215
cmd. arg ( format ! ( "--with-lg-quantum={}" , lg_quantum) ) ;
205
216
}
206
217
207
- if let Ok ( lg_vaddr) = env :: var ( "JEMALLOC_SYS_WITH_LG_VADDR" ) {
218
+ if let Ok ( lg_vaddr) = read_and_watch_env ( "JEMALLOC_SYS_WITH_LG_VADDR" ) {
208
219
info ! ( "--with-lg-vaddr={}" , lg_vaddr) ;
209
220
cmd. arg ( format ! ( "--with-lg-vaddr={}" , lg_vaddr) ) ;
210
221
}
@@ -249,6 +260,7 @@ fn main() {
249
260
. arg ( "-j" )
250
261
. arg ( num_jobs. clone ( ) ) ) ;
251
262
263
+ // Skip watching this environment variables to avoid rebuild in CI.
252
264
if env:: var ( "JEMALLOC_SYS_RUN_JEMALLOC_TESTS" ) . is_ok ( ) {
253
265
info ! ( "Building and running jemalloc tests..." ) ;
254
266
// Make tests:
0 commit comments