Skip to content

Commit

Permalink
pigweed: Fix build by switching to bazel (#11113)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-brough authored Nov 13, 2023
1 parent 1ce0522 commit 521b569
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 202 deletions.
8 changes: 1 addition & 7 deletions projects/pigweed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
################################################################################

FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get install -y git build-essential python

RUN git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git' --depth 1
ENV PATH="${SRC}/depot_tools:${PATH}"

RUN apt-get update && apt-get install -y git build-essential python python3
RUN git clone 'https://pigweed.googlesource.com/pigweed/pigweed' --depth 1

COPY build.sh $SRC/
COPY filter_cipd.py $SRC/
COPY extract_pw_fuzzers.py $SRC/
70 changes: 8 additions & 62 deletions projects/pigweed/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,14 @@
# limitations under the License.
#
################################################################################
cd $SRC/pigweed

# If you ran this script as root against a local checkout, you may need to do
# the following to restore the Pigweed build environment before continuing
# development:
# $ cd $PW_ROOT
# $ sudo rm -rf .cipd/ .python3-env/ out/
# $ git reset --hard
# $ source ./bootstrap.sh

PW_ROOT="$SRC/pigweed"
BUILDROOT="$PW_ROOT/out/oss-fuzz"
mkdir -p $BUILDROOT

# Tweak the ensure file to skip downloading a bunch of build environment pieces
# that we won't use and/or that OSS-Fuzz wants to provide itself.
python $SRC/filter_cipd.py \
--root "$PW_ROOT" \
--json "$PW_ROOT/pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json" \
--excludes \
infra/cmake \
fuchsia/third_party/bazel \
fuchsia/third_party/clang \
infra/go \
pigweed/third_party/protoc-gen-go \
pigweed/third_party/openocd \
fuchsia/rust \
pigweed/third_party/mingw64-x86_64-win32-seh \
pigweed/host_tools \
infra/goma/client \
fuchsia/third_party/qemu \
pigweed/third_party/kythe

# Pigweed checks that it can find these as part of a "sanity check".
mkdir -p "$PW_ROOT/.environment/cipd/pigweed/bin"
for b in arm-none-eabi-gcc bazel bloaty ; do
x="$PW_ROOT/.environment/cipd/pigweed/bin/$b"
if [[ ! -x $x ]] ; then
ln -s "$(which false)" "$x"
fi
done

# Setup the Pigweed build environemnt
set +u
PW_ENVSETUP_QUIET=1 source "$PW_ROOT/bootstrap.sh"
set -u

# -stdlib=libc++ conflicts with the -nostdinc++ used on pw_minimal_cpp_stdlib.
EXTRA_CXXFLAGS="-Wno-unused-command-line-argument"

# Disable UBSan vptr since target built with -fno-rtti.
EXTRA_CXXFLAGS+=" -fno-sanitize=vptr"
EXTRA_CXXFLAGS+=" -fcoverage-compilation-dir=$PW_ROOT"

# Build!
CXXFLAGS="$CXXFLAGS $EXTRA_CXXFLAGS" LDFLAGS="$CXXFLAGS" \
gn gen "$BUILDROOT" \
--root="$PW_ROOT" \
--args="pw_toolchain_OSS_FUZZ_ENABLED=true
pw_toolchain_SANITIZERS=[\"$SANITIZER\"]"
ninja -C "$BUILDROOT" fuzzers

# Use build-generated metadata to identify available fuzzers
python "$SRC/extract_pw_fuzzers.py" --buildroot "$BUILDROOT" --out "$OUT/"
echo "Building project using Bazel wrapper."

export BAZEL_FUZZ_TEST_QUERY="
let all_fuzz_tests = attr(tags, \"fuzz-test\", \"//...\") in
let lang_fuzz_tests = attr(generator_function, \"pw_cc_fuzz_test\", \$all_fuzz_tests) in
\$lang_fuzz_tests - attr(tags, \"no-oss-fuzz\", \$lang_fuzz_tests)
"

bazel_build_fuzz_tests
60 changes: 0 additions & 60 deletions projects/pigweed/extract_pw_fuzzers.py

This file was deleted.

71 changes: 0 additions & 71 deletions projects/pigweed/filter_cipd.py

This file was deleted.

3 changes: 1 addition & 2 deletions projects/pigweed/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ auto_ccs:
- "[email protected]"
sanitizers:
- address
- memory
main_repo: 'https://pigweed.googlesource.com/pigweed/pigweed'
fuzzing_engines:
- afl
- honggfuzz
- libfuzzer

0 comments on commit 521b569

Please sign in to comment.