rules_cc icon indicating copy to clipboard operation
rules_cc copied to clipboard

Poor error with rule based toolchain capabilities

Open keith opened this issue 11 months ago • 1 comments

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: https://github.com/bazelbuild/rules_cc/blob/96d7d59f1fc928ac78b08e07f1172e5b24fe5dac/cc/toolchains/tool.bzl#L126-L133

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",
)

keith avatar Jan 28 '25 00:01 keith

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

AustinSchuh avatar Jan 29 '25 18:01 AustinSchuh