xref: /aosp_15_r20/external/pigweed/pw_function/BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 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
15load("@bazel_skylib//lib:selects.bzl", "selects")
16load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
17
18package(default_visibility = ["//visibility:public"])
19
20licenses(["notice"])
21
22cc_library(
23    name = "config",
24    hdrs = ["public/pw_function/config.h"],
25    strip_include_prefix = "public",
26    deps = [":config_override"],
27)
28
29label_flag(
30    name = "config_override",
31    build_setting_default = "//pw_build:default_module_config",
32)
33
34cc_library(
35    name = "pw_function",
36    hdrs = ["public/pw_function/function.h"],
37    strip_include_prefix = "public",
38    deps = [
39        ":config",
40        "//pw_assert",
41        "//pw_preprocessor",
42        "//third_party/fuchsia:fit",
43    ],
44)
45
46pw_cc_test(
47    name = "function_test",
48    srcs = ["function_test.cc"],
49    deps = [
50        ":pw_function",
51        "//pw_compilation_testing:negative_compilation_testing",
52    ],
53)
54
55cc_library(
56    name = "pointer",
57    hdrs = [
58        "public/pw_function/internal/static_invoker.h",
59        "public/pw_function/pointer.h",
60    ],
61    strip_include_prefix = "public",
62)
63
64pw_cc_test(
65    name = "pointer_test",
66    srcs = ["pointer_test.cc"],
67    deps = [
68        ":pointer",
69        ":pw_function",
70    ],
71)
72
73cc_library(
74    name = "scope_guard",
75    hdrs = ["public/pw_function/scope_guard.h"],
76    strip_include_prefix = "public",
77)
78
79pw_cc_test(
80    name = "scope_guard_test",
81    srcs = ["scope_guard_test.cc"],
82    deps = [
83        ":pw_function",
84        ":scope_guard",
85    ],
86)
87
88# pw_function config for upstream builds.
89#
90# See https://pigweed.dev/pw_function/#dynamic-allocation for more context.
91alias(
92    name = "upstream_default_config",
93    actual = selects.with_or({
94        (
95            "@platforms//os:android",
96            "@platforms//os:chromiumos",
97            "@platforms//os:fuchsia",
98            "@platforms//os:linux",
99            "@platforms//os:macos",
100            "@platforms//os:windows",
101        ): ":config_for_host",
102        "//conditions:default": "//pw_build:default_module_config",
103    }),
104    visibility = ["//visibility:private"],
105)
106
107cc_library(
108    name = "config_for_host",
109    defines = [
110        "PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION=1",
111    ],
112    visibility = ["//visibility:private"],
113)
114
115filegroup(
116    name = "doxygen",
117    srcs = [
118        "public/pw_function/function.h",
119        "public/pw_function/pointer.h",
120        "public/pw_function/scope_guard.h",
121    ],
122)
123