• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 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("@rules_cc//cc/toolchains:args.bzl", "cc_args")
16load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain")
17
18package(default_visibility = ["//visibility:public"])
19
20licenses(["notice"])
21
22filegroup(name = "empty")
23
24cc_args(
25    name = "cortex-m0",
26    actions = [
27        "@rules_cc//cc/toolchains/actions:assembly_actions",
28        "@rules_cc//cc/toolchains/actions:c_compile_actions",
29        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
30        "@rules_cc//cc/toolchains/actions:link_actions",
31    ],
32    args = [
33        "-mcpu=cortex-m0",
34        "-mfloat-abi=soft",
35    ],
36)
37
38cc_args(
39    name = "cortex-m0plus",
40    actions = [
41        "@rules_cc//cc/toolchains/actions:assembly_actions",
42        "@rules_cc//cc/toolchains/actions:c_compile_actions",
43        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
44        "@rules_cc//cc/toolchains/actions:link_actions",
45    ],
46    args = [
47        "-mcpu=cortex-m0plus",
48        "-mfloat-abi=soft",
49    ],
50)
51
52cc_args(
53    name = "armv6m-none-eabi",
54    actions = [
55        "@rules_cc//cc/toolchains/actions:assembly_actions",
56        "@rules_cc//cc/toolchains/actions:c_compile_actions",
57        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
58        "@rules_cc//cc/toolchains/actions:link_actions",
59    ],
60    args = [
61        "--target=armv6m-none-eabi",
62    ],
63)
64
65cc_args(
66    name = "armv7m-none-eabi",
67    actions = [
68        "@rules_cc//cc/toolchains/actions:assembly_actions",
69        "@rules_cc//cc/toolchains/actions:c_compile_actions",
70        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
71        "@rules_cc//cc/toolchains/actions:link_actions",
72    ],
73    args = [
74        "--target=armv7m-none-eabi",
75    ],
76)
77
78cc_args(
79    name = "armv8m.main-none-eabi",
80    actions = [
81        "@rules_cc//cc/toolchains/actions:assembly_actions",
82        "@rules_cc//cc/toolchains/actions:c_compile_actions",
83        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
84        "@rules_cc//cc/toolchains/actions:link_actions",
85    ],
86    args = [
87        "--target=armv8m.main-none-eabi",
88    ],
89)
90
91cc_args(
92    name = "cortex-a35",
93    actions = [
94        "@rules_cc//cc/toolchains/actions:assembly_actions",
95        "@rules_cc//cc/toolchains/actions:c_compile_actions",
96        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
97        "@rules_cc//cc/toolchains/actions:link_actions",
98    ],
99    args = [
100        "-mcpu=cortex-a35",
101    ],
102)
103
104cc_args(
105    name = "aarch64-none-elf",
106    actions = [
107        "@rules_cc//cc/toolchains/actions:assembly_actions",
108        "@rules_cc//cc/toolchains/actions:c_compile_actions",
109        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
110        "@rules_cc//cc/toolchains/actions:link_actions",
111    ],
112    args = [
113        "--target=aarch64-none-elf",
114    ],
115)
116
117cc_args(
118    name = "cxx_compiler_flags",
119    actions = [
120        "@rules_cc//cc/toolchains/actions:compile_actions",
121    ],
122    args = [
123        "-fno-register-global-dtors-with-atexit",
124        "-fno-c++-static-destructors",
125        "-fno-use-cxa-atexit",
126        "-fno-threadsafe-statics",
127        "-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES",
128    ],
129    data = [
130        "//pw_libcxx:cxx_lib_configs",
131    ],
132)
133
134cc_args(
135    name = "cortex_common",
136    actions = [
137        "@rules_cc//cc/toolchains/actions:c_compile_actions",
138        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
139    ],
140)
141
142cc_args(
143    name = "cortex_common_link",
144    actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
145    args = [
146        "-Wl,--gc-sections",
147    ],
148)
149
150cc_args(
151    name = "cortex_a35_linkopts",
152    actions = [
153        "@rules_cc//cc/toolchains/actions:link_actions",
154    ],
155    args = [
156        "-nostartfiles",
157        "-unwindlib=none",
158    ],
159)
160
161# Additional arm_clang specific warning flags
162cc_args(
163    name = "warnings",
164    actions = [
165        "@rules_cc//cc/toolchains/actions:c_compile_actions",
166        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
167    ],
168    args = [
169        # This can't be in common, because proto headers in host builds trigger
170        "-Wundef",
171        # Silence the really verbose ARM warnings.
172        "-Wno-psabi",
173    ],
174)
175
176cc_args(
177    name = "thumb_abi",
178    actions = [
179        "@rules_cc//cc/toolchains/actions:assembly_actions",
180        "@rules_cc//cc/toolchains/actions:c_compile_actions",
181        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
182        "@rules_cc//cc/toolchains/actions:link_actions",
183    ],
184    args = [
185        "-mabi=aapcs",
186        "-mthumb",
187    ],
188)
189
190cc_args(
191    name = "cortex-m33",
192    actions = [
193        "@rules_cc//cc/toolchains/actions:assembly_actions",
194        "@rules_cc//cc/toolchains/actions:c_compile_actions",
195        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
196        "@rules_cc//cc/toolchains/actions:link_actions",
197    ],
198    args = [
199        "-mcpu=cortex-m33",
200        "-mfloat-abi=softfp",
201    ],
202)
203
204cc_args(
205    name = "cortex-m3",
206    actions = [
207        "@rules_cc//cc/toolchains/actions:assembly_actions",
208        "@rules_cc//cc/toolchains/actions:c_compile_actions",
209        "@rules_cc//cc/toolchains/actions:cpp_compile_actions",
210        "@rules_cc//cc/toolchains/actions:link_actions",
211    ],
212    args = [
213        "-mcpu=cortex-m3",
214        "-mfloat-abi=soft",
215    ],
216)
217
218cc_toolchain(
219    name = "arm_clang_toolchain_cortex-m",
220    args = [
221        ":cxx_compiler_flags",
222        "@llvm_toolchain_device//:llvm-libc_args",
223        ":thumb_abi",
224        ":cortex_common",
225        ":cortex_common_link",
226        ":warnings",
227        "//pw_toolchain/cc/args:oz",
228        "//pw_toolchain/cc/args:debugging",
229        "//pw_toolchain/cc/args:reduced_size",
230        "//pw_toolchain/cc/args:no_canonical_prefixes",
231        "//pw_toolchain/cc/args:no_rtti",
232        "//pw_toolchain/cc/args:wno_register",
233        "//pw_toolchain/cc/args:wnon_virtual_dtor",
234        "//pw_toolchain/cc/args:common_warnings",
235        "//pw_toolchain/cc/args:color_diagnostics",
236    ] + select({
237        "//pw_build/constraints/arm:cortex-m0": [
238            ":cortex-m0",
239            ":armv6m-none-eabi",
240        ],
241        "//pw_build/constraints/arm:cortex-m0plus": [
242            ":cortex-m0plus",
243            ":armv6m-none-eabi",
244        ],
245        "//pw_build/constraints/arm:cortex-m3": [
246            ":cortex-m3",
247            ":armv7m-none-eabi",
248        ],
249        "//pw_build/constraints/arm:cortex-m33": [
250            ":cortex-m33",
251            ":armv8m.main-none-eabi",
252        ],
253        "//pw_build/constraints/arm:none": [],
254    }),
255    enabled_features = [
256        "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
257        "//pw_toolchain/cc/capability:compiler_is_clang",
258        "//pw_toolchain/cc/capability:linker_is_clang",
259    ] + select({
260        "//pw_toolchain/cc:c++17_enabled": ["//pw_toolchain/cc/args:c++17_feature"],
261        "//conditions:default": [],
262    }) + select({
263        "//pw_toolchain/cc:c++20_enabled": ["//pw_toolchain/cc/args:c++20_feature"],
264        "//conditions:default": [],
265    }),
266    tags = ["manual"],  # Don't try to build this in wildcard builds.
267    target_compatible_with = select({
268        "//pw_build/constraints/arm:cortex-m0": [],
269        "//pw_build/constraints/arm:cortex-m0plus": [],
270        "//pw_build/constraints/arm:cortex-m3": [],
271        "//pw_build/constraints/arm:cortex-m33": [],
272        "//pw_build/constraints/arm:none": ["@platforms//:incompatible"],
273    }),
274    tool_map = "@llvm_toolchain_device//:all_tools",
275    visibility = ["//pw_toolchain:__pkg__"],
276)
277
278toolchain(
279    name = "arm_clang_cc_toolchain_cortex-m0",
280    target_compatible_with = [
281        "//pw_build/constraints/arm:cortex-m0",
282    ],
283    toolchain = ":arm_clang_toolchain_cortex-m",
284    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
285)
286
287toolchain(
288    name = "arm_clang_cc_toolchain_cortex-m0plus",
289    target_compatible_with = [
290        "//pw_build/constraints/arm:cortex-m0plus",
291    ],
292    toolchain = ":arm_clang_toolchain_cortex-m",
293    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
294)
295
296toolchain(
297    name = "arm_clang_cc_toolchain_cortex-m33",
298    target_compatible_with = [
299        "//pw_build/constraints/arm:cortex-m33",
300    ],
301    toolchain = ":arm_clang_toolchain_cortex-m",
302    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
303)
304
305cc_toolchain(
306    name = "arm_clang_toolchain_cortex-a",
307    args = [
308        ":cxx_compiler_flags",
309        "@llvm_toolchain_device//:llvm-libc_args",
310        ":cortex_common",
311        ":cortex_common_link",
312        ":warnings",
313        "//pw_toolchain/cc/args:oz",
314        "//pw_toolchain/cc/args:debugging",
315        "//pw_toolchain/cc/args:reduced_size",
316        "//pw_toolchain/cc/args:no_canonical_prefixes",
317        "//pw_toolchain/cc/args:no_rtti",
318        "//pw_toolchain/cc/args:wno_register",
319        "//pw_toolchain/cc/args:wnon_virtual_dtor",
320        "//pw_toolchain/cc/args:common_warnings",
321        "//pw_toolchain/cc/args:color_diagnostics",
322    ] + select({
323        "//pw_build/constraints/arm:cortex-a35": [
324            ":cortex-a35",
325            ":aarch64-none-elf",
326            ":cortex_a35_linkopts",
327        ],
328        "//pw_build/constraints/arm:none": [],
329    }),
330    enabled_features = [
331        "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
332        "//pw_toolchain/cc/capability:compiler_is_clang",
333        "//pw_toolchain/cc/capability:linker_is_clang",
334    ] + select({
335        "//pw_toolchain/cc:c++17_enabled": ["//pw_toolchain/cc/args:c++17_feature"],
336        "//conditions:default": [],
337    }) + select({
338        "//pw_toolchain/cc:c++20_enabled": ["//pw_toolchain/cc/args:c++20_feature"],
339        "//conditions:default": [],
340    }),
341    tags = ["manual"],  # Don't try to build this in wildcard builds.
342    target_compatible_with = select({
343        "//pw_build/constraints/arm:cortex-a35": [],
344        "//pw_build/constraints/arm:none": ["@platforms//:incompatible"],
345    }),
346    tool_map = "@llvm_toolchain_device//:all_tools",
347    visibility = ["//pw_toolchain:__pkg__"],
348)
349
350toolchain(
351    name = "arm_clang_cc_toolchain_cortex-a35",
352    target_compatible_with = [
353        "//pw_build/constraints/arm:cortex-a35",
354    ],
355    toolchain = ":arm_clang_toolchain_cortex-a",
356    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
357)
358