1# Copyright 2024 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Implementation of the cc_feature_set rule.""" 15 16load("//cc/toolchains/impl:collect.bzl", "collect_features") 17load( 18 ":cc_toolchain_info.bzl", 19 "FeatureConstraintInfo", 20 "FeatureSetInfo", 21) 22 23def _cc_feature_set_impl(ctx): 24 if ctx.attr.features: 25 fail("Features is a reserved attribute in bazel. cc_feature_set takes `all_of` instead.") 26 features = collect_features(ctx.attr.all_of) 27 return [ 28 FeatureSetInfo(label = ctx.label, features = features), 29 FeatureConstraintInfo( 30 label = ctx.label, 31 all_of = features, 32 none_of = depset([]), 33 ), 34 ] 35 36cc_feature_set = rule( 37 implementation = _cc_feature_set_impl, 38 attrs = { 39 "all_of": attr.label_list( 40 providers = [FeatureSetInfo], 41 doc = "A set of features", 42 ), 43 }, 44 provides = [FeatureSetInfo], 45 doc = """Defines a set of features. 46 47This may be used by both `cc_feature` and `cc_args` rules, and is effectively a way to express 48a logical `AND` operation across multiple required features. 49 50Example: 51``` 52load("//cc/toolchains:feature_set.bzl", "cc_feature_set") 53 54cc_feature_set( 55 name = "thin_lto_requirements", 56 all_of = [ 57 ":thin_lto", 58 ":opt", 59 ], 60) 61``` 62""", 63) 64