• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2025 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:tool.bzl", "cc_tool")
16load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
17
18package(default_visibility = ["//visibility:public"])
19
20licenses(["notice"])
21
22exports_files(glob(["**/bin/**"]))
23
24cc_tool_map(
25    name = "arm_tools",
26    tools = {
27        "@rules_cc//cc/toolchains/actions:assembly_actions": ":arm-zephyr-eabi-asm",
28        "@rules_cc//cc/toolchains/actions:c_compile_actions": ":arm-zephyr-eabi-gcc",
29        "@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":arm-zephyr-eabi-g++",
30        "@rules_cc//cc/toolchains/actions:link_actions": ":arm-zephyr-eabi-ld",
31        "@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":arm-zephyr-eabi-objcopy",
32        "@pigweed//pw_toolchain/action:objdump_disassemble": ":arm-zephyr-eabi-objdump",
33        "@rules_cc//cc/toolchains/actions:strip": ":arm-zephyr-eabi-strip",
34        "@rules_cc//cc/toolchains/actions:ar_actions": ":arm-zephyr-eabi-ar",
35    },
36)
37
38cc_tool_map(
39    name = "x86_64_tools",
40    tools = {
41        "@rules_cc//cc/toolchains/actions:assembly_actions": ":x86_64-zephyr-elf-asm",
42        "@rules_cc//cc/toolchains/actions:c_compile_actions": ":x86_64-zephyr-elf-gcc",
43        "@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":x86_64-zephyr-elf-g++",
44        "@rules_cc//cc/toolchains/actions:link_actions": ":x86_64-zephyr-elf-ld",
45        "@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":x86_64-zephyr-elf-objcopy",
46        "@pigweed//pw_toolchain/action:objdump_disassemble": ":x86_64-zephyr-elf-objdump",
47        "@rules_cc//cc/toolchains/actions:strip": ":x86_64-zephyr-elf-strip",
48        "@rules_cc//cc/toolchains/actions:ar_actions": ":x86_64-zephyr-elf-ar",
49    },
50)
51
52###############################################################################
53# ARM
54###############################################################################
55
56cc_tool(
57    name = "arm-zephyr-eabi-ar",
58    src = select({
59        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-ar.exe",
60        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-ar",
61    }),
62)
63
64cc_tool(
65    name = "arm-zephyr-eabi-g++",
66    src = select({
67        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-g++.exe",
68        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-g++",
69    }),
70    data = glob([
71        "arm-zephyr-eabi/**",
72        # TODO: https://pwbug.dev/380001331 - Figure out which exact files are needed
73        # "arm-zephyr-eabi/**/*.specs",
74        # "arm-zephyr-eabi/picolibc/**",
75        # "arm-zephyr-eabi/arm-zephyr-eabi/sys-include/**",
76        # "arm-zephyr-eabi/arm-zephyr-eabi/include/**",
77        # "arm-zephyr-eabi/lib/*",
78        # "arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/*/include/**",
79        # "arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/*/include-fixed/**",
80        # "arm-zephyr-eabi/libexec/**",
81    ]),
82)
83
84# TODO: https://github.com/bazelbuild/rules_cc/issues/235 - Workaround until
85# Bazel has a more robust way to implement `cc_tool_map`.
86alias(
87    name = "arm-zephyr-eabi-asm",
88    actual = ":arm-zephyr-eabi-gcc",
89)
90
91cc_tool(
92    name = "arm-zephyr-eabi-gcc",
93    src = select({
94        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe",
95        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc",
96    }),
97    data = glob([
98        "arm-zephyr-eabi/**",
99        # TODO: https://pwbug.dev/380001331 - Figure out which exact files are needed
100        # "arm-zephyr-eabi/**/*.specs",
101        # "arm-zephyr-eabi/picolibc/**",
102        # "arm-zephyr-eabi/include/c++/**",
103        # "arm-zephyr-eabi/arm-zephyr-eabi/sys-include/**",
104        # "arm-zephyr-eabi/lib/*",
105        # "arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/*/include/**",
106        # "arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/*/include-fixed/**",
107        # "arm-zephyr-eabi/libexec/**",
108    ]) #+
109    # The assembler needs to be explicilty added. Note that the path is
110    # intentionally different here as `as` is called from arm-zephyr-eabi-gcc.
111    # `arm-zephyr-eabi-as` will not suffice for this context.
112    # select({
113    #     "@platforms//os:windows": ["//:arm-zephyr-eabi/bin/arm-zephyr-eabi-as.exe"],
114    #     "//conditions:default": ["//:arm-zephyr-eabi/bin/arm-zephyr-eabi-as"],
115    # }),
116)
117
118# This tool is actually just g++ under the hood, we just enumerate this
119# tool differently to specify a different set of additional files.
120cc_tool(
121    name = "arm-zephyr-eabi-ld",
122    src = select({
123        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-g++.exe",
124        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-g++",
125    }),
126    data = glob([
127        "arm-zephyr-eabi/**/*.a",
128        "arm-zephyr-eabi/**/*.ld",
129        "arm-zephyr-eabi/**/*.o",
130        "arm-zephyr-eabi/**/*.specs",
131        "arm-zephyr-eabi/**/*.so",
132        "arm-zephyr-eabi/libexec/**",
133    ]) + [
134        "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-ld",
135    ],
136)
137
138cc_tool(
139    name = "arm-zephyr-eabi-gcov",
140    src = select({
141        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-gcov.exe",
142        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-gcov",
143    }),
144)
145
146cc_tool(
147    name = "arm-zephyr-eabi-objcopy",
148    src = select({
149        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy.exe",
150        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy",
151    }),
152)
153
154cc_tool(
155    name = "arm-zephyr-eabi-objdump",
156    src = select({
157        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-objdump.exe",
158        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-objdump",
159    }),
160)
161
162cc_tool(
163    name = "arm-zephyr-eabi-strip",
164    src = select({
165        "@platforms//os:windows": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-strip.exe",
166        "//conditions:default": "//:arm-zephyr-eabi/bin/arm-zephyr-eabi-strip",
167    }),
168)
169
170###############################################################################
171# x86_64
172###############################################################################
173
174cc_tool(
175    name = "x86_64-zephyr-elf-ar",
176    src = select({
177        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-ar.exe",
178        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-ar",
179    }),
180)
181
182cc_tool(
183    name = "x86_64-zephyr-elf-g++",
184    src = select({
185        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-g++.exe",
186        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-g++",
187    }),
188    data = glob([
189        "x86_64-zephyr-elf/**/*.specs",
190        "x86_64-zephyr-elf/picolibc/**",
191        "x86_64-zephyr-elf/lib/gcc/x86_64-zephyr-elf/*/include/**",
192        "x86_64-zephyr-elf/lib/gcc/x86_64-zephyr-elf/*/include-fixed/**",
193        "x86_64-zephyr-elf/libexec/**",
194    ]),
195)
196
197# TODO: https://github.com/bazelbuild/rules_cc/issues/235 - Workaround until
198# Bazel has a more robust way to implement `cc_tool_map`.
199alias(
200    name = "x86_64-zephyr-elf-asm",
201    actual = ":x86_64-zephyr-elf-gcc",
202)
203
204cc_tool(
205    name = "x86_64-zephyr-elf-gcc",
206    src = select({
207        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-gcc.exe",
208        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-gcc",
209    }),
210    data = glob([
211        "x86_64-zephyr-elf/**/*.specs",
212        "x86_64-zephyr-elf/picolibc/**",
213        "x86_64-zephyr-elf/lib/gcc/x86_64-zephyr-elf/*/include/**",
214        "x86_64-zephyr-elf/lib/gcc/x86_64-zephyr-elf/*/include-fixed/**",
215        "x86_64-zephyr-elf/libexec/**",
216    ]) +
217    # The assembler needs to be explicilty added. Note that the path is
218    # intentionally different here as `as` is called from x86_64-zephyr-elf-gcc.
219    # `x86_64-zephyr-elf-as` will not suffice for this context.
220    select({
221        "@platforms//os:windows": ["//:x86_64-zephyr-elf/bin/as.exe"],
222        "//conditions:default": ["//:x86_64-zephyr-elf/bin/as"],
223    }),
224)
225
226# This tool is actually just g++ under the hood, we just enumerate this
227# tool differently to specify a different set of additional files.
228cc_tool(
229    name = "x86_64-zephyr-elf-ld",
230    src = select({
231        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-g++.exe",
232        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-g++",
233    }),
234    data = glob([
235        "x86_64-zephyr-elf/**/*.a",
236        "x86_64-zephyr-elf/**/*.ld",
237        "x86_64-zephyr-elf/**/*.o",
238        "x86_64-zephyr-elf/**/*.specs",
239        "x86_64-zephyr-elf/**/*.so",
240        "x86_64-zephyr-elf/libexec/**",
241    ]) + [
242        "//:x86_64-zephyr-elf/bin/ld",
243    ],
244)
245
246cc_tool(
247    name = "x86_64-zephyr-elf-gcov",
248    src = select({
249        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-gcov.exe",
250        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-gcov",
251    }),
252)
253
254cc_tool(
255    name = "x86_64-zephyr-elf-objcopy",
256    src = select({
257        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-objcopy.exe",
258        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-objcopy",
259    }),
260)
261
262cc_tool(
263    name = "x86_64-zephyr-elf-objdump",
264    src = select({
265        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-objdump.exe",
266        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-objdump",
267    }),
268)
269
270cc_tool(
271    name = "x86_64-zephyr-elf-strip",
272    src = select({
273        "@platforms//os:windows": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-strip.exe",
274        "//conditions:default": "//:x86_64-zephyr-elf/bin/x86_64-zephyr-elf-strip",
275    }),
276)
277