xref: /aosp_15_r20/external/bazelbuild-rules_cc/cc/toolchains/impl/external_feature.bzl (revision eed53cd41c5909d05eedc7ad9720bb158fd93452)
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_external_feature rule."""
15
16load(
17    "//cc/toolchains:cc_toolchain_info.bzl",
18    "ArgsListInfo",
19    "FeatureConstraintInfo",
20    "FeatureInfo",
21    "FeatureSetInfo",
22)
23
24visibility([
25    "//cc/toolchains/...",
26    "//tests/rule_based_toolchain/...",
27])
28
29def _cc_external_feature_impl(ctx):
30    feature = FeatureInfo(
31        label = ctx.label,
32        name = ctx.attr.feature_name,
33        enabled = False,
34        args = ArgsListInfo(
35            label = ctx.label,
36            args = (),
37            files = depset([]),
38            by_action = (),
39        ),
40        implies = depset([]),
41        requires_any_of = (),
42        mutually_exclusive = (),
43        external = True,
44        overridable = ctx.attr.overridable,
45        overrides = None,
46    )
47    providers = [
48        feature,
49        FeatureSetInfo(label = ctx.label, features = depset([feature])),
50        FeatureConstraintInfo(
51            label = ctx.label,
52            all_of = depset([feature]),
53            none_of = depset([]),
54        ),
55    ]
56    return providers
57
58cc_external_feature = rule(
59    implementation = _cc_external_feature_impl,
60    attrs = {
61        "feature_name": attr.string(
62            mandatory = True,
63            doc = "The name of the feature",
64        ),
65        "overridable": attr.bool(
66            doc = "Whether the feature can be overridden",
67            mandatory = True,
68        ),
69    },
70    provides = [FeatureInfo, FeatureSetInfo, FeatureConstraintInfo],
71    doc = "A declaration that a feature with this name is defined elsewhere.",
72)
73