1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Implementation of the pw_cc_feature_constraint rule.""" 15 16load(":providers.bzl", "PwFeatureConstraintInfo", "PwFeatureSetInfo") 17 18visibility("//cc_toolchain") 19 20def _pw_cc_feature_constraint_impl(ctx): 21 all_of = [fp[PwFeatureConstraintInfo] for fp in ctx.attr.all_of] 22 none_of = [ 23 fs[PwFeatureSetInfo].features 24 for fs in ctx.attr.none_of 25 ] 26 none_of.extend([fp.none_of for fp in all_of]) 27 return [PwFeatureConstraintInfo( 28 all_of = depset(transitive = [fp.all_of for fp in all_of]), 29 none_of = depset(transitive = none_of), 30 )] 31 32pw_cc_feature_constraint = rule( 33 implementation = _pw_cc_feature_constraint_impl, 34 attrs = { 35 "all_of": attr.label_list( 36 providers = [PwFeatureConstraintInfo], 37 ), 38 "none_of": attr.label_list( 39 providers = [PwFeatureSetInfo], 40 ), 41 }, 42 provides = [PwFeatureConstraintInfo], 43) 44