Skip to content

Commit 8636464

Browse files
committed
Fix up the environment variable string conversion
* Tweak string conversion For correctness and MSRV compatibility. * Match and explicitly do nothing for absent or strange value * Fix the conversion lifetime by reorganizing the code * Slightly simplify
1 parent 66df3f5 commit 8636464

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

zng/cmake.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::ffi::OsStr;
32

43
pub fn build_zlib_ng(target: &str, compat: bool) {
54
let mut cmake = cmake::Config::new("src/zlib-ng");
@@ -18,23 +17,21 @@ pub fn build_zlib_ng(target: &str, compat: bool) {
1817
if target.contains("riscv") {
1918
// Check if we should pass on an explicit boolean value of the WITH_RVV build option.
2019
// See: https://github.com/zlib-ng/zlib-ng?tab=readme-ov-file#advanced-build-options
21-
match env::var_os("RISCV_WITH_RVV")
22-
.map(OsStr::to_str)
23-
.map(str::trim)
24-
.map(str::to_uppercase)
25-
.map(Into::into)
26-
{
27-
Some("OFF" | "NO" | "FALSE" | "0") => {
28-
// Force RVV off. This turns off RVV entirely, as well as the runtime check for it.
29-
// This is not usually necessary, but can be useful for building binaries portable
30-
// to systems that do not support RVV but where auto-detection fails to identify
31-
// this (as in https://github.com/zlib-ng/zlib-ng/issues/1705).
32-
cmake.define("WITH_RVV", "OFF");
33-
}
34-
Some("ON" | "YES" | "TRUE" | "1") => {
35-
// Try to use RVV, but still don't do so if a runtime check finds it unavailable.
36-
// This has the same effect as omitting WITH_RVV, unless it has already been set.
37-
cmake.define("WITH_RVV", "ON");
20+
if let Ok(value) = env::var("RISCV_WITH_RVV") {
21+
match value.trim().to_uppercase().as_str() {
22+
"OFF" | "NO" | "FALSE" | "0" => {
23+
// Force RVV off. This turns off RVV entirely, as well as the runtime check for it.
24+
// This is not usually necessary, but can be useful for building binaries portable
25+
// to systems that do not support RVV but where auto-detection fails to identify
26+
// this (as in https://github.com/zlib-ng/zlib-ng/issues/1705).
27+
cmake.define("WITH_RVV", "OFF");
28+
}
29+
"ON" | "YES" | "TRUE" | "1" => {
30+
// Try to use RVV, but still don't do so if a runtime check finds it unavailable.
31+
// This has the same effect as omitting WITH_RVV, unless it has already been set.
32+
cmake.define("WITH_RVV", "ON");
33+
}
34+
_ => {}
3835
}
3936
}
4037
}

0 commit comments

Comments
 (0)