Skip to content

Commit 5e53b21

Browse files
committed
refactor(build-rs): Clarify bool policy
1 parent 58ac23d commit 5e53b21

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

crates/build-rs/src/input.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! invalid {
2727
}
2828

2929
#[track_caller]
30-
fn get_bool(key: &str) -> bool {
30+
fn is_present(key: &str) -> bool {
3131
env::var_os(key).is_some()
3232
}
3333

@@ -135,7 +135,7 @@ pub fn cargo_feature(name: &str) -> bool {
135135
}
136136
let name = name.to_uppercase().replace('-', "_");
137137
let key = format!("CARGO_FEATURE_{name}");
138-
get_bool(&key)
138+
is_present(&key)
139139
}
140140

141141
/// For each [configuration option] of the package being built, this will contain
@@ -162,31 +162,31 @@ mod cfg {
162162
#[cfg(any())]
163163
#[track_caller]
164164
pub fn cargo_cfg_clippy() -> bool {
165-
get_bool("CARGO_CFG_CLIPPY")
165+
is_present("CARGO_CFG_CLIPPY")
166166
}
167167

168168
/// If we are compiling with debug assertions enabled.
169169
#[track_caller]
170170
pub fn cargo_cfg_debug_assertions() -> bool {
171-
get_bool("CARGO_CFG_DEBUG_ASSERTIONS")
171+
is_present("CARGO_CFG_DEBUG_ASSERTIONS")
172172
}
173173

174174
#[cfg(any())]
175175
#[track_caller]
176176
pub fn cargo_cfg_doc() -> bool {
177-
get_bool("CARGO_CFG_DOC")
177+
is_present("CARGO_CFG_DOC")
178178
}
179179

180180
#[cfg(any())]
181181
#[track_caller]
182182
pub fn cargo_cfg_docsrs() -> bool {
183-
get_bool("CARGO_CFG_DOCSRS")
183+
is_present("CARGO_CFG_DOCSRS")
184184
}
185185

186186
#[cfg(any())]
187187
#[track_caller]
188188
pub fn cargo_cfg_doctest() -> bool {
189-
get_bool("CARGO_CFG_DOCTEST")
189+
is_present("CARGO_CFG_DOCTEST")
190190
}
191191

192192
/// The level of detail provided by derived [`Debug`] implementations.
@@ -200,15 +200,15 @@ mod cfg {
200200
#[cfg(any())]
201201
#[track_caller]
202202
pub fn cargo_cfg_miri() -> bool {
203-
get_bool("CARGO_CFG_MIRI")
203+
is_present("CARGO_CFG_MIRI")
204204
}
205205

206206
/// If we are compiling with overflow checks enabled.
207207
#[doc = unstable!(cfg_overflow_checks, 111466)]
208208
#[cfg(feature = "unstable")]
209209
#[track_caller]
210210
pub fn cargo_cfg_overflow_checks() -> bool {
211-
get_bool("CARGO_CFG_OVERFLOW_CHECKS")
211+
is_present("CARGO_CFG_OVERFLOW_CHECKS")
212212
}
213213

214214
/// The [panic strategy](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#panic).
@@ -220,7 +220,7 @@ mod cfg {
220220
/// If the crate is being compiled as a procedural macro.
221221
#[track_caller]
222222
pub fn cargo_cfg_proc_macro() -> bool {
223-
get_bool("CARGO_CFG_PROC_MACRO")
223+
is_present("CARGO_CFG_PROC_MACRO")
224224
}
225225

226226
/// The target relocation model.
@@ -234,7 +234,7 @@ mod cfg {
234234
#[cfg(any())]
235235
#[track_caller]
236236
pub fn cargo_cfg_rustfmt() -> bool {
237-
get_bool("CARGO_CFG_RUSTFMT")
237+
is_present("CARGO_CFG_RUSTFMT")
238238
}
239239

240240
/// Sanitizers enabled for the crate being compiled.
@@ -251,15 +251,15 @@ mod cfg {
251251
#[cfg(feature = "unstable")]
252252
#[track_caller]
253253
pub fn cargo_cfg_sanitizer_cfi_generalize_pointers() -> bool {
254-
get_bool("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
254+
is_present("CARGO_CFG_SANITIZER_CFI_GENERALIZE_POINTERS")
255255
}
256256

257257
/// If CFI sanitization is normalizing integers.
258258
#[doc = unstable!(cfg_sanitizer_cfi, 89653)]
259259
#[cfg(feature = "unstable")]
260260
#[track_caller]
261261
pub fn cargo_cfg_sanitizer_cfi_normalize_integers() -> bool {
262-
get_bool("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
262+
is_present("CARGO_CFG_SANITIZER_CFI_NORMALIZE_INTEGERS")
263263
}
264264

265265
/// Disambiguation of the [target ABI](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_abi)
@@ -349,7 +349,7 @@ mod cfg {
349349
#[cfg(feature = "unstable")]
350350
#[track_caller]
351351
pub fn cargo_cfg_target_thread_local() -> bool {
352-
get_bool("CARGO_CFG_TARGET_THREAD_LOCAL")
352+
is_present("CARGO_CFG_TARGET_THREAD_LOCAL")
353353
}
354354

355355
/// The [target vendor](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_vendor).
@@ -361,27 +361,27 @@ mod cfg {
361361
#[cfg(any())]
362362
#[track_caller]
363363
pub fn cargo_cfg_test() -> bool {
364-
get_bool("CARGO_CFG_TEST")
364+
is_present("CARGO_CFG_TEST")
365365
}
366366

367367
/// If we are compiling with UB checks enabled.
368368
#[doc = unstable!(cfg_ub_checks, 123499)]
369369
#[cfg(feature = "unstable")]
370370
#[track_caller]
371371
pub fn cargo_cfg_ub_checks() -> bool {
372-
get_bool("CARGO_CFG_UB_CHECKS")
372+
is_present("CARGO_CFG_UB_CHECKS")
373373
}
374374

375375
/// Set on [unix-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
376376
#[track_caller]
377377
pub fn cargo_cfg_unix() -> bool {
378-
get_bool("CARGO_CFG_UNIX")
378+
is_present("CARGO_CFG_UNIX")
379379
}
380380

381381
/// Set on [windows-like platforms](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#unix-and-windows).
382382
#[track_caller]
383383
pub fn cargo_cfg_windows() -> bool {
384-
get_bool("CARGO_CFG_WINDOWS")
384+
is_present("CARGO_CFG_WINDOWS")
385385
}
386386
}
387387

0 commit comments

Comments
 (0)