blob: 1e11bc953aa59c6fac2a5ba22f8f56fd594ddcd0 [file] [log] [blame]
# 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_external_feature rule."""
load(
"//cc/toolchains:cc_toolchain_info.bzl",
"ArgsListInfo",
"FeatureConstraintInfo",
"FeatureInfo",
"FeatureSetInfo",
)
visibility([
"//cc/toolchains/...",
"//tests/rule_based_toolchain/...",
])
def _cc_external_feature_impl(ctx):
feature = FeatureInfo(
label = ctx.label,
name = ctx.attr.feature_name,
enabled = False,
args = ArgsListInfo(
label = ctx.label,
args = (),
files = depset([]),
by_action = (),
),
implies = depset([]),
requires_any_of = (),
mutually_exclusive = (),
external = True,
overridable = ctx.attr.overridable,
overrides = None,
allowlist_include_directories = depset(),
)
providers = [
feature,
FeatureSetInfo(label = ctx.label, features = depset([feature])),
FeatureConstraintInfo(
label = ctx.label,
all_of = depset([feature]),
none_of = depset([]),
),
]
return providers
cc_external_feature = rule(
implementation = _cc_external_feature_impl,
attrs = {
"feature_name": attr.string(
mandatory = True,
doc = "The name of the feature",
),
"overridable": attr.bool(
doc = "Whether the feature can be overridden",
mandatory = True,
),
},
provides = [FeatureInfo, FeatureSetInfo, FeatureConstraintInfo],
doc = "A declaration that a feature with this name is defined elsewhere.",
)