fix(fuzz): mirror Rust legacy and helper archives

The standalone fuzz Makefile compiled all seven legacy translation units as
C declaration-only shims while building the Rust archive without the matching
legacy features. It also linked the Rust CLI utility implementation nowhere:
programs/util.c is now only an ABI shim, and libregression.a introduces its
UTIL_* references after the existing fuzz archives have been scanned.

Mirror the selected legacy level in the fuzz Rust feature list and archive
cache directory. Build the helpers-only CLI archive for the migrated utility
functions, make every fuzz target depend on it, and place it after
libregression.a so the linker can extract the needed members.

Test Plan:
- `make -C tests/fuzz -j2 sequence_compression_api` -- passed
- `./tests/fuzz/sequence_compression_api tests/fuzz/sequence_compression_api.c` -- passed
- `git diff --cached --check` -- passed
This commit is contained in:
2026-07-18 19:20:48 +02:00
parent bf364cce1c
commit 6ea2ea887f
+38 -4
View File
@@ -68,13 +68,47 @@ RUST_HUF_FEATURE := huf-force-decompress-x2
RUST_BUILD_CONFIG := huf-force-decompress-x2 RUST_BUILD_CONFIG := huf-force-decompress-x2
endif endif
# The fuzz build compiles every legacy translation unit selected by
# libzstd.mk. Those files are declaration-only shims in the Rust migration,
# so mirror the selected C decoder set in the Rust archive as well.
RUST_LEGACY_FEATURES :=
ifneq ($(ZSTD_LEGACY_SUPPORT),0)
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?),0)
RUST_LEGACY_FEATURES := $(addprefix legacy-v0,$(wordlist $(ZSTD_LEGACY_SUPPORT),7,1 2 3 4 5 6 7))
endif
endif
ifneq ($(strip $(RUST_LEGACY_FEATURES)),)
RUST_BUILD_CONFIG := $(RUST_BUILD_CONFIG)-legacy$(ZSTD_LEGACY_SUPPORT)
endif
RUST_FEATURES := $(strip $(RUST_HUF_FEATURE) $(RUST_LEGACY_FEATURES))
RUST_TARGET_DIR := $(RUST_DIR)/target/fuzz/$(RUST_BUILD_CONFIG) RUST_TARGET_DIR := $(RUST_DIR)/target/fuzz/$(RUST_BUILD_CONFIG)
RUST_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \ RUST_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
--target-dir $(RUST_TARGET_DIR) --target-dir $(RUST_TARGET_DIR)
ifneq ($(RUST_HUF_FEATURE),) ifneq ($(RUST_FEATURES),)
RUST_CARGO_FLAGS += --features $(RUST_HUF_FEATURE) RUST_CARGO_FLAGS += --features "$(RUST_FEATURES)"
endif endif
# The shared program utility shim is declaration-only too. Link the same
# helpers-only CLI archive as the normal C tests so fuzz regression drivers can
# resolve UTIL_* without pulling in the parser or fileio backend.
RUST_CLI_DIR := ../../rust/cli
RUST_CLI_MANIFEST := $(RUST_CLI_DIR)/Cargo.toml
RUST_CLI_HELPER_SOURCES := $(RUST_CLI_MANIFEST) $(RUST_CLI_DIR)/Cargo.lock \
$(RUST_CLI_DIR)/src/lib.rs \
$(RUST_DIR)/src/timefn.rs $(RUST_DIR)/src/benchfn.rs \
$(RUST_DIR)/src/datagen.rs $(RUST_DIR)/src/lorem.rs \
$(RUST_DIR)/src/util.rs
RUST_CLI_HELPERS_TARGET_DIR := $(RUST_DIR)/target/fuzz-cli-helpers
RUST_CLI_HELPERS_STATICLIB := $(RUST_CLI_HELPERS_TARGET_DIR)/release/libzstd_cli_rs.a
RUST_CLI_HELPERS_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
--target-dir $(RUST_CLI_HELPERS_TARGET_DIR) \
--no-default-features --features helpers
$(RUST_CLI_HELPERS_STATICLIB): $(RUST_CLI_HELPER_SOURCES)
$(CARGO) build $(RUST_CLI_HELPERS_CARGO_FLAGS)
# Keep a 32-bit C/C++ fuzz invocation from linking a native-width Cargo # Keep a 32-bit C/C++ fuzz invocation from linking a native-width Cargo
# archive. Cross builds may select any supported Cargo target explicitly. # archive. Cross builds may select any supported Cargo target explicitly.
RUST_TARGET ?= RUST_TARGET ?=
@@ -111,7 +145,7 @@ $(RUST_HUF_C_MODE_STAMP): FORCE_RUST_HUF_C_MODE
# Recipes below already append LIB_FUZZING_ENGINE. Preserve user-provided # Recipes below already append LIB_FUZZING_ENGINE. Preserve user-provided
# engines but place the Rust archive ahead of them and after C objects. # engines but place the Rust archive ahead of them and after C objects.
LIB_FUZZING_ENGINE := $(RUST_STATICLIB) $(FUZZING_ENGINE) LIB_FUZZING_ENGINE := $(RUST_STATICLIB) $(FUZZING_ENGINE) $(RUST_CLI_HELPERS_STATICLIB)
PRGDIR = ../../programs PRGDIR = ../../programs
CONTRIBDIR = ../../contrib CONTRIBDIR = ../../contrib
@@ -212,7 +246,7 @@ FUZZ_TARGETS := \
.PHONY: all clean cleanall .PHONY: all clean cleanall
all: libregression.a $(FUZZ_TARGETS) all: libregression.a $(FUZZ_TARGETS)
$(FUZZ_TARGETS): $(RUST_STATICLIB) $(RUST_HUF_C_MODE_STAMP) $(FUZZ_TARGETS): $(RUST_STATICLIB) $(RUST_CLI_HELPERS_STATICLIB) $(RUST_HUF_C_MODE_STAMP)
ifneq ($(filter libregression.a,$(FUZZING_ENGINE)),) ifneq ($(filter libregression.a,$(FUZZING_ENGINE)),)
$(FUZZ_TARGETS): libregression.a $(FUZZ_TARGETS): libregression.a
endif endif