• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("@rules_cc//cc:cc_library.bzl", "cc_library")
17load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
18load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
19load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
20
21package(
22    default_visibility = ["//visibility:public"],
23)
24
25licenses(["notice"])
26
27cc_library(
28    name = "config",
29    hdrs = ["public/pw_function/config.h"],
30    strip_include_prefix = "public",
31    tags = ["noclangtidy"],
32    deps = [":config_override"],
33)
34
35label_flag(
36    name = "config_override",
37    build_setting_default = "//pw_build:default_module_config",
38)
39
40cc_library(
41    name = "pw_function",
42    hdrs = ["public/pw_function/function.h"],
43    strip_include_prefix = "public",
44    deps = [
45        ":config",
46        "//pw_preprocessor",
47        "//third_party/fuchsia:fit",
48    ],
49)
50
51pw_cc_test(
52    name = "function_test",
53    srcs = ["function_test.cc"],
54    deps = [
55        ":pw_function",
56        "//pw_compilation_testing:negative_compilation_testing",
57        "//pw_polyfill",
58    ],
59)
60
61cc_library(
62    name = "pointer",
63    hdrs = [
64        "public/pw_function/internal/static_invoker.h",
65        "public/pw_function/pointer.h",
66    ],
67    strip_include_prefix = "public",
68    tags = ["noclangtidy"],
69)
70
71pw_cc_test(
72    name = "pointer_test",
73    srcs = ["pointer_test.cc"],
74    deps = [
75        ":pointer",
76        ":pw_function",
77    ],
78)
79
80cc_library(
81    name = "scope_guard",
82    hdrs = ["public/pw_function/scope_guard.h"],
83    strip_include_prefix = "public",
84)
85
86pw_cc_test(
87    name = "scope_guard_test",
88    srcs = ["scope_guard_test.cc"],
89    deps = [
90        ":pw_function",
91        ":scope_guard",
92    ],
93)
94
95# pw_function config for upstream builds.
96#
97# See https://pigweed.dev/pw_function/#dynamic-allocation for more context.
98alias(
99    name = "upstream_default_config",
100    actual = selects.with_or({
101        (
102            "@platforms//os:android",
103            "@platforms//os:chromiumos",
104            "@platforms//os:fuchsia",
105            "@platforms//os:linux",
106            "@platforms//os:macos",
107            "@platforms//os:windows",
108        ): ":config_for_host",
109        "//conditions:default": "//pw_build:default_module_config",
110    }),
111    visibility = ["//visibility:private"],
112)
113
114cc_library(
115    name = "config_for_host",
116    defines = [
117        "PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION=1",
118    ],
119    visibility = ["//visibility:private"],
120)
121
122filegroup(
123    name = "doxygen",
124    srcs = [
125        "public/pw_function/function.h",
126        "public/pw_function/pointer.h",
127        "public/pw_function/scope_guard.h",
128    ],
129)
130
131sphinx_docs_library(
132    name = "docs",
133    srcs = [
134        "Kconfig",
135        "docs.rst",
136        "function_test.cc",
137    ],
138    prefix = "pw_function/",
139    target_compatible_with = incompatible_with_mcu(),
140)
141