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:
@@ -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