Skip to content

Commit 193214e

Browse files
committed
support bazel
1 parent 3348bf9 commit 193214e

File tree

6 files changed

+206
-3
lines changed

6 files changed

+206
-3
lines changed

.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
common --enable_platform_specific_config
2+
3+
build --cxxopt=-std=c++20
4+
5+
# Show everything when running tests.
6+
test --test_output=streamed
7+
8+
build:macos --macos_minimum_os=10.15
9+
build:macos --no@fuzztest//fuzztest:use_riegeli
10+
11+
try-import %workspace%/fuzztest.bazelrc

BUILD.bazel

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
2+
3+
filegroup(
4+
name = "srcs",
5+
srcs = glob(
6+
[
7+
"src/snmalloc/**/*",
8+
"src/test/*.h",
9+
"CMakeLists.txt",
10+
],
11+
),
12+
visibility = ["//visibility:private"],
13+
)
14+
15+
cmake(
16+
name = "snmalloc",
17+
build_args = [
18+
"-j12",
19+
"--parallel",
20+
],
21+
cache_entries = {
22+
"CMAKE_BUILD_TYPE": "Release",
23+
"SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE": "ON",
24+
"SNMALLOC_USE_SELF_VENDORED_STL": "OFF",
25+
},
26+
generate_args = ["-G Ninja"],
27+
lib_source = ":srcs",
28+
out_headers_only = False,
29+
out_shared_libs = [
30+
"libsnmallocshim-checks-memcpy-only.dylib",
31+
"libsnmallocshim-checks.dylib",
32+
"libsnmallocshim.dylib",
33+
],
34+
out_static_libs = [
35+
"libsnmallocshim-static.a",
36+
"libsnmalloc-new-override.a",
37+
],
38+
postfix_script = "ninja",
39+
visibility = ["//visibility:public"],
40+
)
41+
42+
cmake(
43+
name = "snmalloc-rs",
44+
build_args = [
45+
"-j12",
46+
"--parallel",
47+
],
48+
cache_entries = {
49+
"CMAKE_BUILD_TYPE": "Release",
50+
"SNMALLOC_RUST_SUPPORT": "ON",
51+
"SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE": "ON",
52+
"SNMALLOC_USE_SELF_VENDORED_STL": "OFF",
53+
},
54+
generate_args = ["-G Ninja"],
55+
lib_source = ":srcs",
56+
out_headers_only = False,
57+
out_shared_libs = [
58+
"libsnmallocshim-checks-memcpy-only.dylib",
59+
"libsnmallocshim-checks.dylib",
60+
"libsnmallocshim.dylib",
61+
],
62+
out_static_libs = [
63+
"libsnmallocshim-static.a",
64+
"libsnmalloc-new-override.a",
65+
],
66+
postfix_script = "ninja",
67+
visibility = ["//visibility:public"],
68+
)

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,19 +654,24 @@ install(TARGETS EXPORT snmallocConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}
654654
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/snmalloc)
655655

656656
install(DIRECTORY src/snmalloc/aal DESTINATION include/snmalloc)
657-
install(DIRECTORY src/snmalloc/ds DESTINATION include/snmalloc)
658-
install(DIRECTORY src/snmalloc/override DESTINATION include/snmalloc)
659657
install(DIRECTORY src/snmalloc/backend DESTINATION include/snmalloc)
658+
install(DIRECTORY src/snmalloc/backend_helpers DESTINATION include/snmalloc)
659+
install(DIRECTORY src/snmalloc/ds DESTINATION include/snmalloc)
660+
install(DIRECTORY src/snmalloc/ds_aal DESTINATION include/snmalloc)
661+
install(DIRECTORY src/snmalloc/ds_core DESTINATION include/snmalloc)
662+
install(DIRECTORY src/snmalloc/global DESTINATION include/snmalloc)
660663
install(DIRECTORY src/snmalloc/mem DESTINATION include/snmalloc)
664+
install(DIRECTORY src/snmalloc/override DESTINATION include/snmalloc)
661665
install(DIRECTORY src/snmalloc/pal DESTINATION include/snmalloc)
666+
install(DIRECTORY src/snmalloc/stl DESTINATION include/snmalloc)
662667
install(FILES
663668
src/test/measuretime.h
664669
src/test/opt.h
665670
src/test/setup.h
666671
src/test/usage.h
667672
src/test/xoroshiro.h
668673
DESTINATION include/snmalloc/test
669-
)
674+
)
670675
install(FILES src/snmalloc/snmalloc.h;src/snmalloc/snmalloc_core.h;src/snmalloc/snmalloc_front.h DESTINATION include/snmalloc)
671676

672677
install(EXPORT snmallocConfig

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module(name = "snmalloc")
2+
3+
bazel_dep(name = "rules_cc", version = "0.1.1")
4+
bazel_dep(name = "rules_foreign_cc", version = "0.14.0")
5+
bazel_dep(name = "fuzztest", version = "20250214.0")
6+
bazel_dep(name = "googletest", version = "1.16.0")
7+
bazel_dep(name = "abseil-cpp", version = "20250127.1")
8+
single_version_override(
9+
module_name = "abseil-cpp",
10+
version = "20250127.1",
11+
)

fuzzing/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_test")
2+
3+
# will raise `ERROR: AddressSanitizer: SEGV on unknown address` if run without -c opt
4+
# --config=asan adds AddressSanitizer libs
5+
# bazel test -c opt --config=asan //fuzzing:snmalloc_fuzzer
6+
cc_test(
7+
name = "snmalloc_fuzzer",
8+
srcs = ["snmalloc-fuzzer.cpp"],
9+
copts = [
10+
"-fexperimental-library", # needed for std::execution::unseq,
11+
"-fsanitize=address",
12+
],
13+
defines = [
14+
"SNMALLOC_USE_WAIT_ON_ADDRESS=0",
15+
"ADDRESS_SANITIZER",
16+
],
17+
linkstatic = True,
18+
malloc = "//:snmalloc",
19+
deps = [
20+
"@fuzztest//fuzztest",
21+
"@fuzztest//fuzztest:fuzztest_gtest_main",
22+
],
23+
)

fuzztest.bazelrc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
### DO NOT EDIT. Generated file.
2+
#
3+
# To regenerate, run the following from your project's workspace:
4+
#
5+
# bazel run @com_google_fuzztest//bazel:setup_configs > fuzztest.bazelrc
6+
#
7+
# And don't forget to add the following to your project's .bazelrc:
8+
#
9+
# try-import %workspace%/fuzztest.bazelrc
10+
11+
### Common options.
12+
#
13+
# Do not use directly.
14+
15+
# Standard define for \"ifdef-ing\" any fuzz test specific code.
16+
build:fuzztest-common --copt=-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
17+
18+
# In fuzz tests, we want to catch assertion violations even in optimized builds.
19+
build:fuzztest-common --copt=-UNDEBUG
20+
21+
# Enable libc++ assertions.
22+
# See https://libcxx.llvm.org/UsingLibcxx.html#enabling-the-safe-libc-mode
23+
build:fuzztest-common --copt=-D_LIBCPP_ENABLE_ASSERTIONS=1
24+
25+
### ASan (Address Sanitizer) build configuration.
26+
#
27+
# Use with: --config=asan
28+
29+
build:asan --linkopt=-fsanitize=address
30+
build:asan --copt=-fsanitize=address
31+
32+
# We rely on the following flag instead of the compiler provided
33+
# __has_feature(address_sanitizer) to know that we have an ASAN build even in
34+
# the uninstrumented runtime.
35+
build:asan --copt=-DADDRESS_SANITIZER
36+
37+
### FuzzTest build configuration.
38+
#
39+
# Use with: --config=fuzztest
40+
#
41+
# Note that this configuration includes the ASan configuration.
42+
43+
build:fuzztest --config=asan
44+
build:fuzztest --config=fuzztest-common
45+
46+
# Link statically.
47+
build:fuzztest --dynamic_mode=off
48+
49+
# We apply coverage tracking instrumentation to everything but Centipede and the
50+
# FuzzTest framework itself (including GoogleTest and GoogleMock).
51+
build:fuzztest --copt=-fsanitize-coverage=inline-8bit-counters,trace-cmp,pc-table
52+
build:fuzztest --per_file_copt=common/.*,fuzztest/.*,centipede/.*,-centipede/.*fuzz_target,googletest/.*,googlemock/.*@-fsanitize-coverage=0
53+
54+
### Experimental FuzzTest build configuration.
55+
#
56+
# Use with: --config=fuzztest-experimental
57+
#
58+
# Use this instead of --config=fuzztest when building test binaries to run with
59+
# Centipede. Eventually, this will be consolidated with --config=fuzztest.
60+
# Note that this configuration doesn't include the ASan configuration. If you
61+
# want to use both, you can use --config=fuzztest-experimental --config=asan.
62+
63+
build:fuzztest-experimental --config=fuzztest-common
64+
build:fuzztest-experimental --@com_google_fuzztest//fuzztest:centipede_integration
65+
66+
# Generate line tables for debugging.
67+
build:fuzztest-experimental --copt=-gline-tables-only
68+
build:fuzztest-experimental --strip=never
69+
70+
# Prevent memcmp & co from being inlined.
71+
build:fuzztest-experimental --copt=-fno-builtin
72+
73+
# Disable heap checking.
74+
build:fuzztest-experimental --copt=-DHEAPCHECK_DISABLE
75+
76+
# Link statically.
77+
build:fuzztest-experimental --dynamic_mode=off
78+
79+
# We apply coverage tracking instrumentation to everything but Centipede and the
80+
# FuzzTest framework itself (including GoogleTest and GoogleMock).
81+
# TODO(b/374840534): Add -fsanitize-coverage=control-flow once we start building
82+
# with clang 16+.
83+
build:fuzztest-experimental --copt=-fsanitize-coverage=trace-pc-guard,pc-table,trace-loads,trace-cmp
84+
build:fuzztest-experimental --per_file_copt=common/.*,fuzztest/.*,centipede/.*,-centipede/.*fuzz_target,googletest/.*,googlemock/.*@-fsanitize-coverage=0
85+

0 commit comments

Comments
 (0)