[llvm] [bazel] Add potential bzlmod inclusion example (PR #173124)
Matt Clarkson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 8 05:08:50 PST 2026
================
@@ -0,0 +1,29 @@
+# Replace with the LLVM commit you want to use.
+LLVM_COMMIT = "2d1bc9f5a212dc4c8fa14a5741af2a7a5e60ff36"
+
+# The easiest way to calculate this for a new commit is to set it to empty and
+# then run a bazel build and it will report the digest necessary to cache the
+# archive and make the build reproducible.
+LLVM_INTEGRITY = "sha256-KST3jta9pEHT0igBUxNaUoJysbefc0yBJ22UEzWcINs="
+
+bazel_dep(name = "llvm-raw")
+archive_override(
+ module_name = "llvm-raw",
+ integrity = LLVM_INTEGRITY,
+ patch_cmds = [
+ "cat utils/bazel/MODULE.bazel | grep -v '\"llvm-raw\"' | sed 's|llvm-project-overlay|llvm-raw|g' > MODULE.bazel",
+ ],
----------------
mattyclarkson wrote:
This will only work for the root repository as overrides do not work transitively.
My suggestion is that we create the extension _outside_ of this project, maybe at `bazel-contrib/llvm-project` that does:
```py
# Bikeshedding welcome on names, API, etc
bazel_dep(name = "llvm-project", version = "1.0.0")
llvm = use_extension("@llvm-project//:extension.bzl", llvm)
llvm.download(
version = "21.0.1", # Could support semantic version modifiers?
targets = ["..."],
# template = "https://github.com/llvm/llvm-project/archive/{version}.tar.gz",
# integrity = "...",
)
use_repo(llvm, llvm = "llvm-21.0.1") # `bazel mod tidy` to generate
# Use `@llvm//clang`, etc
```
This would have the following benefits:
- Bazel would initially only download a thin Bazel module that contains the extension
- The extension can collapse LLVM version downloads across the graph
- It could combine repositories that have the same version and target subsets
- Modules can used different versions of LLVM across the graph
Underneath, the extension would modify, hermetically, the downloaded repository to move the `MODULE.bazel` and configure the correct targets.
My feeling is that most projects will want to have a particular LLVM version rather than collapsing to a single LLVM version across the `bzlmod` graph?
https://github.com/llvm/llvm-project/pull/173124
More information about the llvm-commits
mailing list