5
5
load ("//rules:rv.bzl" , "rv_rule" )
6
6
load ("@rules_cc//cc:find_cc_toolchain.bzl" , "find_cc_toolchain" )
7
7
8
- def _get_assembler (cc_toolchain ):
9
- """Find the path to riscv-unknown-elf-as."""
10
-
11
- # Note: the toolchain config doesn"t appear to have a good way to get
12
- # access to the assembler. We should be able to access it via the
13
- # the compiler, but I had trouble with //hw/ip/otbn/util/otbn_as.py invoking
14
- # the compiler as assembler.
15
- return [f for f in cc_toolchain .all_files .to_list () if f .basename .endswith ("as" )][0 ]
16
-
17
8
def _otbn_assemble_sources (ctx , additional_srcs = []):
18
9
"""Helper function that, for each source file in the provided context, adds
19
10
an action to the context that invokes the otbn assember (otbn_as.py),
20
11
producing a corresponding object file. Returns a list of all object files
21
12
that will be generated by these actions.
22
13
"""
23
14
cc_toolchain = find_cc_toolchain (ctx )
24
- assembler = _get_assembler (cc_toolchain )
25
15
26
16
objs = []
27
17
for src in ctx .files .srcs + additional_srcs :
@@ -33,7 +23,7 @@ def _otbn_assemble_sources(ctx, additional_srcs = []):
33
23
cc_toolchain .all_files .to_list () +
34
24
[ctx .executable ._otbn_as ]),
35
25
env = {
36
- "RV32_TOOL_AS" : assembler .path ,
26
+ "RV32_TOOL_AS" : ctx . executable . _riscv32_as .path ,
37
27
},
38
28
arguments = ["-o" , obj .path , src .path ] + ctx .attr .args ,
39
29
executable = ctx .executable ._otbn_as ,
@@ -78,7 +68,6 @@ def _otbn_binary(ctx, additional_srcs = []):
78
68
that other rules can depend on in their `deps`.
79
69
"""
80
70
cc_toolchain = find_cc_toolchain (ctx )
81
- assembler = _get_assembler (cc_toolchain )
82
71
83
72
# Run the otbn assembler on source files to produce object (.o) files.
84
73
objs = _otbn_assemble_sources (ctx , additional_srcs )
@@ -100,10 +89,10 @@ def _otbn_binary(ctx, additional_srcs = []):
100
89
ctx .files ._otbn_data +
101
90
[ctx .executable ._wrapper ]),
102
91
env = {
103
- "RV32_TOOL_AS" : assembler .path ,
104
- "RV32_TOOL_AR" : cc_toolchain . ar_executable ,
105
- "RV32_TOOL_LD" : cc_toolchain . ld_executable ,
106
- "RV32_TOOL_OBJCOPY" : cc_toolchain . objcopy_executable ,
92
+ "RV32_TOOL_AS" : ctx . executable . _riscv32_as .path ,
93
+ "RV32_TOOL_AR" : ctx . executable . _riscv32_ar . path ,
94
+ "RV32_TOOL_LD" : ctx . executable . _riscv32_ld . path ,
95
+ "RV32_TOOL_OBJCOPY" : ctx . executable . _riscv32_objcopy . path ,
107
96
},
108
97
arguments = [
109
98
"--app-name={}" .format (ctx .attr .name ),
@@ -286,8 +275,11 @@ otbn_library = rv_rule(
286
275
attrs = {
287
276
"srcs" : attr .label_list (allow_files = True ),
288
277
"args" : attr .string_list (),
289
- "_cc_toolchain" : attr .label (
290
- default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" ),
278
+ "_riscv32_as" : attr .label (
279
+ default = Label ("@lowrisc_rv32imcb_toolchain//:bin/riscv32-unknown-elf-as" ),
280
+ allow_single_file = True ,
281
+ executable = True ,
282
+ cfg = "exec" ,
291
283
),
292
284
"_otbn_as" : attr .label (
293
285
default = "//hw/ip/otbn/util:otbn_as" ,
@@ -306,7 +298,30 @@ otbn_binary = rv_rule(
306
298
"srcs" : attr .label_list (allow_files = True ),
307
299
"deps" : attr .label_list (providers = [DefaultInfo ]),
308
300
"args" : attr .string_list (),
309
- "_cc_toolchain" : attr .label (default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" )),
301
+ "_riscv32_ar" : attr .label (
302
+ default = Label ("@lowrisc_rv32imcb_toolchain//:bin/riscv32-unknown-elf-ar" ),
303
+ allow_single_file = True ,
304
+ executable = True ,
305
+ cfg = "exec" ,
306
+ ),
307
+ "_riscv32_as" : attr .label (
308
+ default = Label ("@lowrisc_rv32imcb_toolchain//:bin/riscv32-unknown-elf-as" ),
309
+ allow_single_file = True ,
310
+ executable = True ,
311
+ cfg = "exec" ,
312
+ ),
313
+ "_riscv32_ld" : attr .label (
314
+ default = Label ("@lowrisc_rv32imcb_toolchain//:bin/riscv32-unknown-elf-ld" ),
315
+ allow_single_file = True ,
316
+ executable = True ,
317
+ cfg = "exec" ,
318
+ ),
319
+ "_riscv32_objcopy" : attr .label (
320
+ default = Label ("@lowrisc_rv32imcb_toolchain//:bin/riscv32-unknown-elf-objcopy" ),
321
+ allow_single_file = True ,
322
+ executable = True ,
323
+ cfg = "exec" ,
324
+ ),
310
325
"_otbn_as" : attr .label (
311
326
default = "//hw/ip/otbn/util:otbn_as" ,
312
327
executable = True ,
0 commit comments