Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 1400258

Browse files
committed
Add function and comments in build.bzl
Signed-off-by: Quanyi Ma <eli@patch.sh>
1 parent 9fd98d1 commit 1400258

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

third-party/rust/crates/zstd-sys/2.0.14+zstd.1.5.7/BUCK

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ load("//third-party/rust/crates/zstd-sys/2.0.14+zstd.1.5.7:build.bzl", "get_rust
88
cxx_library(
99
name = "zstd_c",
1010
srcs = glob([
11-
"zstd/lib/common/**/*.c",
12-
"zstd/lib/compress/**/*.c",
13-
"zstd/lib/decompress/**/*.c",
14-
"zstd/lib/dictBuilder/**/*.c",
15-
"zstd/lib/legacy/**/*.c",
16-
"zstd/contrib/seekable_format/**/*.c",
17-
"zstd/lib/decompress/huf_decompress_amd64.S",
18-
]),
11+
"zstd/lib/common/*.c",
12+
"zstd/lib/compress/*.c",
13+
"zstd/lib/decompress/*.c",
14+
]) + select({
15+
"DEFAULT": ["zstd/lib/decompress/huf_decompress_amd64.S"],
16+
"ovr_config//os:windows": [],
17+
}),
1918
headers = glob([
2019
"zstd/lib/**/*.h",
2120
"wasm-shim/**/*.h",
Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,71 @@
1+
"""Build configuration module for zstd-sys crate.
2+
3+
This module provides functionality for configuring Rust features and standard library
4+
support for the zstd-sys crate build process. It handles feature flag management and
5+
platform-specific configurations.
6+
"""
7+
18
def get_rust_features():
29
features_config = read_config("rust", "features", "")
310

411
if features_config == "":
512
return ["legacy", "zdict_builder"] # Default features
6-
return [f.strip() for f in features_config.split(",") if f.strip()]
13+
return [f.strip() for f in features_config.split(",") if f.strip()]
14+
15+
16+
def get_std_feature():
17+
"""Determines whether the std feature should be enabled based on target platform.
18+
19+
Checks the target architecture and OS to decide if the standard library feature
20+
should be enabled. Currently enables std for wasm32 architecture or hermit OS.
21+
22+
```rust
23+
let target_arch =
24+
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
25+
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
26+
27+
if target_arch == "wasm32" || target_os == "hermit" {
28+
cargo_print(&"rustc-cfg=feature=\"std\"");
29+
}
30+
```
31+
32+
Returns:
33+
A list containing "std" if the feature should be enabled, empty list otherwise.
34+
"""
35+
arch = read_config("target", "arch", "")
36+
os = read_config("target", "os", "")
37+
38+
# Enable std feature for wasm32 or hermit OS targets
39+
if arch == "wasm32" or os == "hermit":
40+
return ["std"]
41+
return []
42+
43+
def zstd_features(features: list[str]) -> list[str]:
44+
"""Generates zstd compilation flags based on enabled features.
45+
46+
Takes a list of enabled features and returns corresponding zstd compilation flags.
47+
Handles features like multithreading, legacy support, thin mode, and assembly
48+
optimizations.
49+
50+
Args:
51+
features: List of enabled feature strings to configure zstd compilation
52+
53+
Returns:
54+
List of C compilation flags needed for the requested features
55+
"""
56+
flags = []
57+
if "zstdmt" in features:
58+
flags.append("-DZSTD_MULTITHREAD")
59+
if "legacy" in features:
60+
flags += ["-DZSTD_LEGACY_SUPPORT=1", "-Izstd/lib/legacy"]
61+
if "thin" in features:
62+
flags += [
63+
"-DHUF_FORCE_DECOMPRESS_X1",
64+
"-DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT",
65+
"-DZSTD_NO_INLINE",
66+
"-DZSTD_STRIP_ERROR_STRINGS",
67+
"-DDYNAMIC_BMI2=0",
68+
]
69+
if "no_asm" in features:
70+
flags.append("-DZSTD_DISABLE_ASM")
71+
return flags

0 commit comments

Comments
 (0)