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`
81 lines
3.7 KiB
C
81 lines
3.7 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 benchmark implementation lives in rust/src/benchzstd.rs. Keep this
|
|
* translation unit in the existing C source lists so C build systems retain
|
|
* the public benchzstd.h declarations and validate the C/Rust ABI without
|
|
* defining a second set of BMK_* symbols. */
|
|
|
|
/* This must be included first: it supplies the platform and large-file
|
|
* configuration expected by the program sources. */
|
|
#include "platform.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "benchzstd.h"
|
|
|
|
/*
|
|
* These checks deliberately use the public C declarations. They make the
|
|
* by-value structures consumed by the Rust benchmark implementation fail at
|
|
* compile time if their C layout changes.
|
|
*/
|
|
#define BMK_C_ABI_ASSERT(name, condition) typedef char name[(condition) ? 1 : -1]
|
|
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_result_csize_offset,
|
|
offsetof(BMK_benchResult_t, cSize) == 0);
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_result_cspeed_offset,
|
|
offsetof(BMK_benchResult_t, cSpeed) == sizeof(size_t));
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_result_dspeed_offset,
|
|
offsetof(BMK_benchResult_t, dSpeed)
|
|
== sizeof(size_t) + sizeof(unsigned long long));
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_result_cmem_offset,
|
|
offsetof(BMK_benchResult_t, cMem)
|
|
== sizeof(size_t) + 2 * sizeof(unsigned long long));
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_result_size,
|
|
sizeof(BMK_benchResult_t)
|
|
== 2 * sizeof(size_t) + 2 * sizeof(unsigned long long));
|
|
|
|
BMK_C_ABI_ASSERT(BMK_rust_bench_outcome_tag_offset,
|
|
offsetof(BMK_benchOutcome_t, tag)
|
|
== sizeof(BMK_benchResult_t));
|
|
|
|
BMK_C_ABI_ASSERT(BMK_rust_mode_is_int, sizeof(BMK_mode_t) == sizeof(int));
|
|
BMK_C_ABI_ASSERT(BMK_rust_param_switch_is_int,
|
|
sizeof(ZSTD_ParamSwitch_e) == sizeof(int));
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_mode_offset,
|
|
offsetof(BMK_advancedParams_t, mode) == 0);
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_seconds_offset,
|
|
offsetof(BMK_advancedParams_t, nbSeconds)
|
|
== sizeof(BMK_mode_t));
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_block_offset,
|
|
offsetof(BMK_advancedParams_t, blockSize)
|
|
== sizeof(BMK_mode_t) + sizeof(unsigned));
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_target_block_offset,
|
|
offsetof(BMK_advancedParams_t, targetCBlockSize)
|
|
== sizeof(BMK_mode_t) + sizeof(unsigned) + sizeof(size_t));
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_workers_offset,
|
|
offsetof(BMK_advancedParams_t, nbWorkers)
|
|
== sizeof(BMK_mode_t) + sizeof(unsigned) + 2 * sizeof(size_t));
|
|
BMK_C_ABI_ASSERT(BMK_rust_advanced_row_match_offset,
|
|
offsetof(BMK_advancedParams_t, useRowMatchFinder)
|
|
== offsetof(BMK_advancedParams_t, literalCompressionMode)
|
|
+ sizeof(ZSTD_ParamSwitch_e));
|
|
|
|
BMK_C_ABI_ASSERT(BMK_rust_compression_strategy_is_int,
|
|
sizeof(ZSTD_strategy) == sizeof(int));
|
|
BMK_C_ABI_ASSERT(BMK_rust_compression_params_strategy_offset,
|
|
offsetof(ZSTD_compressionParameters, strategy)
|
|
== 6 * sizeof(unsigned));
|
|
BMK_C_ABI_ASSERT(BMK_rust_compression_params_size,
|
|
sizeof(ZSTD_compressionParameters)
|
|
== 6 * sizeof(unsigned) + sizeof(ZSTD_strategy));
|
|
|
|
#undef BMK_C_ABI_ASSERT
|