bazelbuild/rules_cc

Toolchain rules: legacy features need to be explicitly enabled to create a working toolchain

armandomontanez opened this issue · 0 comments

When creating a rule-based toolchain, legacy features must be explicitly enabled in order for tool invocations to be correctly constructed. This can be done in one of two ways:

  1. List implies on a cc_action_type_config:
cc_action_type_config(
    name = "arm-none-eabi-ar",
    action_types = ["@rules_cc//cc/toolchains/actions:ar_actions"],
    tools = [":arm-none-eabi-ar_tool"],
    implies = [
        "@rules_cc//cc/toolchains/features/legacy:archiver_flags",
        "@rules_cc//cc/toolchains/features/legacy:linker_param_file",
    ]
)
  1. Create a custom feature that implies legacy features across a cc_toolchain.
cc_feature(
    name = "legacy_features",
    args = [],
    enabled = True,
    feature_name = "force_legacy_features",
    implies = [
        "@rules_cc//cc/toolchains/features/legacy:archiver_flags",
        "@rules_cc//cc/toolchains/features/legacy:linker_param_file",
        # ...
        "@rules_cc//cc/toolchains/features/legacy:fission_support",
        "@rules_cc//cc/toolchains/features/legacy:sysroot",
    ],
)

cc_toolchain(
    name = "my_toolchain",
    # ...
    toolchain_features = [
        "@pico-sdk//bazel/toolchain:legacy_features",
    ],
)

This is a bit of a stumbling block, since it's not exactly obvious which of these legacy features are required to construct a working toolchain, or how to re-implement these features correctly in a way that makes Bazel happy.

There's a few potential paths to pursue here:

  1. Have an option on cc_toolchain that enables all legacy features.
  2. Provide features (or better, raw cc_args /cc_args_list) that implement the required flags, and either provide guidance on how to comprehensively build a toolchain that includes the required arguments or make the toolchain rules infer the required args if no args are explicitly provided.