2024-02-27 12:48:53 +00:00
|
|
|
# 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):
|
2024-03-05 22:54:47 +00:00
|
|
|
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)
|
2024-02-27 12:48:53 +00:00
|
|
|
return [
|
|
|
|
FeatureSetInfo(label = ctx.label, features = features),
|
|
|
|
FeatureConstraintInfo(
|
|
|
|
label = ctx.label,
|
|
|
|
all_of = features,
|
|
|
|
none_of = depset([]),
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2024-03-05 22:54:47 +00:00
|
|
|
cc_feature_set = rule(
|
2024-02-27 12:48:53 +00:00
|
|
|
implementation = _cc_feature_set_impl,
|
|
|
|
attrs = {
|
2024-03-05 22:54:47 +00:00
|
|
|
"all_of": attr.label_list(
|
2024-02-27 12:48:53 +00:00
|
|
|
providers = [FeatureSetInfo],
|
|
|
|
doc = "A set of features",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
provides = [FeatureSetInfo],
|
|
|
|
doc = """Defines a set of features.
|
|
|
|
|
2024-10-02 16:09:54 +00:00
|
|
|
This may be used by both `cc_feature` and `cc_args` rules, and is effectively a way to express
|
2024-10-09 15:43:20 +00:00
|
|
|
a logical `AND` operation across multiple required features.
|
2024-10-02 16:09:54 +00:00
|
|
|
|
2024-02-27 12:48:53 +00:00
|
|
|
Example:
|
2024-10-02 16:09:54 +00:00
|
|
|
```
|
|
|
|
load("//cc/toolchains:feature_set.bzl", "cc_feature_set")
|
2024-02-27 12:48:53 +00:00
|
|
|
|
2024-10-02 16:09:54 +00:00
|
|
|
cc_feature_set(
|
|
|
|
name = "thin_lto_requirements",
|
|
|
|
all_of = [
|
|
|
|
":thin_lto",
|
|
|
|
":opt",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
```
|
2024-02-27 12:48:53 +00:00
|
|
|
""",
|
|
|
|
)
|