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+
18def 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