Restore benchmark decode mode, auto-thread selection, alternate frame formats, gzip/xz/lzma/lz4 aliases, and trace lifecycle handling in the Rust frontend. Test Plan: - RUSTC_WRAPPER= CARGO_BUILD_RUSTC_WRAPPER= cargo test --manifest-path rust/cli/Cargo.toml - RUSTC_WRAPPER= CARGO_BUILD_RUSTC_WRAPPER= cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - make -B -C programs zstd V=1 - make -C tests check V=1
84 lines
3.5 KiB
C
84 lines
3.5 KiB
C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
* in the COPYING file in the root directory of this source tree).
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
*/
|
|
|
|
/* 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);
|
|
}
|