• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2020 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18# Note: This project creates Rust fuzz targets exclusively
19
20build() {
21  project=$1
22  shift
23  fuzzer_prefix=$1
24  shift
25  fuzz_targets=$1
26  shift
27  PROJECT_DIR=$SRC/$project
28
29  # ensure we get absolute paths for the coverage report
30  cd $PROJECT_DIR
31  crate_src_abspath=`cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root'`
32  while read i; do
33    export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix $i=$crate_src_abspath/$i"
34  done <<< "$(find . -name "*.rs" | cut -d/ -f2 | uniq)"
35
36  cd $PROJECT_DIR/fuzz && cargo fuzz build -O --debug-assertions "$@"
37
38  FUZZ_TARGET_OUTPUT_DIR=$PROJECT_DIR/target/x86_64-unknown-linux-gnu/release
39
40  if [ "x$fuzz_targets" = "x" ]; then
41      fuzz_targets=$PROJECT_DIR/fuzz/fuzz_targets/*.rs
42  fi
43
44  for f in $fuzz_targets; do
45      src_name=$(basename ${f%.*})
46      dst_name=$fuzzer_prefix$src_name
47      cp $FUZZ_TARGET_OUTPUT_DIR/$src_name $OUT/$dst_name
48
49      if [[ -d $SRC/wasmtime/wasmtime-libfuzzer-corpus/$dst_name/ ]]; then
50          zip -jr \
51              $OUT/${dst_name}_seed_corpus.zip \
52              $SRC/wasmtime/wasmtime-libfuzzer-corpus/$dst_name/
53      fi
54
55      cp $SRC/default.options $OUT/$dst_name.options
56  done
57}
58
59# Build with peepmatic in order to enable the related fuzz targets.
60build wasmtime "" "" --features "peepmatic-fuzzing experimental_x64"
61
62build wasm-tools wasm-tools- ""
63build regalloc.rs regalloc- bt bt
64