Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot list the same tool twice in a cc_tool_map #235

Open
armandomontanez opened this issue Aug 23, 2024 · 0 comments
Open

Cannot list the same tool twice in a cc_tool_map #235

armandomontanez opened this issue Aug 23, 2024 · 0 comments

Comments

@armandomontanez
Copy link
Contributor

When the same tool is listed twice for different actions in a cc_tool_map, an error occurs:

# ERROR: /private/var/tmp/_bazel_amontanez/e724b21efc8bc19866072fbc72ee5907/external/_main~_repo_rules~llvm_toolchain/BUILD:60:12: Label '@@_main~_repo_rules~llvm_toolchain//:clang' is duplicated in the 'tools' attribute of rule 'default_tools'

Workaround

To work around this limitation, create an alias pointing to the same tool as an intermediate:

cc_tool_map(
    name = "default_tools",
    tools = {
        "@rules_cc//cc/toolchains/actions:assembly_actions": ":asm",
        "@rules_cc//cc/toolchains/actions:c_compile": ":clang",
    },
)

alias(
    name = "asm",
    actual = ":clang",
)

cc_tool(
    name = "clang",
    # ...
)

Root cause

Because Bazel lacks a label_keyed_label_dict, cc_tool_map is implemented by unrolling the passed dictionary into two 1:1 label lists. Bazel emits an error when the same label is listed twice in a label_list, which is what is seen above. For cc_tool_map.tool, it's an error for the same dictionary key to be listed twice, but different keys may point to the same tool. Until Bazel supports a better mechanism for implementing cc_tool_map, please use the workaround above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant