Skip to content

Commit ebe88dd

Browse files
committed
Add support for Bzlmod
1 parent d17a7d7 commit ebe88dd

File tree

14 files changed

+175
-9
lines changed

14 files changed

+175
-9
lines changed

.bazelrc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# rules_fuzzing is not yet compatible with Bzlmod.
16-
# Use the experimental version of the flag for Bazel 5 compatibility.
17-
common --noexperimental_enable_bzlmod
18-
1915
# Force the use of Clang for all builds.
2016
build --repo_env=CC=clang
2117

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.0.0
1+
7.0.1rc1

.github/workflows/bazel_test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ jobs:
169169
- name: Run regression tests on macOS
170170
run: |
171171
bazel test --verbose_failures --test_output=all //examples/...
172+
bzlmod_examples:
173+
name: Bzlmod examples
174+
runs-on: ubuntu-20.04
175+
steps:
176+
- name: Checkout repository
177+
uses: actions/checkout@v2
178+
- name: Run regression tests on macOS
179+
run: |
180+
cd examples/bzlmod
181+
bazel test --verbose_failures --test_output=all //...

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414

1515
# Bazel-generated files.
1616
/bazel-*
17+
/examples/bzlmod/bazel-*
1718

1819
# Visual Studio Code configuration.
1920
/.vscode
2021

2122
# IntelliSense configuration generated by
2223
# https://github.com/grailbio/bazel-compilation-database
2324
compile_commands.json
25+
26+
# IntelliJ & CLion
27+
.clwb
28+
.ijwb
29+
30+
# The Bzlmod lockfile is platform-dependent with Python and thus hard
31+
# to keep up-to-date in CI. It still speeds up local development.
32+
MODULE.bazel.lock

MODULE.bazel

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module(
2+
name = "rules_fuzzing",
3+
# Automatically updated during releases.
4+
version = "0.0.0",
5+
)
6+
7+
# Update to 20230802.1.
8+
bazel_dep(name = "abseil-cpp", version = "20230802.0", repo_name = "com_google_absl")
9+
bazel_dep(name = "bazel_skylib", version = "1.5.0")
10+
bazel_dep(name = "platforms", version = "0.0.8")
11+
bazel_dep(name = "rules_python", version = "0.26.0")
12+
13+
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
14+
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True, repo_name = "com_google_googletest")
15+
bazel_dep(name = "re2", version = "2023-11-01", dev_dependency = True)
16+
17+
non_module_dependencies = use_extension("//fuzzing/private:extensions.bzl", "non_module_dependencies")
18+
use_repo(
19+
non_module_dependencies,
20+
"honggfuzz",
21+
"rules_fuzzing_jazzer",
22+
"rules_fuzzing_jazzer_api",
23+
"rules_fuzzing_oss_fuzz",
24+
)
25+
26+
SUPPORTED_PYTHON_VERSIONS = [
27+
"3.8",
28+
"3.9",
29+
"3.10",
30+
"3.11",
31+
"3.12",
32+
]
33+
34+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
35+
36+
[
37+
python.toolchain(
38+
is_default = python_version == SUPPORTED_PYTHON_VERSIONS[-1],
39+
python_version = python_version,
40+
)
41+
for python_version in SUPPORTED_PYTHON_VERSIONS
42+
]
43+
44+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
45+
46+
[
47+
pip.parse(
48+
extra_pip_args = ["--require-hashes"],
49+
hub_name = "rules_fuzzing_py_deps",
50+
python_version = python_version,
51+
requirements_lock = "//fuzzing:requirements.txt",
52+
)
53+
for python_version in SUPPORTED_PYTHON_VERSIONS
54+
]
55+
56+
use_repo(pip, fuzzing_py_deps = "rules_fuzzing_py_deps")

WORKSPACE.bzlmod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Intentionally left blank as all deps are defined in MODULE.bazel.

examples/bzlmod/.bazelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
common --repo_env=CC=clang
16+
common --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
17+
common --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
18+
common --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan

examples/bzlmod/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
2+
load("@rules_fuzzing//fuzzing:java_defs.bzl", "java_fuzz_test")
3+
4+
cc_fuzz_test(
5+
name = "cc_fuzz_test",
6+
srcs = ["cc_fuzz_test.cc"],
7+
)
8+
9+
java_fuzz_test(
10+
name = "java_fuzz_test",
11+
srcs = ["JavaFuzzTest.java"],
12+
target_class = "com.example.JavaFuzzTest",
13+
)

examples/bzlmod/JavaFuzzTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// A plain fuzz target that does nothing.
16+
17+
package com.example;
18+
19+
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
20+
21+
public class JavaFuzzTest {
22+
public static void fuzzerTestOneInput(FuzzedDataProvider data) {}
23+
}

examples/bzlmod/MODULE.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bazel_dep(name = "rules_fuzzing")
2+
local_path_override(
3+
module_name = "rules_fuzzing",
4+
path = "../..",
5+
)
6+
7+
# TODO: Get rid of this.
8+
bazel_dep(name = "rules_python", version = "0.26.0")
9+
10+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
11+
python.toolchain(
12+
python_version = "3.12",
13+
)

0 commit comments

Comments
 (0)