feat(cli): move benchmark bridge into Rust
Move benchmark parameter normalization and dispatch into the Rust CLI archive while retaining the stable C launcher entry point. Keep compact CLI variants benchmark-free and add an explicit helpers feature for the C test generators. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features benchmark - cargo test --manifest-path rust/cli/Cargo.toml --no-default-features --features helpers - cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets --no-default-features --features cli,compression,decompression,benchmark - cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets --no-default-features --features helpers - make -B -C programs -j2 zstd zstd-small zstd-frugal - make -B -C tests -j2 test-cli-tests - programs/zstd -b1i1 -q
This commit is contained in:
+12
-2
@@ -124,7 +124,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_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
|
||||
--target-dir $(RUST_CLI_TARGET_DIR) \
|
||||
--no-default-features --features cli,compression,decompression
|
||||
--no-default-features --features cli,compression,decompression,benchmark
|
||||
|
||||
$(RUST_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
||||
$(CARGO) build $(RUST_CLI_CARGO_FLAGS)
|
||||
@@ -132,6 +132,16 @@ $(RUST_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
||||
$(RUST_CLI_STATICLIB_32): $(RUST_CLI_SOURCES)
|
||||
$(CARGO) build $(RUST_CLI_CARGO_FLAGS) --target $(RUST_TARGET_32)
|
||||
|
||||
RUST_NOBENCH_CLI_BUILD_CONFIG := cli-c1-d1-nobench-$(RUST_HUF_MODE)
|
||||
RUST_NOBENCH_CLI_TARGET_DIR := $(RUST_DIR)/target/$(RUST_NOBENCH_CLI_BUILD_CONFIG)
|
||||
RUST_NOBENCH_CLI_STATICLIB := $(RUST_NOBENCH_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
|
||||
RUST_NOBENCH_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
|
||||
--target-dir $(RUST_NOBENCH_CLI_TARGET_DIR) \
|
||||
--no-default-features --features cli,compression,decompression
|
||||
|
||||
$(RUST_NOBENCH_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
||||
$(CARGO) build $(RUST_NOBENCH_CLI_CARGO_FLAGS)
|
||||
|
||||
RUST_DECOMPRESS_BUILD_CONFIG := lib-c0-d1-b0-$(RUST_HUF_MODE)-$(RUST_DEBUG_MODE)
|
||||
RUST_DECOMPRESS_TARGET_DIR := $(RUST_DIR)/target/$(RUST_DECOMPRESS_BUILD_CONFIG)
|
||||
RUST_DECOMPRESS_STATICLIB := $(RUST_DECOMPRESS_TARGET_DIR)/release/libzstd_rs.a
|
||||
@@ -455,7 +465,7 @@ CLEAN += zstd-small zstd-frugal
|
||||
# requested HUF decoder mode from the C sources while the Rust archive sees it.
|
||||
ZSTD_SMALL_HUF_CFLAGS := $(filter -DHUF_FORCE_DECOMPRESS_X1% -DHUF_FORCE_DECOMPRESS_X2%,$(CFLAGS))
|
||||
zstd-small: CFLAGS = -Os -Wl,-s $(ZSTD_SMALL_HUF_CFLAGS)
|
||||
zstd-frugal zstd-small: $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c $(RUST_STATICLIB) $(RUST_CLI_STATICLIB)
|
||||
zstd-frugal zstd-small: $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c $(RUST_STATICLIB) $(RUST_NOBENCH_CLI_STATICLIB)
|
||||
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT)
|
||||
|
||||
CLEAN += zstd-decompress
|
||||
|
||||
@@ -10,73 +10,17 @@
|
||||
|
||||
/* The CLI parser and control flow live in rust/src/zstd_cli.rs. Keep this
|
||||
* translation unit as the stable C entry point used by program launchers. */
|
||||
#include <stddef.h> /* size_t */
|
||||
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
|
||||
#include "../lib/zstd.h"
|
||||
#ifndef ZSTD_NOBENCH
|
||||
# include "benchzstd.h" /* BMK_benchFilesAdvanced, BMK_syntheticTest */
|
||||
#endif
|
||||
|
||||
int ZSTD_rust_cli_main(int argCount, const char* const argv[]);
|
||||
const char* ZSTD_rust_cli_expected_version(void);
|
||||
int ZSTD_rust_cli_bench(const char* const* fileNames, unsigned nbFiles,
|
||||
const char* dictFileName,
|
||||
int startCLevel, int endCLevel,
|
||||
const ZSTD_compressionParameters* compressionParams,
|
||||
int displayLevel, unsigned nbSeconds,
|
||||
size_t blockSize, int nbWorkers, int mode);
|
||||
|
||||
const char* ZSTD_rust_cli_expected_version(void)
|
||||
{
|
||||
return ZSTD_VERSION_STRING;
|
||||
}
|
||||
|
||||
/* Benchmark bridge for the Rust CLI. Whether benchmarking exists is a C
|
||||
* preprocessor property (ZSTD_NOBENCH), so the decision stays in this shim:
|
||||
* the Rust frontend calls in unconditionally, and stripped program variants
|
||||
* never reference benchmark symbols.
|
||||
* @return the benchmark result code (>= 0), or -1 when unavailable. */
|
||||
int ZSTD_rust_cli_bench(const char* const* fileNames, unsigned nbFiles,
|
||||
const char* dictFileName,
|
||||
int startCLevel, int endCLevel,
|
||||
const ZSTD_compressionParameters* compressionParams,
|
||||
int displayLevel, unsigned nbSeconds,
|
||||
size_t blockSize, int nbWorkers, int mode)
|
||||
{
|
||||
#ifndef ZSTD_NOBENCH
|
||||
BMK_advancedParams_t advancedParams = BMK_initAdvancedParams();
|
||||
int startLevel = startCLevel;
|
||||
int endLevel = endCLevel;
|
||||
advancedParams.nbSeconds = nbSeconds;
|
||||
advancedParams.blockSize = blockSize;
|
||||
advancedParams.nbWorkers = nbWorkers;
|
||||
advancedParams.mode = (BMK_mode_t)mode;
|
||||
if (advancedParams.mode == BMK_decodeOnly) {
|
||||
startLevel = 0;
|
||||
endLevel = 0;
|
||||
}
|
||||
if (startLevel > ZSTD_maxCLevel()) startLevel = ZSTD_maxCLevel();
|
||||
if (endLevel > ZSTD_maxCLevel()) endLevel = ZSTD_maxCLevel();
|
||||
if (endLevel < startLevel) endLevel = startLevel;
|
||||
if (nbFiles == 0) {
|
||||
/* No input file: benchmark a synthetic sample (lorem generator). */
|
||||
return BMK_syntheticTest(-1.0, startLevel, endLevel,
|
||||
compressionParams, displayLevel,
|
||||
&advancedParams);
|
||||
}
|
||||
return BMK_benchFilesAdvanced(fileNames, nbFiles, dictFileName,
|
||||
startLevel, endLevel,
|
||||
compressionParams, displayLevel,
|
||||
&advancedParams);
|
||||
#else
|
||||
(void)fileNames; (void)nbFiles; (void)dictFileName;
|
||||
(void)startCLevel; (void)endCLevel; (void)compressionParams;
|
||||
(void)displayLevel; (void)nbSeconds; (void)blockSize; (void)nbWorkers;
|
||||
(void)mode;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argCount, const char* argv[])
|
||||
{
|
||||
return ZSTD_rust_cli_main(argCount, argv);
|
||||
|
||||
Reference in New Issue
Block a user