mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 22:02:28 +01:00
The `libpfm` in the Bazel central repository uses `make` to build it, which is difficult to integrate with our toolchain. Rather than try to fix all the issues there, it's easy to just add a native Bazel build for the library. I don't know that any of the relevant upstream folks are interested in this kind of build, but it seems easy for us to maintain as a Carbon project build configuration. I've also not tried to port all of the different configurations as a consequence, and only 64-bit x86 and Arm as that seems the only likely architectures we'll care about in the near term. I've kept this using the `bzlmod` stuff as best I can, and I *think* I'm holding all of those pieces correctly, but if not, happy for suggestions on adjustments. The `google_benchmark` package also has an awkward way of enabling `libpfm` support using a top-level `bazel` command line flag. I think this is because of how brittle the Bazel build of `libpfm` is, but I'm not sure. With the new build, it seems easy to patch `google_benchmark` to detect the same conditions as we build `libpfm` under, and enable it there. So I've done this to avoid folks having to pass a command line flag on platforms where it is supported. The result is that we now get really nice CPU counter support in our benchmarks out-of-the-box on Linux x86-64 and AArch64. For example on my Fedora Asahi install on a Mac Mini I get: ```console $ bazel run -c opt --copt=-gmlt //common:hashing_benchmark --run_under="taskset -c 4" -- --benchmark_counters_tabular=true --benchmark_perf_counters=CYCLES,INSTRUCTIONS INFO: Invocation ID: 4aaeb9e9-7df5-4f1f-b56b-c03411790268 INFO: Analyzed target //common:hashing_benchmark (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //common:hashing_benchmark up-to-date: bazel-bin/common/hashing_benchmark INFO: Elapsed time: 0.360s, Critical Path: 0.02s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Running command line: /bin/bash -c 'taskset -c 4 bazel-bin/common/hashing_benchmark '\''--benchmark_counters_tabular=true'\'' '\''--benchmark_perf_counters=CYCLES,INSTRUCTIONS'\''' 2024-01-15T00:10:50-08:00 Running /home/chandlerc/.cache/bazel/_bazel_chandlerc/b686aa8910e0845b88c21d715819b076/execroot/_main/bazel-out/aarch64-opt/bin/common/hashing_benchmark Run on (8 X 2064 MHz CPU s) CPU Caches: L1 Data 64 KiB (x8) L1 Instruction 128 KiB (x8) L2 Unified 4096 KiB (x2) Load Average: 0.01, 0.08, 0.08 -------------------------------------------------------------------------------------------------------------------------------------------------------------- Benchmark Time CPU Iterations CYCLES INSTRUCTIONS bytes_per_second -------------------------------------------------------------------------------------------------------------------------------------------------------------- BM_LatencyHash<RandValues<uint8_t>, CarbonHashBench> 4.11 ns 4.11 ns 170200064 13.1321 9.00587 232.116Mi/s BM_LatencyHash<RandValues<uint8_t>, AbseilHashBench> 4.82 ns 4.82 ns 145643520 15.3657 12.0059 197.946Mi/s BM_LatencyHash<RandValues<uint8_t>, LLVMHashBench> 7.96 ns 7.95 ns 87956480 25.3737 17.0068 119.991Mi/s BM_LatencyHash<RandValues<uint16_t>, CarbonHashBench> 4.11 ns 4.11 ns 170365952 13.1247 9.00587 464.573Mi/s BM_LatencyHash<RandValues<uint16_t>, AbseilHashBench> 5.51 ns 5.51 ns 127568896 17.5578 14.0059 346.225Mi/s BM_LatencyHash<RandValues<uint16_t>, LLVMHashBench> 8.00 ns 7.99 ns 87085056 25.377 17.0068 238.834Mi/s BM_LatencyHash<RandValues<std::pair<uint8_t, uint8_t>>, CarbonHashBench> 4.91 ns 4.90 ns 136013824 15.6456 14.0059 389.006Mi/s BM_LatencyHash<RandValues<std::pair<uint8_t, uint8_t>>, AbseilHashBench> 6.85 ns 6.85 ns 102630400 21.8041 18.0059 278.637Mi/s BM_LatencyHash<RandValues<std::pair<uint8_t, uint8_t>>, LLVMHashBench> 7.57 ns 7.56 ns 92798976 24.1437 20.0068 252.151Mi/s BM_LatencyHash<RandValues<uint32_t>, CarbonHashBench> 4.12 ns 4.12 ns 170229760 13.1272 9.00587 926.444Mi/s BM_LatencyHash<RandValues<uint32_t>, AbseilHashBench> 4.93 ns 4.92 ns 145304576 15.3738 12.0059 775.224Mi/s BM_LatencyHash<RandValues<uint32_t>, LLVMHashBench> 8.11 ns 8.10 ns 87127040 25.373 17.0068 470.98Mi/s ```
179 lines
6.2 KiB
Python
179 lines
6.2 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
"""Bazel modules.
|
|
|
|
If `MODULE.bazel.lock` changes locally, it means the host platform hasn't yet
|
|
been added to the lock file. Running `bazel mod deps` provides a canonical
|
|
update to `MODULE.bazel.lock`; create a PR with those changes in order to
|
|
include the host platform.
|
|
|
|
Platforms tested with GitHub actions are kept up-to-date. Other platforms may
|
|
fall out of sync on dependency changes, and should be updated with a PR the same
|
|
way a platform is added.
|
|
"""
|
|
|
|
module(name = "carbon")
|
|
|
|
http_archive = use_repo_rule(
|
|
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
|
"http_archive",
|
|
)
|
|
|
|
bazel_dep(name = "bazel_skylib", version = "1.5.0")
|
|
bazel_dep(
|
|
name = "abseil-cpp",
|
|
version = "20230802.0",
|
|
repo_name = "com_google_absl",
|
|
)
|
|
bazel_dep(
|
|
name = "re2",
|
|
version = "2023-11-01",
|
|
repo_name = "com_googlesource_code_re2",
|
|
)
|
|
bazel_dep(
|
|
name = "googletest",
|
|
version = "1.14.0.bcr.1",
|
|
repo_name = "com_google_googletest",
|
|
)
|
|
|
|
google_benchmark_version = "1.8.3"
|
|
|
|
bazel_dep(
|
|
name = "google_benchmark",
|
|
version = google_benchmark_version,
|
|
repo_name = "com_github_google_benchmark",
|
|
)
|
|
archive_override(
|
|
module_name = "google_benchmark",
|
|
integrity = "sha256-a8GApX0j1NlRVRn5KwyD1hsFtbqxiJYfNqx7BrDZ6c4=",
|
|
patch_strip = 1,
|
|
patches = ["@//bazel/google_benchmark:0001-Use-libpfm-by-default-on-supported-platforms.patch"],
|
|
strip_prefix = "benchmark-{0}".format(google_benchmark_version),
|
|
urls = ["https://github.com/google/benchmark/archive/refs/tags/v{0}.tar.gz".format(google_benchmark_version)],
|
|
)
|
|
|
|
bazel_dep(
|
|
name = "libpfm",
|
|
# The registry only has an old version. We use that here to avoid a miss but
|
|
# override it with a newer version.
|
|
version = "4.11.0",
|
|
)
|
|
|
|
libpfm_version = "4.13.0"
|
|
|
|
archive_override(
|
|
module_name = "libpfm",
|
|
integrity = "sha256-0YuXdkx1VSjBBR03bjNUXQ62DG6/hWgENoE/pbBMw9E=",
|
|
patch_strip = 1,
|
|
patches = ["@//bazel/libpfm:0001-Introduce-a-simple-native-Bazel-build.patch"],
|
|
strip_prefix = "libpfm-{0}".format(libpfm_version),
|
|
urls = ["https://sourceforge.net/projects/perfmon2/files/libpfm4/libpfm-{0}.tar.gz".format(libpfm_version)],
|
|
)
|
|
|
|
bazel_dep(name = "rules_bison", version = "0.2.2")
|
|
bazel_dep(name = "rules_flex", version = "0.2.1")
|
|
bazel_dep(name = "rules_m4", version = "0.2.3")
|
|
bazel_dep(name = "rules_cc", version = "0.0.9")
|
|
bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
|
|
bazel_dep(
|
|
name = "protobuf",
|
|
version = "21.7",
|
|
repo_name = "com_google_protobuf",
|
|
)
|
|
|
|
libprotobuf_mutator_version = "1.1"
|
|
|
|
http_archive(
|
|
name = "com_google_libprotobuf_mutator",
|
|
build_file = "@//:third_party/libprotobuf_mutator/BUILD.txt",
|
|
sha256 = "fd299fd72c5cf664259d9bd43a72cb74dc6a8b9604d107fe2d2e90885aeb7c16",
|
|
strip_prefix = "libprotobuf-mutator-{0}".format(libprotobuf_mutator_version),
|
|
urls = ["https://github.com/google/libprotobuf-mutator/archive/v{0}.tar.gz".format(libprotobuf_mutator_version)],
|
|
)
|
|
|
|
clang_tidy_version = "d2aecc583d14c9554febeab185833c1e8cce5384"
|
|
|
|
http_archive(
|
|
name = "bazel_clang_tidy",
|
|
patch_args = ["-p1"],
|
|
patches = ["@carbon//bazel/bazel_clang_tidy:0001_Add_hdrs.patch"],
|
|
sha256 = "89c198a9f544beac119bb41904d16d8870686ccb5fe946442c1576934c9e6869",
|
|
strip_prefix = "bazel_clang_tidy-{0}".format(clang_tidy_version),
|
|
urls = ["https://github.com/erenon/bazel_clang_tidy/archive/{0}.tar.gz".format(clang_tidy_version)],
|
|
)
|
|
|
|
bazel_cc_toolchain = use_extension(
|
|
"//bazel/cc_toolchains:clang_configuration.bzl",
|
|
"clang_toolchain_extension",
|
|
)
|
|
use_repo(bazel_cc_toolchain, "bazel_cc_toolchain")
|
|
|
|
register_toolchains("@bazel_cc_toolchain//:all")
|
|
|
|
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
|
|
git_override(
|
|
module_name = "hedron_compile_commands",
|
|
# HEAD as of 2023-12-19.
|
|
commit = "af167878427c469db96444b65f026d064ec62a4f",
|
|
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
|
|
)
|
|
|
|
# Required for llvm-project.
|
|
bazel_dep(name = "platforms", version = "0.0.8")
|
|
bazel_dep(name = "zlib", version = "1.3", repo_name = "llvm_zlib")
|
|
bazel_dep(name = "zstd", version = "1.5.5", repo_name = "llvm_zstd")
|
|
|
|
###############################################################################
|
|
# llvm-project
|
|
###############################################################################
|
|
|
|
# We pin to specific upstream commits and try to track top-of-tree reasonably
|
|
# closely rather than pinning to a specific release.
|
|
# HEAD as of 2024-01-03.
|
|
llvm_project_version = "82e33d6203f62c0be16f8da8d4178e7fa9e790ea"
|
|
|
|
# Load a repository for the raw llvm-project, pre-overlay.
|
|
http_archive(
|
|
name = "llvm-raw",
|
|
build_file_content = "# empty",
|
|
patch_args = ["-p1"],
|
|
patches = [
|
|
"@carbon//bazel/llvm_project:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch",
|
|
"@carbon//bazel/llvm_project:0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch",
|
|
"@carbon//bazel/llvm_project:0003_Add_library_for_clangd.patch",
|
|
],
|
|
sha256 = "402a6dc72452f24ff27ae8157c6d55ea74124de83c57855bbff89b85787fad1c",
|
|
strip_prefix = "llvm-project-{0}".format(llvm_project_version),
|
|
urls = ["https://github.com/llvm/llvm-project/archive/{0}.tar.gz".format(llvm_project_version)],
|
|
)
|
|
|
|
# Apply the overlay to produce llvm-project.
|
|
llvm_project = use_extension(
|
|
"//bazel/llvm_project:llvm_project.bzl",
|
|
"llvm_project",
|
|
)
|
|
use_repo(llvm_project, "llvm-project")
|
|
|
|
###############################################################################
|
|
# Python
|
|
###############################################################################
|
|
|
|
bazel_dep(name = "rules_python", version = "0.27.1")
|
|
|
|
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
|
|
python.toolchain(
|
|
python_version = "3.11",
|
|
)
|
|
use_repo(python, "python_versions")
|
|
|
|
# Create a central repo that knows about the pip dependencies.
|
|
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
|
|
pip.parse(
|
|
hub_name = "py_deps",
|
|
python_version = "3.11",
|
|
requirements_lock = "//github_tools:requirements.txt",
|
|
)
|
|
use_repo(pip, "py_deps")
|