Skip to content

Add a helper function for rules that need the CC toolchain #14728

@katre

Description

@katre

Currently, rules that require the CC toolchain via toolchain resolution use this syntax:

foo = rule(
    ...
    toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
)

(Possibly with other toolchain types present)

With optional toolchains, the syntax is changing, and will wait on a Bazel release.

We should provide a simple helper function that rules can use to be forward compatible when the new optional toolchains are release:

load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain")

foo = rule(
    ...
    toolchains = [other toolchains] + use_cpp_toolchain(mandatory = True),
)

The implemenation of use_cpp_toolchain will update with Bazel and will either return the bare-string toolchain type (as used currently) or the more complicated config.toolchain_type call. Rules won't need to make changes (beyond changing the value of mandatory if desired).

The only parameter will be mandatory, which will default to True for backwards compatibility.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions