Skip to content

Commit 736567c

Browse files
committed
[bazel] Autogen Rust register modules
Signed-off-by: James Wainwright <[email protected]>
1 parent 5898e5e commit 736567c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

hw/top/BUILD

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
77
load(
88
"//rules:autogen.bzl",
99
"opentitan_ip_c_header",
10+
"opentitan_ip_rust_module",
1011
)
1112
load("//rules/opentitan:hw.bzl", "get_top_attr")
1213
load(
@@ -18,6 +19,7 @@ load(
1819
"opentitan_alias_top_attr",
1920
"opentitan_if_ip",
2021
)
22+
load("@rules_rust//rust:defs.bzl", "rust_library")
2123

2224
package(default_visibility = ["//visibility:public"])
2325

@@ -125,6 +127,51 @@ alias(
125127
for ip in ALL_IP_NAMES
126128
]
127129

130+
# Rust register modules for all IPs.
131+
[
132+
opentitan_ip_rust_module(
133+
name = "{}_rust_regs".format(ip),
134+
ip = ip,
135+
kind = "generic",
136+
)
137+
for ip in ALL_IP_NAMES
138+
]
139+
140+
# `lib.rs` file defining a module for each IP.
141+
genrule(
142+
name = "ot_regs_lib_rs",
143+
srcs = [],
144+
outs = ["lib.rs"],
145+
cmd = "echo '{}' > \"$@\"".format(
146+
"\n".join([
147+
'#[cfg(feature = "{ip}")]\npub mod {ip};'.format(ip = ip)
148+
for ip in ALL_IP_NAMES
149+
]),
150+
),
151+
visibility = ["//visibility:private"],
152+
)
153+
154+
# Crate with a module for the registers of each IP.
155+
rust_library(
156+
name = "ot_regs",
157+
srcs = [":ot_regs_lib_rs"] + flatten([
158+
opentitan_if_ip(
159+
ip,
160+
[":{}_rust_regs".format(ip)],
161+
[],
162+
)
163+
for ip in ALL_IP_NAMES
164+
]),
165+
crate_features = flatten([
166+
opentitan_if_ip(
167+
ip,
168+
[ip],
169+
[],
170+
)
171+
for ip in ALL_IP_NAMES
172+
]),
173+
)
174+
128175
cc_library(
129176
name = "doxy_target",
130177
deps = [

hw/top/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Furthermore, adding `//hw/top:top_lib` or `//hw/top:top_ld` as a dependency of a
4242

4343
The headers for every IP are exposed as:
4444
- `//hw/top:<ip>_c_regs` for the C registers,
45+
- `//hw/top:<ip>_rust_regs` for the Rust registers,
4546
- `//hw/top/tock:<ip>_regs` for the Rust registers for Tock.
4647

4748
[**Compatibility annotations**](#compatibility-annotations): those targets are only marked as compatible with the tops that contain at least an instance of them.

0 commit comments

Comments
 (0)