xref: /aosp_15_r20/external/pigweed/pw_toolchain_bazel/cc_toolchain/private/unsafe_feature.bzl (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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_unsafe_feature rule."""
15
16load(
17    ":providers.bzl",
18    "PwBuiltinFeatureInfo",
19    "PwFeatureConstraintInfo",
20    "PwFeatureInfo",
21    "PwFeatureSetInfo",
22)
23
24def _pw_cc_unsafe_feature_impl(ctx):
25    feature = PwFeatureInfo(
26        label = ctx.label,
27        name = ctx.attr.feature_name,
28        enabled = False,
29        flag_sets = depset([]),
30        implies_features = depset([]),
31        implies_action_configs = depset([]),
32        requires_any_of = tuple([]),
33        provides = depset([]),
34        known = True,
35        overrides = None,
36    )
37    providers = [
38        feature,
39        PwFeatureSetInfo(features = depset([feature])),
40        PwFeatureConstraintInfo(all_of = depset([feature]), none_of = depset([])),
41    ]
42    if ctx.attr.builtin:
43        providers.append(PwBuiltinFeatureInfo())
44    return providers
45
46pw_cc_unsafe_feature = rule(
47    implementation = _pw_cc_unsafe_feature_impl,
48    attrs = {
49        "builtin": attr.bool(
50            doc = "Whether the feature is builtin, and can be overridden",
51        ),
52        "feature_name": attr.string(
53            mandatory = True,
54            doc = "The name of the feature",
55        ),
56    },
57    provides = [PwFeatureInfo, PwFeatureSetInfo, PwFeatureConstraintInfo],
58    doc = "A declaration that a feature with this name is defined elsewhere.",
59)
60