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