diff options
-rw-r--r-- | bazel/cc.bzl | 25 | ||||
-rw-r--r-- | examples/BUILD.bazel | 14 | ||||
-rw-r--r-- | examples/src/main/native/BUILD.bazel | 8 |
3 files changed, 36 insertions, 11 deletions
diff --git a/bazel/cc.bzl b/bazel/cc.bzl index 33418934..ebf7de58 100644 --- a/bazel/cc.bzl +++ b/bazel/cc.bzl @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@rules_cc//cc:defs.bzl", "cc_binary") + def _add_cxxopt_std_17_impl(settings, attr): return { "//command_line_option:cxxopt": settings["//command_line_option:cxxopt"] + ["-std=c++17"], @@ -66,3 +68,26 @@ def cc_17_library(name, visibility = None, **kwargs): library = library_name, visibility = visibility, ) + +# Workaround for https://github.com/bazelbuild/bazel/issues/11082 +# By explicitly setting the name of a cc_binary and selecting based on the +# platform, the resulting shared object will have the correct extension on both +# Linux and macOS. +def cc_shared_library(name, visibility = None, **kwargs): + # Linux + linux_name = "lib%s.so" % name + cc_binary( + name = linux_name, + linkshared = True, + visibility = visibility, + **kwargs + ) + + # macOS + osx_name = "lib%s.dylib" % name + cc_binary( + name = osx_name, + linkshared = True, + visibility = visibility, + **kwargs + ) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 8fde0191..53b01fbc 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -18,10 +18,11 @@ java_fuzz_target_test( srcs = [ "src/main/java/com/example/ExampleFuzzerWithNative.java", ], - native_libs = ["//examples/src/main/native:native_asan"], + native_libs = [ + "//examples/src/main/native:libnative_asan.dylib", + "//examples/src/main/native:libnative_asan.so", + ], sanitizer = "address", - # Bazel creates shared libraries with an incorrect extension on macOS. - tags = ["broken-on-darwin"], target_class = "com.example.ExampleFuzzerWithNative", ) @@ -30,10 +31,11 @@ java_fuzz_target_test( srcs = [ "src/main/java/com/example/ExampleFuzzerWithNative.java", ], - native_libs = ["//examples/src/main/native:native_ubsan"], + native_libs = [ + "//examples/src/main/native:libnative_ubsan.dylib", + "//examples/src/main/native:libnative_ubsan.so", + ], sanitizer = "undefined", - # Bazel creates shared libraries with an incorrect extension on macOS. - tags = ["broken-on-darwin"], target_class = "com.example.ExampleFuzzerWithNative", ) diff --git a/examples/src/main/native/BUILD.bazel b/examples/src/main/native/BUILD.bazel index df24bb37..32358891 100644 --- a/examples/src/main/native/BUILD.bazel +++ b/examples/src/main/native/BUILD.bazel @@ -1,6 +1,6 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") +load("//bazel:cc.bzl", "cc_shared_library") -cc_binary( +cc_shared_library( name = "native_asan", srcs = [ "com_example_ExampleFuzzerWithNative.cpp", @@ -12,14 +12,13 @@ cc_binary( linkopts = [ "-fsanitize=fuzzer-no-link,address", ], - linkshared = True, visibility = ["//examples:__pkg__"], deps = [ "@bazel_tools//tools/jdk:jni", ], ) -cc_binary( +cc_shared_library( name = "native_ubsan", srcs = [ "com_example_ExampleFuzzerWithNative.cpp", @@ -34,7 +33,6 @@ cc_binary( linkopts = [ "-fsanitize=fuzzer-no-link,undefined", ], - linkshared = True, visibility = ["//examples:__pkg__"], deps = [ "@bazel_tools//tools/jdk:jni", |