Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions utils/bazel/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "zlib-ng", version = "2.0.7", repo_name = "llvm_zlib")
bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd")

llvm_repos_extension = use_extension(":extensions.bzl", "llvm_repos_extension")
llvm_repos_extension = use_extension("@llvm-raw//utils/bazel:extensions.bzl", "llvm_repos_extension")
use_repo(
llvm_repos_extension,
"gmp",
Expand All @@ -34,6 +34,5 @@ use_repo(
"vulkan_sdk",
)

llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(name = "llvm-project")
llvm = use_extension("@llvm-raw//utils/bazel:configure.bzl", "llvm")
use_repo(llvm, "llvm-project")
34 changes: 34 additions & 0 deletions utils/bazel/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,37 @@ llvm_configure = repository_rule(
"targets": attr.string_list(default = DEFAULT_TARGETS),
},
)

def _llvm_impl(mctx):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this configure setup needs to be callable multiple times from multiple contexts so that it can view all the repositories from the MODULE.bazel in this repo. this is virtually copied from https://github.com/cerisier/toolchains_llvm_bootstrapped/blob/a6e8188bad743b8fa05be68642edf253811fe9ac/llvm.bzl#L3-L17

the biggest implementation question is how targets should combine, in the current implementation it only respects the root repo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, https://github.com/zml/zml and https://github.com/cerisier/toolchains_llvm_bootstrapped include only a subset of the targets so as to reduce compile times.

targets = {t: True for t in DEFAULT_TARGETS}
for mod in mctx.modules:
if not mod.is_root:
continue
if mod.tags.configure:
targets = {}
for conf in mod.tags.configure:
for target in conf.targets:
targets[target] = True
break

llvm_configure(
name = "llvm-project",
targets = targets.keys(),
)

return mctx.extension_metadata(
reproducible = True,
root_module_direct_deps = "all",
root_module_direct_dev_deps = [],
)

llvm = module_extension(
implementation = _llvm_impl,
tag_classes = {
"configure": tag_class(
attrs = {
"targets": attr.string_list(mandatory = True),
},
),
},
)
29 changes: 29 additions & 0 deletions utils/bazel/examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
strip_prefix = "llvm-project-" + LLVM_COMMIT,
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
)

llvm = use_extension("@llvm-raw//utils/bazel:configure.bzl", "llvm")

# Optionally configure LLVM targets here
# llvm.configure(
# targets = [
# "X86",
# ...
# ],
# )
use_repo(llvm, "llvm-project")
Loading