2
0
Fork 0
mirror of https://github.com/bazelbuild/rules_cc synced 2024-12-03 02:53:18 +00:00
rules_cc/cc/toolchains/feature_set.bzl
Googler 324612d107 Add documentation for cc_toolchain
BEGIN_PUBLIC

Add documentation for `cc_toolchain`

Updates and includes documentation for the `cc_toolchain` rule, fixing some minor typos along the way.

END_PUBLIC

PiperOrigin-RevId: 684051451
Change-Id: I5bb62f22b3fb68e2d233fb85255d1a86bb45a47d
2024-10-09 08:44:04 -07:00

64 lines
1.8 KiB
Python

# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Implementation of the cc_feature_set rule."""
load("//cc/toolchains/impl:collect.bzl", "collect_features")
load(
":cc_toolchain_info.bzl",
"FeatureConstraintInfo",
"FeatureSetInfo",
)
def _cc_feature_set_impl(ctx):
if ctx.attr.features:
fail("Features is a reserved attribute in bazel. cc_feature_set takes `all_of` instead.")
features = collect_features(ctx.attr.all_of)
return [
FeatureSetInfo(label = ctx.label, features = features),
FeatureConstraintInfo(
label = ctx.label,
all_of = features,
none_of = depset([]),
),
]
cc_feature_set = rule(
implementation = _cc_feature_set_impl,
attrs = {
"all_of": attr.label_list(
providers = [FeatureSetInfo],
doc = "A set of features",
),
},
provides = [FeatureSetInfo],
doc = """Defines a set of features.
This may be used by both `cc_feature` and `cc_args` rules, and is effectively a way to express
a logical `AND` operation across multiple required features.
Example:
```
load("//cc/toolchains:feature_set.bzl", "cc_feature_set")
cc_feature_set(
name = "thin_lto_requirements",
all_of = [
":thin_lto",
":opt",
],
)
```
""",
)