• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 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//rules:common_settings.bzl", "string_flag")
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(default_visibility = ["//visibility:public"])
22
23licenses(["notice"])
24
25# One specific flavor of duct tape for now.
26string_flag(
27    name = "cortex-m_toolchain_kind",
28    build_setting_default = "gcc",
29    values = [
30        "clang",
31        "gcc",
32    ],
33)
34
35config_setting(
36    name = "use_clang_for_cortex-m",
37    flag_values = {":cortex-m_toolchain_kind": "clang"},
38)
39
40alias(
41    name = "cortex-m_cc_toolchain",
42    actual = select({
43        ":use_clang_for_cortex-m": "//pw_toolchain/arm_clang:arm_clang_toolchain_cortex-m",
44        "//conditions:default": "//pw_toolchain/arm_gcc:arm_gcc_toolchain_cortex-m",
45    }),
46)
47
48# This is an interim solution to allow flag-based toolchain selection.
49# Do not rely on this, as it is likely to change.
50toolchain(
51    name = "cc_toolchain_cortex-m0",
52    target_compatible_with = [
53        "//pw_build/constraints/arm:cortex-m0",
54    ],
55    toolchain = ":cortex-m_cc_toolchain",
56    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
57)
58
59toolchain(
60    name = "cc_toolchain_cortex-m0plus",
61    target_compatible_with = [
62        "//pw_build/constraints/arm:cortex-m0plus",
63    ],
64    toolchain = ":cortex-m_cc_toolchain",
65    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
66)
67
68toolchain(
69    name = "cc_toolchain_cortex-m33",
70    target_compatible_with = [
71        "//pw_build/constraints/arm:cortex-m33",
72    ],
73    toolchain = ":cortex-m_cc_toolchain",
74    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
75)
76
77toolchain(
78    name = "cc_toolchain_cortex-m3",
79    target_compatible_with = [
80        "//pw_build/constraints/arm:cortex-m3",
81    ],
82    toolchain = ":cortex-m_cc_toolchain",
83    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
84)
85
86cc_library(
87    name = "constexpr_tag",
88    hdrs = ["public/pw_toolchain/constexpr_tag.h"],
89    strip_include_prefix = "public",
90)
91
92cc_library(
93    name = "no_destructor",
94    hdrs = ["public/pw_toolchain/no_destructor.h"],
95    strip_include_prefix = "public",
96    deps = ["//pw_polyfill"],
97)
98
99cc_library(
100    name = "globals",
101    hdrs = ["public/pw_toolchain/globals.h"],
102    strip_include_prefix = "public",
103)
104
105cc_library(
106    name = "infinite_loop",
107    hdrs = ["public/pw_toolchain/infinite_loop.h"],
108    strip_include_prefix = "public",
109    deps = ["//pw_preprocessor"],
110)
111
112pw_cc_test(
113    name = "no_destructor_test",
114    srcs = ["no_destructor_test.cc"],
115    deps = [
116        ":no_destructor",
117        "//pw_assert:check",
118        "//pw_polyfill",
119    ],
120)
121
122pw_cc_test(
123    name = "globals_test",
124    srcs = ["globals_test.cc"],
125    deps = [
126        ":globals",
127        "//pw_assert:check",
128        "//pw_polyfill",
129    ],
130)
131
132pw_cc_test(
133    name = "infinite_loop_test",
134    srcs = [
135        "infinite_loop_test.cc",
136        "infinite_loop_test_c.c",
137    ],
138    deps = [
139        ":infinite_loop",
140        "//pw_unit_test",
141    ],
142)
143
144cc_library(
145    name = "sibling_cast",
146    hdrs = ["public/pw_toolchain/internal/sibling_cast.h"],
147    strip_include_prefix = "public",
148    visibility = ["//:__subpackages__"],  # Restrict to Pigweed
149)
150
151pw_cc_test(
152    name = "sibling_cast_test",
153    srcs = ["sibling_cast_test.cc"],
154    deps = [
155        ":sibling_cast",
156        "//pw_compilation_testing:negative_compilation_testing",
157    ],
158)
159
160cc_library(
161    name = "wrap_abort",
162    srcs = ["wrap_abort.cc"],
163    implementation_deps = ["//pw_assert:check"],
164    linkopts = ["-Wl,--wrap=abort"],
165    alwayslink = 1,
166)
167
168filegroup(
169    name = "doxygen",
170    srcs = [
171        "public/pw_toolchain/constexpr_tag.h",
172        "public/pw_toolchain/globals.h",
173        "public/pw_toolchain/infinite_loop.h",
174        "public/pw_toolchain/no_destructor.h",
175    ],
176)
177
178sphinx_docs_library(
179    name = "docs",
180    srcs = [
181        "bazel.rst",
182        "docs.rst",
183        "globals_test.cc",
184        "gn.rst",
185    ],
186    prefix = "pw_toolchain/",
187    target_compatible_with = incompatible_with_mcu(),
188)
189