Skip to content

Commit 728acdf

Browse files
jschwesagudev
andauthored
Respect MOZJS_FROM_SOURCE=0 (#581)
* Respect MOZJS_FROM_SOURCE=0 Allow disabling the from source build explicitly. Signed-off-by: Jonathan Schwender <[email protected]> * Fix wrong condition Co-authored-by: sagudev <[email protected]> Signed-off-by: Jonathan Schwender <[email protected]> --------- Signed-off-by: Jonathan Schwender <[email protected]> Signed-off-by: Jonathan Schwender <[email protected]> Co-authored-by: sagudev <[email protected]>
1 parent d1525df commit 728acdf

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

mozjs-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository.workspace = true
5-
version = "0.128.9-1"
5+
version = "0.128.9-2"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
build = "build.rs"

mozjs-sys/build.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,38 @@ fn main() {
118118
}
119119
}
120120

121+
/// Returns the value of an environment variable as a boolean if set
122+
///
123+
/// If the variable is set without a value, that is interpreted as `true`
124+
///
125+
/// ### Panics
126+
///
127+
/// Panics if the value was set, but could not be interpreted as a boolean.
128+
fn env_var_bool_value(name: &str) -> Option<bool> {
129+
let Some(os_val) = env::var_os(name) else {
130+
return None;
131+
};
132+
let val_lowercase = os_val.to_string_lossy().to_lowercase();
133+
match val_lowercase.as_str() {
134+
"1" | "on" | "true" | "yes" | "" => Some(true),
135+
"0" | "off" | "false" | "no" => Some(false),
136+
_other => {
137+
panic!("Expected `{name}` to have a boolean-ish value, but got `{os_val:?}`");
138+
}
139+
}
140+
}
141+
121142
/// Check env variable conditions to decide if we need to link pre-built archive first.
122143
/// And then return bool value to notify if we need to build from source instead.
123144
fn should_build_from_source() -> bool {
124-
if env::var_os("MOZJS_FROM_SOURCE").is_some() {
125-
println!("Environment variable MOZJS_FROM_SOURCE is set. Building from source directly.");
126-
true
127-
} else if env::var_os("MOZJS_CREATE_ARCHIVE").is_some() {
145+
if let Some(from_source) = env_var_bool_value("MOZJS_FROM_SOURCE") {
146+
if from_source {
147+
println!(
148+
"Environment variable MOZJS_FROM_SOURCE is set. Building from source directly."
149+
);
150+
}
151+
from_source
152+
} else if env_var_bool_value("MOZJS_CREATE_ARCHIVE") == Some(true) {
128153
println!(
129154
"Environment variable MOZJS_CREATE_ARCHIVE is set. Building from source directly."
130155
);

0 commit comments

Comments
 (0)