Skip to content

Commit 1d0a512

Browse files
committed
Allow repo_mapping parameter to be disabled
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.
1 parent 977743e commit 1d0a512

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

bindgen/transitive_repositories.bzl

+27-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@
22

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

5+
DEFAULT_REPO_MAPPING = {
6+
"@llvm_zlib": "@zlib",
7+
}
8+
LLVM_TARGETS = ["AArch64", "X86"]
9+
510
# buildifier: disable=unnamed-macro
6-
def rust_bindgen_transitive_dependencies():
7-
"""Declare transitive dependencies needed for bindgen."""
11+
def rust_bindgen_transitive_dependencies(repo_mapping = DEFAULT_REPO_MAPPING):
12+
"""Declare transitive dependencies needed for bindgen.
13+
14+
Args:
15+
repo_mapping: Mapping for renaming repositories created by this function.
16+
The repository names created by this function are undocumented and subject
17+
to change in the future.
18+
"""
819

9-
llvm_configure(
10-
name = "llvm-project",
11-
repo_mapping = {"@llvm_zlib": "@zlib"},
12-
targets = [
13-
"AArch64",
14-
"X86",
15-
],
16-
)
20+
# Bzlmod does not support the `repo_mapping` parameter *at all*, so we have
21+
# to only specify it when requested.
22+
if repo_mapping == None:
23+
llvm_configure(
24+
name = "llvm-project",
25+
targets = LLVM_TARGETS,
26+
)
27+
else:
28+
llvm_repo_name = repo_mapping.get("llvm-project", default = "llvm-project")
29+
llvm_configure(
30+
name = llvm_repo_name,
31+
repo_mapping = repo_mapping,
32+
targets = LLVM_TARGETS,
33+
)
1734

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

0 commit comments

Comments
 (0)