2
0
Fork 0
mirror of https://github.com/bazelbuild/rules_cc synced 2024-11-29 21:33:43 +00:00
rules_cc/cc/toolchains/feature_set.bzl
Googler 9befdcd90e Remove macros wrapping rules that take in features.
Based on the comments in unknown commit, I created this CL

BEGIN_PUBLIC
Remove macros wrapping rules that take in features.
END_PUBLIC

PiperOrigin-RevId: 612979047
Change-Id: I5690717b164432c9cecebf87ef9dda41f9fa846f
2024-03-05 14:55:21 -08:00

58 lines
1.6 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.
Example:
cc_feature_set(
name = "thin_lto_requirements",
all_of = [
":thin_lto",
":opt",
],
)
""",
)