Skip to content

Commit

Permalink
Add support for Bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 15, 2024
1 parent d17a7d7 commit ebe88dd
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 9 deletions.
4 changes: 0 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# rules_fuzzing is not yet compatible with Bzlmod.
# Use the experimental version of the flag for Bazel 5 compatibility.
common --noexperimental_enable_bzlmod

# Force the use of Clang for all builds.
build --repo_env=CC=clang

Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.0.1rc1
10 changes: 10 additions & 0 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,13 @@ jobs:
- name: Run regression tests on macOS
run: |
bazel test --verbose_failures --test_output=all //examples/...
bzlmod_examples:
name: Bzlmod examples
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run regression tests on macOS
run: |
cd examples/bzlmod
bazel test --verbose_failures --test_output=all //...
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@

# Bazel-generated files.
/bazel-*
/examples/bzlmod/bazel-*

# Visual Studio Code configuration.
/.vscode

# IntelliSense configuration generated by
# https://github.com/grailbio/bazel-compilation-database
compile_commands.json

# IntelliJ & CLion
.clwb
.ijwb

# The Bzlmod lockfile is platform-dependent with Python and thus hard
# to keep up-to-date in CI. It still speeds up local development.
MODULE.bazel.lock
56 changes: 56 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module(
name = "rules_fuzzing",
# Automatically updated during releases.
version = "0.0.0",
)

# Update to 20230802.1.
bazel_dep(name = "abseil-cpp", version = "20230802.0", repo_name = "com_google_absl")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_python", version = "0.26.0")

bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "re2", version = "2023-11-01", dev_dependency = True)

non_module_dependencies = use_extension("//fuzzing/private:extensions.bzl", "non_module_dependencies")
use_repo(
non_module_dependencies,
"honggfuzz",
"rules_fuzzing_jazzer",
"rules_fuzzing_jazzer_api",
"rules_fuzzing_oss_fuzz",
)

SUPPORTED_PYTHON_VERSIONS = [
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
]

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

[
python.toolchain(
is_default = python_version == SUPPORTED_PYTHON_VERSIONS[-1],
python_version = python_version,
)
for python_version in SUPPORTED_PYTHON_VERSIONS
]

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

[
pip.parse(
extra_pip_args = ["--require-hashes"],
hub_name = "rules_fuzzing_py_deps",
python_version = python_version,
requirements_lock = "//fuzzing:requirements.txt",
)
for python_version in SUPPORTED_PYTHON_VERSIONS
]

use_repo(pip, fuzzing_py_deps = "rules_fuzzing_py_deps")
1 change: 1 addition & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Intentionally left blank as all deps are defined in MODULE.bazel.
18 changes: 18 additions & 0 deletions examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 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
#
# https://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.

common --repo_env=CC=clang
common --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
common --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
common --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan
13 changes: 13 additions & 0 deletions examples/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
load("@rules_fuzzing//fuzzing:java_defs.bzl", "java_fuzz_test")

cc_fuzz_test(
name = "cc_fuzz_test",
srcs = ["cc_fuzz_test.cc"],
)

java_fuzz_test(
name = "java_fuzz_test",
srcs = ["JavaFuzzTest.java"],
target_class = "com.example.JavaFuzzTest",
)
23 changes: 23 additions & 0 deletions examples/bzlmod/JavaFuzzTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 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.

// A plain fuzz target that does nothing.

package com.example;

import com.code_intelligence.jazzer.api.FuzzedDataProvider;

public class JavaFuzzTest {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {}
}
13 changes: 13 additions & 0 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bazel_dep(name = "rules_fuzzing")
local_path_override(
module_name = "rules_fuzzing",
path = "../..",
)

# TODO: Get rid of this.
bazel_dep(name = "rules_python", version = "0.26.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
python_version = "3.12",
)
8 changes: 8 additions & 0 deletions examples/bzlmod/cc_fuzz_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// A plain fuzz target that does nothing (just returns).

#include <cstddef>
#include <cstdint>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}
1 change: 0 additions & 1 deletion examples/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# serve as regression tests. Targets that are expected to crash or hang are
# disabled in the OSS-Fuzz integration using the "no-oss-fuzz" tag.

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//fuzzing:java_defs.bzl", "java_fuzz_test")

filegroup(
Expand Down
20 changes: 20 additions & 0 deletions fuzzing/private/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 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
#
# https://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.

load("//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")

def _non_module_dependencies(_):
rules_fuzzing_dependencies()

non_module_dependencies = module_extension(_non_module_dependencies)
6 changes: 3 additions & 3 deletions fuzzing/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def rules_fuzzing_dependencies(oss_fuzz = True, honggfuzz = True, jazzer = True)
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)
maybe(
http_archive,
Expand Down

0 comments on commit ebe88dd

Please sign in to comment.