Skip to content

Commit

Permalink
Allow repo_mapping parameter to be disabled
Browse files Browse the repository at this point in the history
With Bzlmod enabled, `repo_mapping` isn't that useful since repositories
are namespaced under their parents. Unfortunately, Bazel errors out if
you try to use it.

This commit conditionally provides the parameter if needed, but allows
it to be disabled.
  • Loading branch information
jwnrt committed Sep 13, 2024
1 parent 977743e commit 4d74cc8
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions bindgen/transitive_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,38 @@

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

DEFAULT_REPO_MAPPING = {
"@llvm_zlib": "@zlib",
}
LLVM_TARGETS = ["AArch64", "X86"]

# buildifier: disable=unnamed-macro
def rust_bindgen_transitive_dependencies():
"""Generate repositories for transitive dependencies needed by the `bindgen` rules.
Args:
repo_mapping (dict): Mapping for renaming repositories created by this function.
The repository names created by this function are undocumented and subject
to change in the future.
"""

def rust_bindgen_transitive_dependencies(repo_mapping = DEFAULT_REPO_MAPPING):
"""Declare transitive dependencies needed for bindgen."""

llvm_configure(
name = "llvm-project",
repo_mapping = {"@llvm_zlib": "@zlib"},
targets = [
"AArch64",
"X86",
],
)
# Bzlmod does not support the `repo_mapping` parameter *at all*, so we have
# to only specify it when requested.
if repo_mapping == None:
llvm_configure(
name = "llvm-project",
targets = LLVM_TARGETS,
)
else:
llvm_repo_name = repo_mapping.get("llvm-project", default = "llvm-project")
llvm_configure(
name = llvm_repo_name,
repo_mapping = repo_mapping,
targets = LLVM_TARGETS,
)

# Disables optional dependencies for Support like zlib and terminfo. You may
# instead want to configure them using the macros in the corresponding bzl
Expand Down

0 comments on commit 4d74cc8

Please sign in to comment.