Skip to content

Commit dbbe477

Browse files
committed
Use RISCV_WITH_RVV as the env var, taking ON/OFF values
Instead of `RVV_OFF`. This checks if the value appears to match any of several hard-coded truthy or falsy values. Typically the literal values `ON` or `OFF` would be used, as is typically done when passing boolean `-D...` options to `cmake` on the command-line. It is typically more useful to pass `OFF` here than `ON`, becuase the default is `ON`, as noted in the linked section of the zlib-ng readme. At least for now, empty, blank, and otherwise unrecognized values are simply ignored. Recognized values are always "normalized" as either `ON` (if truthy) or `OFF` (if falsy).
1 parent 7579d46 commit dbbe477

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

zng/cmake.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::ffi::OsStr;
23

34
pub fn build_zlib_ng(target: &str, compat: bool) {
45
let mut cmake = cmake::Config::new("src/zlib-ng");
@@ -14,8 +15,25 @@ pub fn build_zlib_ng(target: &str, compat: bool) {
1415
.define("WITH_DFLTCC_INFLATE", "1")
1516
.cflag("-DDFLTCC_LEVEL_MASK=0x7e");
1617
}
17-
if target.contains("riscv64") && env::var_os("RVV_OFF").is_some() {
18-
cmake.define("WITH_RVV", "OFF");
18+
if target.contains("riscv") {
19+
// Check if we should pass on an explicit boolean value of the WITH_RVV build option.
20+
// 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+
cmake.define("WITH_RVV", "OFF");
30+
}
31+
Some("ON" | "YES" | "TRUE" | "1") => {
32+
// Try to use RVV, but still don't do so if a runtime check finds it unavailable.
33+
// This has the same effect as omitting WITH_RVV, unless it has already been set.
34+
cmake.define("WITH_RVV", "ON");
35+
}
36+
}
1937
}
2038
if target == "i686-pc-windows-msvc" {
2139
cmake.define("CMAKE_GENERATOR_PLATFORM", "Win32");

0 commit comments

Comments
 (0)