bazel: apply buildifier
diff --git a/BUILD.bazel b/BUILD.bazel index 11aaa98..84fe9bf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel
@@ -18,21 +18,31 @@ flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc"}, ) -CFLAGS_FOR_GCC = ["-Wall", "-Wwrite-strings", "-Wno-sign-compare", "-DTCMALLOC_DISABLE_HIDDEN_VISIBILITY"] -CXXFLAGS_FOR_GCC = CFLAGS_FOR_GCC + ["-Woverloaded-virtual", "-std=gnu++17", "-fsized-deallocation"] +CFLAGS_FOR_GCC = [ + "-Wall", + "-Wwrite-strings", + "-Wno-sign-compare", + "-DTCMALLOC_DISABLE_HIDDEN_VISIBILITY", +] + +CXXFLAGS_FOR_GCC = CFLAGS_FOR_GCC + [ + "-Woverloaded-virtual", + "-std=gnu++17", + "-fsized-deallocation", +] CXXFLAGS = select({ ":is_msvc": ["/std:c++17 /D_WIN32_WINNT=0x0602"], - "//conditions:default": ["/std:c++17 /D_WIN32_WINNT=0x0602"], # the above doesn't work! + "//conditions:default": ["/std:c++17 /D_WIN32_WINNT=0x0602"], # the above doesn't work! ":is_gcc": CXXFLAGS_FOR_GCC, - ":is_clang": CXXFLAGS_FOR_GCC + ["-Wthread-safety"] + ":is_clang": CXXFLAGS_FOR_GCC + ["-Wthread-safety"], }) CFLAGS = select({ ":is_msvc": ["/D_WIN32_WINNT=0x0602"], "//conditions:default": ["/D_WIN32_WINNT=0x0602"], ":is_gcc": CFLAGS_FOR_GCC, - ":is_clang": CFLAGS_FOR_GCC + ["-Wthread-safety"] + ":is_clang": CFLAGS_FOR_GCC + ["-Wthread-safety"], }) NON_WINDOWS = select({ @@ -49,7 +59,13 @@ cc_library( name = "all_headers", - hdrs = glob(["src/*h", "src/base/*h", "generic-config/*h", "src/gperftools/*h", "src/windows/*h"]), + hdrs = glob([ + "src/*h", + "src/base/*h", + "generic-config/*h", + "src/gperftools/*h", + "src/windows/*h", + ]), copts = CXXFLAGS, ) @@ -57,47 +73,89 @@ name = "run_benchmark", srcs = ["benchmark/run_benchmark.cc"], hdrs = ["benchmark/run_benchmark.h"], - includes = ["generic-config", "src"], - deps = [":trivialre", ":all_headers"], copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + ], + deps = [ + ":all_headers", + ":trivialre", + ], ) cc_binary( name = "basic_benchmark", srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark"], copts = CXXFLAGS, + deps = [":run_benchmark"], ) cc_library( name = "common", - includes = ["generic-config", "src", "src/base"], - copts = CXXFLAGS, srcs = [ - "src/base/logging.cc", - "src/base/sysinfo.cc", "src/base/dynamic_annotations.cc", + "src/base/generic_writer.cc", + "src/base/logging.cc", + "src/base/proc_maps_iterator.cc", "src/base/spinlock.cc", "src/base/spinlock_internal.cc", + "src/base/sysinfo.cc", "src/safe_strerror.cc", - "src/base/generic_writer.cc", - "src/base/proc_maps_iterator.cc", - ] + - select({"@platforms//os:windows": ["src/windows/port.cc", - "src/windows/ia32_modrm_map.cc", - "src/windows/ia32_opcode_map.cc", - "src/windows/mini_disassembler.cc", - "src/windows/preamble_patcher.cc", - "src/windows/preamble_patcher_with_stub.cc"], - "//conditions:default": []}), - linkopts = select({"@platforms//os:windows": ["psapi.lib", "synchronization.lib", "shlwapi.lib"], - "//conditions:default": []}), + ] + select({ + "@platforms//os:windows": [ + "src/windows/ia32_modrm_map.cc", + "src/windows/ia32_opcode_map.cc", + "src/windows/mini_disassembler.cc", + "src/windows/port.cc", + "src/windows/preamble_patcher.cc", + "src/windows/preamble_patcher_with_stub.cc", + ], + "//conditions:default": [], + }), + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], + linkopts = select({ + "@platforms//os:windows": [ + "psapi.lib", + "synchronization.lib", + "shlwapi.lib", + ], + "//conditions:default": [], + }), deps = [":all_headers"], ) cc_library( name = "tcmalloc_minimal", - visibility = ["//visibility:public"], + srcs = [ + "src/central_freelist.cc", + "src/common.cc", + "src/internal_logging.cc", + "src/malloc_extension.cc", + "src/malloc_hook.cc", + "src/memfs_malloc.cc", + "src/page_heap.cc", + "src/sampler.cc", + "src/span.cc", + "src/stack_trace_table.cc", + "src/static_vars.cc", + "src/thread_cache.cc", + "src/thread_cache_ptr.cc", + ] + select({ + "@platforms//os:windows": [ + "src/windows/patch_functions.cc", + "src/windows/system-alloc.cc", + ], + "//conditions:default": [ + "src/system-alloc.cc", + "src/tcmalloc.cc", + ], + }), hdrs = [ "src/gperftools/malloc_extension.h", "src/gperftools/malloc_extension_c.h", @@ -106,126 +164,195 @@ "src/gperftools/nallocx.h", "src/gperftools/tcmalloc.h", ], + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. local_defines = ["NO_TCMALLOC_SAMPLES"], - includes = ["generic-config", "src", "src/base"], - textual_hdrs = select({"@platforms//os:windows": ["src/tcmalloc.cc"], "//conditions:default": []}), - copts = CXXFLAGS, - srcs = [ - "src/common.cc", - "src/internal_logging.cc", - "src/memfs_malloc.cc", - "src/stack_trace_table.cc", - "src/central_freelist.cc", - "src/page_heap.cc", - "src/sampler.cc", - "src/span.cc", - "src/static_vars.cc", - "src/thread_cache.cc", - "src/thread_cache_ptr.cc", - "src/malloc_hook.cc", - "src/malloc_extension.cc"] + - select({"@platforms//os:windows": ["src/windows/patch_functions.cc", "src/windows/system-alloc.cc"], - "//conditions:default": ["src/tcmalloc.cc", "src/system-alloc.cc"]}), + textual_hdrs = select({ + "@platforms//os:windows": ["src/tcmalloc.cc"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ], alwayslink = 1, - deps = [":all_headers", ":common"], ) cc_library( name = "libbacktrace", - copts = CFLAGS, - includes = ["vendor/libbacktrace-integration", "vendor/libbacktrace"], - hdrs = ["vendor/libbacktrace/elf.c", "vendor/libbacktrace/macho.c"], # yes, elf.c is included by file-format.c below and bazel makes us do this srcs = [ "vendor/libbacktrace-integration/file-format.c", "vendor/libbacktrace/dwarf.c", "vendor/libbacktrace/fileline.c", "vendor/libbacktrace/posix.c", + "vendor/libbacktrace/read.c", "vendor/libbacktrace/sort.c", "vendor/libbacktrace/state.c", - "vendor/libbacktrace/read.c"] + - glob(["vendor/libbacktrace-integration/*.h", "vendor/libbacktrace/*.h"]), + ] + glob([ + "vendor/libbacktrace-integration/*.h", + "vendor/libbacktrace/*.h", + ]), + hdrs = [ + "vendor/libbacktrace/elf.c", + "vendor/libbacktrace/macho.c", + ], # yes, elf.c is included by file-format.c below and bazel makes us do this + copts = CFLAGS, + includes = [ + "vendor/libbacktrace", + "vendor/libbacktrace-integration", + ], target_compatible_with = NON_WINDOWS, ) cc_library( name = "symbolize", - includes = ["generic-config", "src", "src/base"], + srcs = [ + "src/symbolize.cc", + "vendor/libbacktrace-integration/backtrace-alloc.cc", + ], copts = CXXFLAGS, - srcs = ["src/symbolize.cc", - "vendor/libbacktrace-integration/backtrace-alloc.cc"], - deps = [":all_headers", ":libbacktrace"], + includes = [ + "generic-config", + "src", + "src/base", + ], target_compatible_with = NON_WINDOWS, + deps = [ + ":all_headers", + ":libbacktrace", + ], ) cc_library( name = "low_level_alloc", - includes = ["generic-config", "src", "src/base"], - copts = CXXFLAGS, srcs = ["src/base/low_level_alloc.cc"], + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], deps = [":all_headers"], ) cc_library( name = "tcmalloc_minimal_debug", - visibility = ["//visibility:public"], - hdrs = ["src/tcmalloc.cc", - "src/gperftools/malloc_extension.h", - "src/gperftools/malloc_extension_c.h", - "src/gperftools/malloc_hook.h", - "src/gperftools/malloc_hook_c.h", - "src/gperftools/nallocx.h", - "src/gperftools/tcmalloc.h", - ], - # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. - local_defines = ["NO_TCMALLOC_SAMPLES"], - includes = ["generic-config", "src", "src/base"], - copts = CXXFLAGS, srcs = [ - "src/common.cc", - "src/internal_logging.cc", - "src/memfs_malloc.cc", - "src/stack_trace_table.cc", "src/central_freelist.cc", + "src/common.cc", + "src/debugallocation.cc", + "src/internal_logging.cc", + "src/malloc_extension.cc", + "src/malloc_hook.cc", + "src/memfs_malloc.cc", "src/page_heap.cc", "src/sampler.cc", "src/span.cc", + "src/stack_trace_table.cc", "src/static_vars.cc", + "src/system-alloc.cc", "src/thread_cache.cc", "src/thread_cache_ptr.cc", - "src/malloc_hook.cc", - "src/malloc_extension.cc", - "src/debugallocation.cc", "src/system-alloc.cc"], - alwayslink = 1, - deps = [":all_headers", ":common", ":symbolize", ":low_level_alloc"], + ], + hdrs = [ + "src/gperftools/malloc_extension.h", + "src/gperftools/malloc_extension_c.h", + "src/gperftools/malloc_hook.h", + "src/gperftools/malloc_hook_c.h", + "src/gperftools/nallocx.h", + "src/gperftools/tcmalloc.h", + "src/tcmalloc.cc", + ], + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], + # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. + local_defines = ["NO_TCMALLOC_SAMPLES"], target_compatible_with = NON_WINDOWS, + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ":low_level_alloc", + ":symbolize", + ], + alwayslink = 1, ) cc_library( name = "stacktrace", - visibility = ["//visibility:public"], + srcs = [ + "src/base/elf_mem_image.cc", + "src/base/vdso_support.cc", + "src/stacktrace.cc", + ], hdrs = ["src/gperftools/stacktrace.h"], - includes = ["generic-config", "src", "src/base"], copts = CXXFLAGS, - srcs = ["src/stacktrace.cc", "src/base/elf_mem_image.cc", "src/base/vdso_support.cc"], - deps = [":all_headers", ":common"], + includes = [ + "generic-config", + "src", + "src/base", + ], + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ], ) cc_binary( name = "tcmalloc_bench", - copts = CXXFLAGS, srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark", ":tcmalloc_minimal"]) + copts = CXXFLAGS, + deps = [ + ":run_benchmark", + ":tcmalloc_minimal", + ], +) cc_binary( name = "tcmalloc_debug_bench", - copts = CXXFLAGS, srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark", ":tcmalloc_minimal_debug"]) + copts = CXXFLAGS, + deps = [ + ":run_benchmark", + ":tcmalloc_minimal_debug", + ], +) cc_library( name = "tcmalloc", - visibility = ["//visibility:public"], + srcs = [ + "src/central_freelist.cc", + "src/common.cc", + "src/emergency_malloc.cc", + "src/heap-checker-stub.cc", + "src/heap-profile-table.cc", + "src/heap-profiler.cc", + "src/internal_logging.cc", + "src/malloc_backtrace.cc", + "src/malloc_extension.cc", + "src/malloc_hook.cc", + "src/memfs_malloc.cc", + "src/page_heap.cc", + "src/sampler.cc", + "src/span.cc", + "src/stack_trace_table.cc", + "src/static_vars.cc", + "src/system-alloc.cc", + "src/tcmalloc.cc", + "src/thread_cache.cc", + "src/thread_cache_ptr.cc", + ], hdrs = [ "src/gperftools/heap-profiler.h", "src/gperftools/malloc_extension.h", @@ -235,139 +362,195 @@ "src/gperftools/nallocx.h", "src/gperftools/tcmalloc.h", ], + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. local_defines = ["ENABLE_EMERGENCY_MALLOC"], - includes = ["generic-config", "src", "src/base"], - copts = CXXFLAGS, - srcs = [ - "src/common.cc", - "src/internal_logging.cc", - "src/memfs_malloc.cc", - "src/stack_trace_table.cc", - "src/central_freelist.cc", - "src/page_heap.cc", - "src/sampler.cc", - "src/span.cc", - "src/static_vars.cc", - "src/thread_cache.cc", - "src/thread_cache_ptr.cc", - "src/malloc_hook.cc", - "src/malloc_extension.cc", - "src/tcmalloc.cc", - "src/system-alloc.cc", - "src/emergency_malloc.cc", - "src/heap-profile-table.cc", - "src/heap-profiler.cc", - "src/malloc_backtrace.cc", - "src/heap-checker-stub.cc", + target_compatible_with = NON_WINDOWS, + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ":low_level_alloc", + ":stacktrace", ], alwayslink = 1, - deps = [":all_headers", ":common", ":low_level_alloc", ":stacktrace"], - target_compatible_with = NON_WINDOWS, ) cc_binary( name = "tcmalloc_full_bench", - copts = CXXFLAGS, srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark", ":tcmalloc"]) + copts = CXXFLAGS, + deps = [ + ":run_benchmark", + ":tcmalloc", + ], +) cc_library( name = "tcmalloc_debug", - visibility = ["//visibility:public"], - hdrs = ["src/tcmalloc.cc", # tcmalloc.cc gets included by debugallocation.cc - "src/gperftools/heap-profiler.h", - "src/gperftools/malloc_extension.h", - "src/gperftools/malloc_extension_c.h", - "src/gperftools/malloc_hook.h", - "src/gperftools/malloc_hook_c.h", - "src/gperftools/nallocx.h", - "src/gperftools/tcmalloc.h", - ], - # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. - local_defines = ["ENABLE_EMERGENCY_MALLOC"], - includes = ["generic-config", "src", "src/base"], - copts = CXXFLAGS, srcs = [ - "src/common.cc", - "src/internal_logging.cc", - "src/memfs_malloc.cc", - "src/stack_trace_table.cc", "src/central_freelist.cc", + "src/common.cc", + "src/debugallocation.cc", + "src/emergency_malloc.cc", + "src/heap-checker-stub.cc", + "src/heap-profile-table.cc", + "src/heap-profiler.cc", + "src/internal_logging.cc", + "src/malloc_backtrace.cc", + "src/malloc_extension.cc", + "src/malloc_hook.cc", + "src/memfs_malloc.cc", "src/page_heap.cc", "src/sampler.cc", "src/span.cc", + "src/stack_trace_table.cc", "src/static_vars.cc", + "src/system-alloc.cc", "src/thread_cache.cc", "src/thread_cache_ptr.cc", - "src/malloc_hook.cc", - "src/malloc_extension.cc", - "src/debugallocation.cc", - "src/system-alloc.cc", - "src/emergency_malloc.cc", - "src/heap-profile-table.cc", - "src/heap-profiler.cc", - "src/malloc_backtrace.cc", - "src/heap-checker-stub.cc", + ], + hdrs = [ + "src/gperftools/heap-profiler.h", + "src/gperftools/malloc_extension.h", + "src/gperftools/malloc_extension_c.h", + "src/gperftools/malloc_hook.h", + "src/gperftools/malloc_hook_c.h", + "src/gperftools/nallocx.h", + "src/gperftools/tcmalloc.h", + "src/tcmalloc.cc", # tcmalloc.cc gets included by debugallocation.cc + ], + copts = CXXFLAGS, + includes = [ + "generic-config", + "src", + "src/base", + ], + # note, bazel thingy is passing NDEBUG automagically in -c opt builds. So we're okay with that. + local_defines = ["ENABLE_EMERGENCY_MALLOC"], + target_compatible_with = NON_WINDOWS, + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ":low_level_alloc", + ":stacktrace", + ":symbolize", ], alwayslink = 1, - deps = [":all_headers", ":common", ":low_level_alloc", ":symbolize", ":stacktrace"], - target_compatible_with = NON_WINDOWS, ) cc_binary( name = "tcmalloc_full_debug_bench", - copts = CXXFLAGS, srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark", ":tcmalloc_debug"]) + copts = CXXFLAGS, + deps = [ + ":run_benchmark", + ":tcmalloc_debug", + ], +) cc_test( name = "tcmalloc_minimal_test", + srcs = [ + "src/tests/tcmalloc_unittest.cc", + "src/tests/testutil.h", + ], copts = CXXFLAGS, - srcs = ["src/tests/tcmalloc_unittest.cc", "src/tests/testutil.h"], - deps = [":all_headers", ":tcmalloc_minimal", "@googletest//:gtest_main"],) + deps = [ + ":all_headers", + ":tcmalloc_minimal", + "@googletest//:gtest_main", + ], +) cc_test( name = "tcmalloc_minimal_debug_test", + srcs = [ + "src/tests/tcmalloc_unittest.cc", + "src/tests/testutil.h", + ], copts = CXXFLAGS, - srcs = ["src/tests/tcmalloc_unittest.cc", "src/tests/testutil.h"], - deps = [":all_headers", ":tcmalloc_minimal_debug", "@googletest//:gtest_main"],) + deps = [ + ":all_headers", + ":tcmalloc_minimal_debug", + "@googletest//:gtest_main", + ], +) cc_test( name = "tcmalloc_test", + srcs = [ + "src/tests/tcmalloc_unittest.cc", + "src/tests/testutil.h", + ], copts = CXXFLAGS, - srcs = ["src/tests/tcmalloc_unittest.cc", "src/tests/testutil.h"], - deps = [":all_headers", ":tcmalloc", "@googletest//:gtest_main"],) + deps = [ + ":all_headers", + ":tcmalloc", + "@googletest//:gtest_main", + ], +) cc_test( name = "tcmalloc_debug_test", + srcs = [ + "src/tests/tcmalloc_unittest.cc", + "src/tests/testutil.h", + ], copts = CXXFLAGS, - srcs = ["src/tests/tcmalloc_unittest.cc", "src/tests/testutil.h"], - deps = [":all_headers", ":tcmalloc_debug", "@googletest//:gtest_main"],) + deps = [ + ":all_headers", + ":tcmalloc_debug", + "@googletest//:gtest_main", + ], +) cc_test( name = "debugallocation_test", + srcs = [ + "src/tests/debugallocation_test.cc", + "src/tests/testutil.h", + ], copts = CXXFLAGS, - srcs = ["src/tests/debugallocation_test.cc", "src/tests/testutil.h"], - deps = [":all_headers", ":tcmalloc_debug", "@googletest//:gtest_main"],) + deps = [ + ":all_headers", + ":tcmalloc_debug", + "@googletest//:gtest_main", + ], +) cc_library( name = "cpu_profiler", - visibility = ["//visibility:public"], - hdrs = ["src/gperftools/profiler.h"], - copts = CXXFLAGS, srcs = [ - "src/profiler.cc", "src/profile-handler.cc", "src/profiledata.cc", + "src/profiler.cc", + ], + hdrs = ["src/gperftools/profiler.h"], + copts = CXXFLAGS, + target_compatible_with = NON_WINDOWS, + visibility = ["//visibility:public"], + deps = [ + ":all_headers", + ":common", + ":stacktrace", ], alwayslink = 1, - deps = [":all_headers", ":stacktrace", ":common"], - target_compatible_with = NON_WINDOWS, ) cc_binary( name = "tcmalloc_full_bench_with_profiler", - copts = CXXFLAGS, srcs = ["benchmark/malloc_bench.cc"], - deps = [":run_benchmark", ":tcmalloc", ":cpu_profiler"]) + copts = CXXFLAGS, + deps = [ + ":cpu_profiler", + ":run_benchmark", + ":tcmalloc", + ], +)
diff --git a/MODULE.bazel b/MODULE.bazel index 1a09e8a..f6e4cfd 100644 --- a/MODULE.bazel +++ b/MODULE.bazel
@@ -1,5 +1,10 @@ -module(name = "gperftools", version = "2.17.2", compatibility_level = 2) +module( + name = "gperftools", + version = "2.17.2", + compatibility_level = 2, +) bazel_dep(name = "rules_cc", version = "0.1.1") bazel_dep(name = "platforms", version = "0.0.11") + bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True)