File
Blob: build/wd_cc_benchmark.bzl
| 1 | """wd_cc_benchmark definition""" |
| 2 | |
| 3 | load("@rules_cc//cc:cc_test.bzl", "cc_test") |
| 4 | |
| 5 | def wd_cc_benchmark( |
| 6 | name, |
| 7 | linkopts = [], |
| 8 | deps = [], |
| 9 | tags = [], |
| 10 | visibility = None, |
| 11 | **kwargs): |
| 12 | """Wrapper for cc_binary that sets common attributes and links the benchmark library. |
| 13 | """ |
| 14 | cc_test( |
| 15 | name = name, |
| 16 | defines = ["WD_IS_BENCHMARK"], |
| 17 | # Use shared linkage for benchmarks, matching the approach used for tests. Unfortunately, |
| 18 | # bazel does not support shared linkage on macOS and it is broken on Windows, so only |
| 19 | # enable this on Linux. |
| 20 | linkstatic = select({ |
| 21 | "@platforms//os:linux": 0, |
| 22 | "//conditions:default": 1, |
| 23 | }), |
| 24 | linkopts = linkopts + select({ |
| 25 | "@//:use_dead_strip": ["-Wl,-dead_strip", "-Wl,-no_exported_symbols"], |
| 26 | "//conditions:default": [""], |
| 27 | }), |
| 28 | visibility = visibility, |
| 29 | deps = deps + [ |
| 30 | "@google_benchmark//:benchmark_main", |
| 31 | "//src/workerd/tests:bench-tools", |
| 32 | ], |
| 33 | # use the same malloc we use for server |
| 34 | malloc = "//src/workerd/server:malloc", |
| 35 | tags = ["workerd-benchmark", "google_benchmark"] + tags, |
| 36 | size = "large", |
| 37 | **kwargs |
| 38 | ) |
| 39 | |
| 40 | # generate benchmark report |
| 41 | native.genrule( |
| 42 | name = name + "@benchmark.csv", |
| 43 | outs = [name + ".benchmark.csv"], |
| 44 | srcs = [name], |
| 45 | cmd = "./$(location {}) --benchmark_format=csv > \"$@\"".format(name), |
| 46 | tags = ["off-by-default", "benchmark_report", "workerd-benchmark"], |
| 47 | ) |