Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize RISCV_WITH_RVV env var on RISC-V to set WITH_RVV cmake var #218

Merged
merged 8 commits into from
Sep 23, 2024
10 changes: 10 additions & 0 deletions Cargo-zng.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,15 @@ libc = "0.2.43"
[build-dependencies]
cmake = "0.1.50"

[features]
# Experimental: This feature only affects zlib-ng, is only relevant to riscv64
# targets, and currently only has an effect when `cmake` is used. It builds
# binaries portable to machines without RVV, even if the build machine is
# riscv64 and detected to support RVV. This is useful for building a more
# portable binary, or on systems where auto-detection is incorrect (as in
# https://github.com/zlib-ng/zlib-ng/issues/1705). Building with the `RVV_OFF`
# environment variable set (to any value) is equivalent to this feature.
rvv-off = []

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zng)'] }
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ zlib-ng = ["libc", "cmake"]
# or be completely removed in the future
zlib-ng-no-cmake-experimental-community-maintained = ["libc"]
stock-zlib = []
# Experimental: This feature only affects zlib-ng, is only relevant to riscv64
# targets, and currently only has an effect when `cmake` is used. It builds
# binaries portable to machines without RVV, even if the build machine is
# riscv64 and detected to support RVV. This is useful for building a more
# portable binary, or on systems where auto-detection is incorrect (as in
# https://github.com/zlib-ng/zlib-ng/issues/1705). Building with the `RVV_OFF`
# environment variable set (to any value) is equivalent to this feature.
rvv-off = []
# Deprecated: the assembly routines are outdated, and either reduce performance
# or cause segfaults.
asm = []
Expand Down
3 changes: 3 additions & 0 deletions zng/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub fn build_zlib_ng(target: &str, compat: bool) {
.define("WITH_DFLTCC_INFLATE", "1")
.cflag("-DDFLTCC_LEVEL_MASK=0x7e");
}
if target.contains("riscv64") && (cfg!(feature = "rvv-off") || env::var_os("RVV_OFF").is_some()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I prefer "positive" features over "negative" features. By this I mean that the feature sounds like it adds something rather than taking something away.

For example, you could name the environment variable WITH_RVV and allowing the values ON and OFF. This would be familiar to someone who knows the zlib-ng build. It would allow forcing the use of RVV if there was ever a case where it was disabled.

You could name the feature with-rvv. However this would require the default to compile without RVV. This has the advantage of working in more places, at the cost of behaving differently to the default behavior of zlib-ng.

cmake.define("WITH_RVV", "OFF");
}
if target == "i686-pc-windows-msvc" {
cmake.define("CMAKE_GENERATOR_PLATFORM", "Win32");
}
Expand Down
Loading