feat(cli): move benchmark orchestration into Rust

The C benchmark translation unit still contained the complete BMK
implementation, so program builds and paramgrill could silently keep using a
second C implementation even though rust/src/benchzstd.rs already provided the
same ABI. Replace that duplicate with a declaration-only shim and retain
compile-time checks for the by-value result and parameter layouts.

The standalone test tools do not link the full CLI archive. Keep their
helpers archive free of the benchmark and trace-only objects, and add a
separate benchmark archive for paramgrill so the shim remains linkable without
pulling program-only trace dependencies into datagen and similar targets.

Test Plan:
- `cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features cli,compression,decompression,benchmark,dict-builder --lib -- --test-threads=1` -- 165 passed
- `make -B -C programs -j2 zstd` -- passed
- `./programs/zstd -b1 tests/hello` -- passed
- `make -B -C tests paramgrill` -- passed
- `./tests/paramgrill -S tests/hello` -- passed
- `make -C tests -j2 test-fullbench` -- passed
- targeted Rust clippy and nightly rustfmt checks -- passed
- full all-target clippy remains blocked by pre-existing test-only lints in `zstd_compress.rs` and `fileio_backend.rs`
This commit is contained in:
2026-07-18 18:28:31 +02:00
parent 4c94c644c4
commit 725c064df5
3 changed files with 90 additions and 1270 deletions
+22 -2
View File
@@ -111,7 +111,8 @@ RUST_CLI_MANIFEST := $(RUST_CLI_DIR)/Cargo.toml
RUST_CLI_HELPER_SOURCES := $(RUST_CLI_MANIFEST) $(RUST_CLI_DIR)/Cargo.lock \
$(RUST_CLI_DIR)/src/lib.rs \
$(RUST_DIR)/src/timefn.rs $(RUST_DIR)/src/benchfn.rs \
$(RUST_DIR)/src/datagen.rs $(RUST_DIR)/src/lorem.rs
$(RUST_DIR)/src/datagen.rs $(RUST_DIR)/src/lorem.rs \
$(RUST_DIR)/src/util.rs
RUST_CLI_HELPERS_TARGET_DIR := $(RUST_DIR)/target/cli-helpers
RUST_CLI_HELPERS_STATICLIB := $(RUST_CLI_HELPERS_TARGET_DIR)/release/libzstd_cli_rs.a
RUST_CLI_HELPERS_STATICLIB_32 := $(RUST_CLI_HELPERS_TARGET_DIR)/$(RUST_TARGET_32)/release/libzstd_cli_rs.a
@@ -125,6 +126,25 @@ $(RUST_CLI_HELPERS_STATICLIB): $(RUST_CLI_HELPER_SOURCES)
$(RUST_CLI_HELPERS_STATICLIB_32): $(RUST_CLI_HELPER_SOURCES)
$(CARGO) build $(RUST_CLI_HELPERS_CARGO_FLAGS) --target $(RUST_TARGET_32)
# `paramgrill` still consumes the public benchmark ABI, but unlike the CLI it
# does not link `zstdcli_trace.c` or any other program-only trace surface. Keep
# its benchmark implementation in a separate archive so the helpers archive
# remains linkable by small standalone test tools such as `datagen`.
RUST_CLI_BENCH_SOURCES := $(RUST_CLI_MANIFEST) $(RUST_CLI_DIR)/Cargo.lock \
$(RUST_CLI_DIR)/src/lib.rs \
$(RUST_DIR)/src/benchzstd.rs \
$(RUST_DIR)/src/timefn.rs $(RUST_DIR)/src/benchfn.rs \
$(RUST_DIR)/src/datagen.rs $(RUST_DIR)/src/lorem.rs \
$(RUST_DIR)/src/util.rs
RUST_CLI_BENCH_TARGET_DIR := $(RUST_DIR)/target/cli-benchmark
RUST_CLI_BENCH_STATICLIB := $(RUST_CLI_BENCH_TARGET_DIR)/release/libzstd_cli_rs.a
RUST_CLI_BENCH_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
--target-dir $(RUST_CLI_BENCH_TARGET_DIR) \
--no-default-features --features benchmark
$(RUST_CLI_BENCH_STATICLIB): $(RUST_CLI_BENCH_SOURCES)
$(CARGO) build $(RUST_CLI_BENCH_CARGO_FLAGS)
# These test objects have flat filenames, unlike the configuration-hashed
# program objects. Track the HUF mode separately so a C object set compiled
# for one decoder is never relinked with a Rust archive for another decoder.
@@ -322,7 +342,7 @@ zstreamtest-dll : $(ZSTREAM_LOCAL_FILES) $(RUST_CLI_HELPERS_STATICLIB)
CLEAN += paramgrill
paramgrill : DEBUGFLAGS = # turn off debug for speed measurements
paramgrill : LDLIBS += -lm
paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c $(PRGDIR)/lorem.c paramgrill.c
paramgrill : $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c $(PRGDIR)/benchfn.c $(PRGDIR)/benchzstd.c $(PRGDIR)/datagen.c $(PRGDIR)/lorem.c paramgrill.c $(RUST_CLI_BENCH_STATICLIB)
CLEAN += datagen
datagen : $(PRGDIR)/datagen.c $(PRGDIR)/lorem.c loremOut.c datagencli.c