Skip to content

Commit

Permalink
Feedback: stricter bool env var parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Sep 4, 2024
1 parent 473ff7b commit fb24403
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aws-lc-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ detected in the build environment *it is used* to compile the assembly files. Ho
if a NASM assembler is not available, and the "fips" feature is not enabled, then the build fails unless one of the following conditions are true:

* You are building for `x86-64` and either:
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1" (or the value is empty); OR
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1"; OR
* `AWS_LC_SYS_PREBUILT_NASM` is *not found* in the environment AND the "prebuilt-nasm" feature has been enabled.

If the above cases apply, then the crate provided prebuilt NASM objects will be used for the build. To prevent usage of prebuilt NASM
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
//! if a NASM assembler is not available, and the "fips" feature is not enabled, then the build fails unless one of the following conditions are true:
//!
//! * You are building for `x86-64` and either:
//! * The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1" (or the value is empty); OR
//! * The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1"; OR
//! * `AWS_LC_SYS_PREBUILT_NASM` is *not found* in the environment AND the "prebuilt-nasm" feature has been enabled.
//!
//! If the above cases apply, then the crate provided prebuilt NASM objects will be used for the build. To prevent usage of prebuilt NASM
Expand Down
2 changes: 1 addition & 1 deletion aws-lc-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if a NASM assembler is not available, and the "fips" feature is not enabled, the
following conditions are true:

* You are building for `x86-64` and either:
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1" (or the value is empty); OR
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1"; OR
* `AWS_LC_SYS_PREBUILT_NASM` is *not found* in the environment AND the "prebuilt-nasm" feature has been enabled.

If the above cases apply, then the crate provided prebuilt NASM objects will be used for the build. To prevent usage of
Expand Down
23 changes: 15 additions & 8 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,28 @@ fn option_env<N: AsRef<str>>(name: N) -> Option<String> {
fn env_var_to_bool(name: &str) -> Option<bool> {
let build_type_result = option_env(name);
if let Some(env_var_value) = build_type_result {
eprintln!("{name}={env_var_value}");
// If the environment variable is set, we ignore every other factor.
eprintln!("Evaluating: {name}='{env_var_value}'");

let env_var_value = env_var_value.to_lowercase();
if env_var_value.starts_with('0')
|| env_var_value.starts_with('n')
|| env_var_value.starts_with("off")
|| env_var_value.starts_with('f')
{
Some(false)
} else {
// Otherwise, if the variable is set, assume true
Some(true)
eprintln!("Parsed: {name}=false");
return Some(false);
}
} else {
None
if env_var_value.starts_with(|c: char| c.is_ascii_digit())
|| env_var_value.starts_with('y')
|| env_var_value.starts_with("on")
|| env_var_value.starts_with('t')
{
eprintln!("Parsed: {name}=true");
return Some(true);
}
eprintln!("Parsed: {name}=unknown");
}
None
}

impl Default for OutputLibType {
Expand Down
2 changes: 1 addition & 1 deletion book/src/requirements/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if a NASM assembler is not available, and the "fips" feature is not enabled, the
following conditions are true:

* You are building for `x86-64` and either:
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1" (or the value is empty); OR
* The `AWS_LC_SYS_PREBUILT_NASM` environment variable is found and has a value of "1"; OR
* `AWS_LC_SYS_PREBUILT_NASM` is *not found* in the environment AND the "prebuilt-nasm" feature has been enabled.

If the above cases apply, then the crate provided prebuilt NASM objects will be used for the build. To prevent usage of
Expand Down

0 comments on commit fb24403

Please sign in to comment.