fix(build): gate CLI dictionary builder by feature

Keep dictionary-training code out of compressor-only and decompressor-only CLI
archives, where its ZDICT symbols are intentionally absent. Add a dedicated
Rust CLI archive for zstd-dictBuilder, enable the builder feature only for the
full and dictionary-builder programs, and make reduced-feature help use the
feature-independent max-level helper.

Test Plan:
- cargo test --manifest-path rust/cli/Cargo.toml --lib -- --test-threads=1 (158 passed)
- cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features cli,compression,dict-builder --lib -- --test-threads=1 (124 passed)
- cargo clippy --manifest-path rust/cli/Cargo.toml --lib -- -D warnings
- cargo clippy --manifest-path rust/cli/Cargo.toml --no-default-features --features cli,compression,dict-builder --lib -- -D warnings
- make -C programs -j2 zstd zstd-small zstd-frugal zstd-decompress zstd-compress zstd-dictBuilder
- git diff --check
This commit is contained in:
2026-07-18 17:36:24 +02:00
parent f7a2576761
commit e557549ff4
4 changed files with 20 additions and 8 deletions
+12 -2
View File
@@ -125,7 +125,7 @@ RUST_CLI_STATICLIB := $(RUST_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
RUST_CLI_STATICLIB_32 := $(RUST_CLI_TARGET_DIR)/$(RUST_TARGET_32)/release/libzstd_cli_rs.a RUST_CLI_STATICLIB_32 := $(RUST_CLI_TARGET_DIR)/$(RUST_TARGET_32)/release/libzstd_cli_rs.a
RUST_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \ RUST_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
--target-dir $(RUST_CLI_TARGET_DIR) \ --target-dir $(RUST_CLI_TARGET_DIR) \
--no-default-features --features cli,compression,decompression,benchmark --no-default-features --features cli,compression,decompression,benchmark,dict-builder
$(RUST_CLI_STATICLIB): $(RUST_CLI_SOURCES) $(RUST_CLI_STATICLIB): $(RUST_CLI_SOURCES)
$(CARGO) build $(RUST_CLI_CARGO_FLAGS) $(CARGO) build $(RUST_CLI_CARGO_FLAGS)
@@ -206,6 +206,16 @@ RUST_COMPRESS_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release
$(RUST_COMPRESS_CLI_STATICLIB): $(RUST_CLI_SOURCES) $(RUST_COMPRESS_CLI_STATICLIB): $(RUST_CLI_SOURCES)
$(CARGO) build $(RUST_COMPRESS_CLI_CARGO_FLAGS) $(CARGO) build $(RUST_COMPRESS_CLI_CARGO_FLAGS)
RUST_DICTBUILDER_CLI_BUILD_CONFIG := cli-c1-d0-dictbuilder-$(RUST_HUF_MODE)
RUST_DICTBUILDER_CLI_TARGET_DIR := $(RUST_DIR)/target/$(RUST_DICTBUILDER_CLI_BUILD_CONFIG)
RUST_DICTBUILDER_CLI_STATICLIB := $(RUST_DICTBUILDER_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
RUST_DICTBUILDER_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
--target-dir $(RUST_DICTBUILDER_CLI_TARGET_DIR) \
--no-default-features --features cli,compression,dict-builder
$(RUST_DICTBUILDER_CLI_STATICLIB): $(RUST_CLI_SOURCES)
$(CARGO) build $(RUST_DICTBUILDER_CLI_CARGO_FLAGS)
# Most program objects use a configuration-hashed directory, but the compact # Most program objects use a configuration-hashed directory, but the compact
# direct-source variants below do not. Give their C outputs an independent # direct-source variants below do not. Give their C outputs an independent
# mode stamp so they cannot outlive a different Rust HUF archive selection. # mode stamp so they cannot outlive a different Rust HUF archive selection.
@@ -479,7 +489,7 @@ zstd-compress: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) zstdcli.c util.c ti
## zstd-dictBuilder: executable supporting dictionary creation and compression (only) ## zstd-dictBuilder: executable supporting dictionary creation and compression (only)
CLEAN += zstd-dictBuilder CLEAN += zstd-dictBuilder
zstd-dictBuilder: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c dibio.c $(RUST_DICTBUILDER_STATICLIB) $(RUST_COMPRESS_CLI_STATICLIB) zstd-dictBuilder: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c dibio.c $(RUST_DICTBUILDER_STATICLIB) $(RUST_DICTBUILDER_CLI_STATICLIB)
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT) $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT)
RUST_DIRECT_LINK_TARGETS := zstd32 zstd-nolegacy zstd-small zstd-frugal \ RUST_DIRECT_LINK_TARGETS := zstd32 zstd-nolegacy zstd-small zstd-frugal \
+1
View File
@@ -14,6 +14,7 @@ default = ["cli", "compression", "decompression", "benchmark"]
cli = [] cli = []
compression = [] compression = []
decompression = [] decompression = []
dict-builder = ["compression"]
helpers = [] helpers = []
# The integrated benchmark archive is optional so zstd-small and zstd-frugal # The integrated benchmark archive is optional so zstd-small and zstd-frugal
# can omit every benchmark implementation and its timing/data-generator # can omit every benchmark implementation and its timing/data-generator
+1 -1
View File
@@ -7,7 +7,7 @@ mod benchzstd;
#[cfg(any(feature = "benchmark", feature = "helpers"))] #[cfg(any(feature = "benchmark", feature = "helpers"))]
#[path = "../../src/datagen.rs"] #[path = "../../src/datagen.rs"]
mod datagen; mod datagen;
#[cfg(feature = "cli")] #[cfg(all(feature = "cli", feature = "dict-builder"))]
#[path = "../../src/dibio.rs"] #[path = "../../src/dibio.rs"]
mod dibio; mod dibio;
#[cfg(feature = "cli")] #[cfg(feature = "cli")]
+6 -5
View File
@@ -152,6 +152,7 @@ struct ZDICT_fastCover_params_t {
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg(all(feature = "compression", feature = "dict-builder"))]
struct ZDICT_legacy_params_t { struct ZDICT_legacy_params_t {
selectivityLevel: c_uint, selectivityLevel: c_uint,
zParams: ZDICT_params_t, zParams: ZDICT_params_t,
@@ -297,7 +298,7 @@ unsafe extern "C" {
/// Narrow bridge to `programs/dibio.c`. The file loader and dictionary /// Narrow bridge to `programs/dibio.c`. The file loader and dictionary
/// algorithms remain on the C/Rust library side of this boundary. /// algorithms remain on the C/Rust library side of this boundary.
#[cfg(feature = "compression")] #[cfg(all(feature = "compression", feature = "dict-builder"))]
fn DiB_trainFromFiles( fn DiB_trainFromFiles(
dict_file_name: *const c_char, dict_file_name: *const c_char,
max_dict_size: usize, max_dict_size: usize,
@@ -688,7 +689,7 @@ const fn max_c_level_for_help() -> i32 {
} }
fn write_basic_usage<W: Write>(out: &mut W, program_name: &str) { fn write_basic_usage<W: Write>(out: &mut W, program_name: &str) {
let max_level = DEFAULT_MAX_CLEVEL; let max_level = max_c_level_for_help();
let _ = writeln!( let _ = writeln!(
out, out,
"Compress or decompress the INPUT file(s); reads from STDIN if INPUT is `-` or not provided." "Compress or decompress the INPUT file(s); reads from STDIN if INPUT is `-` or not provided."
@@ -2538,13 +2539,13 @@ fn run_bench(cli: &Cli) -> Result<i32, String> {
/// file loading and output path stay in that bridge for now; the selected /// file loading and output path stay in that bridge for now; the selected
/// dictionary builder symbols are supplied by the Rust library archive. /// dictionary builder symbols are supplied by the Rust library archive.
fn run_train(cli: &Cli) -> Result<i32, String> { fn run_train(cli: &Cli) -> Result<i32, String> {
#[cfg(not(feature = "compression"))] #[cfg(not(all(feature = "compression", feature = "dict-builder")))]
{ {
let _ = cli; let _ = cli;
return Err("training mode not available".to_owned()); Err("training mode not available".to_owned())
} }
#[cfg(feature = "compression")] #[cfg(all(feature = "compression", feature = "dict-builder"))]
{ {
let default_output = cstring(DEFAULT_DICT_NAME).expect("static dictionary name"); let default_output = cstring(DEFAULT_DICT_NAME).expect("static dictionary name");
let output = cli.output.as_ref().unwrap_or(&default_output); let output = cli.output.as_ref().unwrap_or(&default_output);