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

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

Closed
katre opened this issue Feb 4, 2022 · 0 comments
Closed

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

katre opened this issue Feb 4, 2022 · 0 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@katre
Copy link
Member

katre commented Feb 4, 2022

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.

@katre katre added type: feature request P1 I'll work on this now. (Assignee required) team-Rules-CPP Issues for C++ rules labels Feb 4, 2022
@katre katre self-assigned this Feb 4, 2022
katre added a commit to katre/bazel that referenced this issue Feb 7, 2022
Fixes bazelbuild#14728, part of bazelbuild#14727.

Rules can begin using this as soon as it is released (hopefully in Bazel
5.1), and then future versions of Bazel will update the functionality as
optional toolchains are added and C++ rules are updated to use them.
fmeum pushed a commit to fmeum/bazel that referenced this issue Feb 11, 2022
Fixes bazelbuild#14728, part of bazelbuild#14727.

Rules can begin using this as soon as it is released (hopefully in Bazel
5.1), and then future versions of Bazel will update the functionality as
optional toolchains are added and C++ rules are updated to use them.

Closes bazelbuild#14742.

PiperOrigin-RevId: 427931123
bazel-io pushed a commit that referenced this issue Feb 11, 2022
Part of #14728.

PiperOrigin-RevId: 428001400
Wyverald pushed a commit that referenced this issue Feb 14, 2022
…14795)

Fixes #14728, part of #14727.

Rules can begin using this as soon as it is released (hopefully in Bazel
5.1), and then future versions of Bazel will update the functionality as
optional toolchains are added and C++ rules are updated to use them.

Closes #14742.

PiperOrigin-RevId: 427931123

Co-authored-by: John Cater <jcater@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant