Skip to content

Commit 4d1a3f3

Browse files
committed
netsim: Add pdl_rust rule & gen rust for netsim pdl files.
For netsimd. Bug: b/402294843
1 parent 01875b0 commit 4d1a3f3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

base/cvd/BUILD.android_tools_netsim.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@@//build_external/netsim:pdl_rust.bzl", "pdl_rust")
12
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
23
load("@netsim_crates//:defs.bzl", "all_crate_deps")
34
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
@@ -6,6 +7,36 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
67
load("@rules_proto_grpc_cpp//:defs.bzl", "cpp_grpc_library")
78
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
89

10+
pdl_rust(
11+
name = "netsim_netlink_rust_gen",
12+
src = "pdl/netlink.pdl",
13+
out = "netlink_packets.rs",
14+
)
15+
16+
pdl_rust(
17+
name = "netsim_mac80211_hwsim_rust_gen",
18+
src = "pdl/mac80211_hwsim.pdl",
19+
out = "mac80211_hwsim_packets.rs",
20+
)
21+
22+
pdl_rust(
23+
name = "netsim_ieee80211_rust_gen",
24+
src = "pdl/ieee80211.pdl",
25+
out = "ieee80211_packets.rs",
26+
)
27+
28+
pdl_rust(
29+
name = "netsim_llc_rust_gen",
30+
src = "pdl/llc.pdl",
31+
out = "llc_packets.rs",
32+
)
33+
34+
pdl_rust(
35+
name = "netsim_arp_rust_gen",
36+
src = "pdl/arp.pdl",
37+
out = "arp_packets.rs",
38+
)
39+
940
rust_library(
1041
name = "libnetsim_proto",
1142
srcs = glob(["rust/proto/src/**/*.rs"]),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Run pdlc --output-format rust"""
2+
3+
def _pdl_rust_impl(ctx):
4+
out = ctx.actions.declare_file(ctx.attr.out)
5+
ctx.actions.run_shell(
6+
tools = [ctx.executable._pdlc],
7+
inputs = [ctx.file.src],
8+
outputs = [out],
9+
command = "{pdlc} --output-format rust {src} > {out}".format(
10+
pdlc = ctx.executable._pdlc.path,
11+
src = ctx.file.src.path,
12+
out = out.path,
13+
),
14+
)
15+
return DefaultInfo(files = depset([out]))
16+
17+
pdl_rust = rule(
18+
implementation = _pdl_rust_impl,
19+
attrs = {
20+
"src": attr.label(allow_single_file = True),
21+
"out": attr.string(mandatory = True),
22+
"_pdlc": attr.label(
23+
# Any crates with pdl-compiler would work.
24+
default = "@netsim_crates//:pdl-compiler__pdlc",
25+
executable = True,
26+
cfg = "exec",
27+
),
28+
},
29+
)

0 commit comments

Comments
 (0)