Skip to content

Commit 43cf380

Browse files
committed
Add .cargo/config.toml for fuzz cfg flags
Set fuzzing, secp256k1_fuzz, and hashes_fuzz cfg flags in fuzz/.cargo/config.toml so they are automatically applied to plain cargo commands (cargo test, cargo run) run from the fuzz directory. Remove the now-redundant RUSTFLAGS from the README crash reproduction examples, the CI cargo test step, and generate_fuzz_coverage.sh. The honggfuzz and cargo-fuzz docs are unchanged because those tools build their own RUSTFLAGS env var (which overrides config.toml) and require the flags to be exported separately. AI tools were used in preparing this commit.
1 parent d830f10 commit 43cf380

4 files changed

Lines changed: 4 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ jobs:
241241
- name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
242242
run: |
243243
cd fuzz
244-
RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz" cargo test --verbose --color always --lib --bins -j8
244+
cargo test --verbose --color always --lib --bins -j8
245245
cargo clean
246246
- name: Run fuzzers
247247
run: cd fuzz && ./ci-fuzz.sh && cd ..

contrib/generate_fuzz_coverage.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ fi
5555
# Create output directory if it doesn't exist
5656
mkdir -p "$OUTPUT_DIR"
5757

58-
export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"
59-
6058
# dont run this command when running in CI
6159
if [ "$OUTPUT_CODECOV_JSON" = "0" ]; then
6260
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"

fuzz/.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["--cfg=fuzzing", "--cfg=secp256k1_fuzz", "--cfg=hashes_fuzz"]

fuzz/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ mkdir -p ./test_cases/$TARGET
134134
echo $HEX | xxd -r -p > ./test_cases/$TARGET/any_filename_works
135135

136136
export RUST_BACKTRACE=1
137-
export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"
138137
cargo test
139138
```
140139

@@ -152,7 +151,7 @@ Alternatively, you can use the `stdin_fuzz` feature to pipe the crash input dire
152151
creating test case files on disk:
153152

154153
```shell
155-
echo -ne '\x2d\x31\x36\x38\x37\x34\x09\x01...' | RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz" cargo run --features stdin_fuzz --bin full_stack_target
154+
echo -ne '\x2d\x31\x36\x38\x37\x34\x09\x01...' | cargo run --features stdin_fuzz --bin full_stack_target
156155
```
157156

158157
Panics will abort the process directly (the crate uses `panic = "abort"`), resulting in a

0 commit comments

Comments
 (0)