[infra] Add support for rules_fuzzing's java_fuzz_test macro (#5960)

* [infra] Add support for rules_fuzzing's java_fuzz_test macro

* [infra] Update bazelisk for rolling release support

* [infra] Fix C++ stdlib mixing for uninstrumented Bazel targets

The build script for Bazel rules_fuzzing tests did not set the C++
stdlib for uninstrumented C++ binaries, which thus use the system
libstdc++ instead of the libc++ built from source.

* [rules_fuzzing] Add test project for rules_fuzzing's java_fuzz_test
This commit is contained in:
Fabian Meumertzheim 2021-06-28 15:33:38 +02:00 committed by GitHub
parent 5d7cc94d00
commit 84ea9561f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 2 deletions

View File

@ -97,7 +97,7 @@ RUN rustup component add rust-src --toolchain nightly
ENV OSSFUZZ_RUSTPATH /rust
# Install Bazel through Bazelisk, which automatically fetches the latest Bazel version.
ENV BAZELISK_VERSION 1.7.4
ENV BAZELISK_VERSION 1.9.0
RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \
chmod +x /usr/local/bin/bazel

View File

@ -22,10 +22,17 @@
: "${BAZEL_TOOL:=bazel}"
: "${BAZEL_EXTRA_BUILD_FLAGS:=}"
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
BAZEL_LANGUAGE=java
else
BAZEL_LANGUAGE=cc
fi
if [[ -z "${BAZEL_FUZZ_TEST_QUERY:-}" ]]; then
BAZEL_FUZZ_TEST_QUERY="
let all_fuzz_tests = attr(tags, \"${BAZEL_FUZZ_TEST_TAG}\", \"//...\") in
\$all_fuzz_tests - attr(tags, \"${BAZEL_FUZZ_TEST_EXCLUDE_TAG}\", \$all_fuzz_tests)
let lang_fuzz_tests = attr(generator_function, \"^${BAZEL_LANGUAGE}_fuzz_test\$\", \$all_fuzz_tests) in
\$lang_fuzz_tests - attr(tags, \"${BAZEL_FUZZ_TEST_EXCLUDE_TAG}\", \$lang_fuzz_tests)
"
fi
@ -45,6 +52,7 @@ declare -r BAZEL_BUILD_FLAGS=(
"--@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing_oss_fuzz//:oss_fuzz_engine" \
"--@rules_fuzzing//fuzzing:cc_engine_instrumentation=oss-fuzz" \
"--@rules_fuzzing//fuzzing:cc_engine_sanitizer=none" \
"--cxxopt=-stdlib=libc++" \
"--linkopt=-lc++" \
"--action_env=CC=${CC}" "--action_env=CXX=${CXX}" \
${BAZEL_EXTRA_BUILD_FLAGS[*]}

View File

@ -0,0 +1,21 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
RUN git clone https://github.com/bazelbuild/rules_fuzzing.git
WORKDIR $SRC/rules_fuzzing/
COPY build.sh $SRC/

View File

@ -0,0 +1,27 @@
#!/bin/bash -eu
#
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# Due to https://github.com/bazelbuild/bazel/issues/11128, affecting Bazel 4.0
# or earlier, we cannot use the "@rules_fuzzing//" prefix for the label-typed
# cc_engine configuration flag when fuzzing directly the rules_fuzzing workspace.
#
# This is NOT needed for any other Bazel repository that depends on
# rules_fuzzing.
export BAZEL_EXTRA_BUILD_FLAGS="--//fuzzing:cc_engine=@rules_fuzzing_oss_fuzz//:oss_fuzz_engine"
bazel_build_fuzz_tests

View File

@ -0,0 +1,13 @@
homepage: "https://github.com/bazelbuild/rules_fuzzing"
language: jvm
primary_contact: "test@example.com"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefined
# This is a test project.
disabled: true