1#!/bin/bash 2 3# Copyright 2020 Google Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17################################################################################ 18 19# If you ran this script as root against a local checkout, you may need to do 20# the following to restore the Pigweed build environment before continuing 21# development: 22# $ cd $PW_ROOT 23# $ sudo rm -rf .cipd/ .python3-env/ out/ 24# $ git reset --hard 25# $ source ./bootstrap.sh 26 27PW_ROOT="$SRC/pigweed" 28BUILDROOT="$PW_ROOT/out/oss-fuzz" 29mkdir -p $BUILDROOT 30 31# Tweak the ensure file to skip downloading a bunch of build environment pieces 32# that we won't use and/or that OSS-Fuzz wants to provide itself. 33python $SRC/filter_cipd.py \ 34 --root "$PW_ROOT" \ 35 --json "$PW_ROOT/pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json" \ 36 --excludes \ 37 infra/cmake \ 38 fuchsia/third_party/bazel \ 39 pigweed/third_party/bloaty-embedded \ 40 fuchsia/third_party/clang \ 41 infra/go \ 42 pigweed/third_party/protoc-gen-go \ 43 pigweed/third_party/openocd \ 44 fuchsia/rust \ 45 pigweed/third_party/mingw64-x86_64-win32-seh \ 46 pigweed/host_tools \ 47 infra/goma/client \ 48 fuchsia/third_party/qemu \ 49 pigweed/third_party/kythe 50 51# Pigweed checks that it can find these as part of a "sanity check". 52mkdir -p "$PW_ROOT/.environment/cipd/pigweed/bin" 53for b in arm-none-eabi-gcc bazel bloaty ; do 54 x="$PW_ROOT/.environment/cipd/pigweed/bin/$b" 55 if [[ ! -x $x ]] ; then 56 ln -s "$(which false)" "$x" 57 fi 58done 59 60# Setup the Pigweed build environemnt 61set +u 62PW_ENVSETUP_QUIET=1 source "$PW_ROOT/bootstrap.sh" 63set -u 64 65# -stdlib=libc++ conflicts with the -nostdinc++ used on pw_minimal_cpp_stdlib. 66EXTRA_CXXFLAGS="-Wno-unused-command-line-argument" 67 68# Disable UBSan vptr since target built with -fno-rtti. 69EXTRA_CXXFLAGS+=" -fno-sanitize=vptr" 70 71# Build! 72CXXFLAGS="$CXXFLAGS $EXTRA_CXXFLAGS" LDFLAGS="$CXXFLAGS" \ 73 gn gen "$BUILDROOT" \ 74 --root="$PW_ROOT" \ 75 --args="pw_toolchain_OSS_FUZZ_ENABLED=true 76 pw_toolchain_SANITIZERS=[\"$SANITIZER\"]" 77ninja -C "$BUILDROOT" fuzzers 78 79# Use build-generated metadata to identify available fuzzers 80python "$SRC/extract_pw_fuzzers.py" --buildroot "$BUILDROOT" --out "$OUT/" 81 82 83