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

Poor error with rule based toolchain capabilities #322

Open
keith opened this issue Jan 28, 2025 · 1 comment
Open

Poor error with rule based toolchain capabilities #322

keith opened this issue Jan 28, 2025 · 1 comment
Assignees

Comments

@keith
Copy link
Member

keith commented Jan 28, 2025

When trying to write a toolchain that supports --start-lib, my first attempt at trying to enable this feature was to apply that option to my linker because of this example:

cc_tool(
name = "clang_tool",
src = "@llvm_toolchain//:bin/clang",
# Suppose clang needs libc to run.
data = ["@llvm_toolchain//:lib/x86_64-linux-gnu/libc.so.6"]
tags = ["requires-network"],
capabilities = ["//cc/toolchains/capabilities:supports_pic"],
)

doing this:

cc_tool(
    name = "lld",
    src = select({
        "//constraint:linux_aarch64": "@clang-linux-aarch64//:bin/clang++",
        "//constraint:linux_x86_64": "@clang-linux-x86_64//:bin/clang++",
    }),
    capabilities = [
        "@rules_cc//cc/toolchains/capabilities:supports_start_end_lib",
    ],
    data = [
        ":exec_platform_linker_builtins",
        ":exec_platform_multicall_support_files",
    ],
)

results in this error:

        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/9f9228df1e3a30aece838a611f14f344/external/rules_cc~/cc/toolchains/impl/toolchain_config.bzl", line 54, column 45, in _cc_toolchain_config_impl
                toolchain_config = toolchain_config_info(
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/9f9228df1e3a30aece838a611f14f344/external/rules_cc~/cc/toolchains/impl/toolchain_config_info.bzl", line 183, column 24, in toolchain_config_info
                _validate_toolchain(toolchain_config, fail = fail)
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/9f9228df1e3a30aece838a611f14f344/external/rules_cc~/cc/toolchains/impl/toolchain_config_info.bzl", line 119, column 41, in _validate_toolchain
                known_features = _get_known_features(self.features, capabilities, fail = fail)
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/9f9228df1e3a30aece838a611f14f344/external/rules_cc~/cc/toolchains/impl/toolchain_config_info.bzl", line 63, column 21, in _get_known_features
                fail(_FEATURE_NAME_ERR.format(
Error in fail: The feature name supports_start_end_lib was defined by both @@rules_cc~//cc/toolchains/capabilities:supports_start_end_lib and @@rules_cc~//cc/toolchains/capabilities:supports_start_end_lib.

I'm still not sure how this is supposed to work today, but I was able to hack around this by adding a custom feature to enabled features:

cc_feature(
    name = "supports_start_end_lib",
    feature_name = "supports_start_end_lib",
)
@armandomontanez armandomontanez self-assigned this Jan 29, 2025
@AustinSchuh
Copy link

I just hit this too. It looks like capabilities aren't getting de-duplicated correctly when multiple tools provide the same capability.

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

3 participants