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
+6 -5
View File
@@ -152,6 +152,7 @@ struct ZDICT_fastCover_params_t {
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg(all(feature = "compression", feature = "dict-builder"))]
struct ZDICT_legacy_params_t {
selectivityLevel: c_uint,
zParams: ZDICT_params_t,
@@ -297,7 +298,7 @@ unsafe extern "C" {
/// Narrow bridge to `programs/dibio.c`. The file loader and dictionary
/// algorithms remain on the C/Rust library side of this boundary.
#[cfg(feature = "compression")]
#[cfg(all(feature = "compression", feature = "dict-builder"))]
fn DiB_trainFromFiles(
dict_file_name: *const c_char,
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) {
let max_level = DEFAULT_MAX_CLEVEL;
let max_level = max_c_level_for_help();
let _ = writeln!(
out,
"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
/// dictionary builder symbols are supplied by the Rust library archive.
fn run_train(cli: &Cli) -> Result<i32, String> {
#[cfg(not(feature = "compression"))]
#[cfg(not(all(feature = "compression", feature = "dict-builder")))]
{
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 output = cli.output.as_ref().unwrap_or(&default_output);