/* * 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 /* 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); 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) { #ifndef ZSTD_NOBENCH BMK_advancedParams_t advancedParams = BMK_initAdvancedParams(); int startLevel = startCLevel; int endLevel = endCLevel; advancedParams.nbSeconds = nbSeconds; advancedParams.blockSize = blockSize; advancedParams.nbWorkers = nbWorkers; 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; return -1; #endif } int main(int argCount, const char* argv[]) { return ZSTD_rust_cli_main(argCount, argv); }