@@ -195,12 +195,15 @@ rec {
195
195
# Cargo.nix as the key, and the result of calling it as the value.
196
196
#
197
197
# Assumes that your matrix has entries projectName, prNum, rustc, lockFile, src.
198
+ #
199
+ # Note that EVERY INPUT TO THIS FUNCTION MUST BE ADDED TO generatedCargoNix. If it is
200
+ # not, the memoization logic will collapse all the different values for that input
201
+ # into one.
198
202
crate2nixSingleCheckMemo =
199
203
{ projectName
200
204
, prNum
201
205
, rustc
202
206
, lockFile
203
- , features ? [ ]
204
207
, src
205
208
, ...
206
209
} :
@@ -211,7 +214,7 @@ rec {
211
214
} ) ] ;
212
215
} ;
213
216
generatedCargoNix = tools-nix . generatedCargoNix {
214
- name = "${ projectName } -generated-cargo-nix-${ builtins . toString prNum } -${ src . shortId } " ;
217
+ name = "${ projectName } -generated-cargo-nix-${ builtins . toString prNum } -${ src . shortId } - ${ builtins . toString rustc } " ;
215
218
src = src . src ;
216
219
overrideLockFile = lockFile ;
217
220
} ;
@@ -235,7 +238,6 @@ rec {
235
238
echo "rustc: ${ builtins . toString rustc } "
236
239
echo "lockFile: ${ lockFile } "
237
240
echo "Source: ${ builtins . toJSON src } "
238
- echo "Features: ${ builtins . toJSON features } "
239
241
'' ;
240
242
}
241
243
else pkgs . buildRustCrate crate ;
@@ -258,6 +260,78 @@ rec {
258
260
called = calledCargoNix ;
259
261
} ;
260
262
} ;
263
+
264
+ cargoFuzzDrv = {
265
+ normalDrv
266
+ , projectName
267
+ , src
268
+ , nixes
269
+ , fuzzTargets
270
+ } : let
271
+ overlaidPkgs = import <nixpkgs> {
272
+ overlays = [
273
+ ( import ( fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz" ) )
274
+ ] ;
275
+ } ;
276
+ singleFuzzDrv = fuzzTarget : stdenv . mkDerivation {
277
+ name = "fuzz-${ fuzzTarget } " ;
278
+ src = src . src ;
279
+ buildInputs = [
280
+ overlaidPkgs . rust-bin . stable . "1.58.0" . default
281
+ ( import ./honggfuzz-rs.nix { } )
282
+ # Pinned version because of breaking change in args to init_disassemble_info
283
+ nixpkgs . libopcodes_2_38 # for dis-asm.h and bfd.h
284
+ nixpkgs . libunwind # for libunwind-ptrace.h
285
+ ] ;
286
+ phases = [ "unpackPhase" "buildPhase" ] ;
287
+
288
+ buildPhase = ''
289
+ set -x
290
+ export CARGO_HOME=$PWD/cargo
291
+ export HFUZZ_RUN_ARGS="--run_time 300 --exit_upon_crash"
292
+
293
+ cargo -V
294
+ cargo hfuzz version
295
+ echo "Source: ${ builtins . toJSON src } "
296
+ echo "Fuzz target: ${ fuzzTarget } "
297
+
298
+ # honggfuzz rebuilds the world, including itself for some reason, and
299
+ # it expects to be able to build itself in-place. So we need a read/write
300
+ # copy.
301
+ cp -r ${ nixes . generated } /cargo .
302
+ chmod -R +w cargo
303
+
304
+ DEP_DIR=$(grep 'directory =' $CARGO_HOME/config | sed 's/directory = "\(.*\)"/\1/')
305
+ cp -r "$DEP_DIR" vendor-copy/
306
+ chmod +w vendor-copy/
307
+ rm vendor-copy/*honggfuzz*
308
+ cp -rL "$DEP_DIR/"*honggfuzz* vendor-copy/ # -L means copy soft-links as real files
309
+ chmod -R +w vendor-copy/
310
+ # These two lines are just a search-and-replace ... but trying to get sed to replace
311
+ # one string full of slashes with another is an unreadable mess, so easier to just
312
+ # erase the line completely then recreate it with echo.
313
+ sed -i "s/directory = \".*\"//" "$CARGO_HOME/config"
314
+ echo "directory = \"$PWD/vendor-copy\"" >> "$CARGO_HOME/config"
315
+ cat "$CARGO_HOME/config"
316
+ # Done crazy honggfuzz shit
317
+
318
+ pushd fuzz/
319
+ cargo hfuzz run "${ fuzzTarget } "
320
+ popd
321
+
322
+ touch $out
323
+ '' ;
324
+ } ;
325
+ fuzzDrv = overlaidPkgs . linkFarm
326
+ "${ projectName } -${ src . shortId } -fuzz"
327
+ ( ( map ( x : rec {
328
+ name = "fuzz-${ path . name } " ;
329
+ path = singleFuzzDrv x ;
330
+ } ) fuzzTargets ) ++ [ {
331
+ name = "fuzz-normal-tests" ;
332
+ path = normalDrv ;
333
+ } ] ) ;
334
+ in fuzzDrv ;
261
335
}
262
336
263
337
0 commit comments