Skip to content

Commit d575a1f

Browse files
committed
netsim: Add lib-netsim
Steps towards netsimd. Bug: b/402294843
1 parent 92a0488 commit d575a1f

3 files changed

Lines changed: 91 additions & 1 deletion

File tree

base/cvd/BUILD.android_tools_netsim.bazel

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
12
load("@netsim_crates//:defs.bzl", "all_crate_deps")
23
load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
4+
load("@rules_cc//cc:defs.bzl", "cc_library")
35
load("@rules_proto//proto:defs.bzl", "proto_library")
6+
load("@rules_proto_grpc_cpp//:defs.bzl", "cpp_grpc_library")
47
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
58

69
rust_library(
@@ -73,6 +76,75 @@ proto_library(
7376

7477
# lib-netsimd-proto
7578
cc_proto_library(
76-
name = "netsim_proto_cc",
79+
name = "netsim_cc_proto",
7780
deps = [":netsim_proto"],
7881
)
82+
83+
cpp_grpc_library(
84+
name = "netsim_cc_grpc",
85+
protos = [":netsim_proto"],
86+
deps = [":netsim_cc_proto"],
87+
)
88+
89+
# netsim_daemon_cc, netsim_daemon_h
90+
run_binary(
91+
name = "netsim_daemon_ffi",
92+
srcs = [
93+
"rust/daemon/src/ffi.rs",
94+
],
95+
outs = [
96+
"netsim-daemon/src/ffi.rs.cc",
97+
"netsim-daemon/src/ffi.rs.h",
98+
],
99+
args = [
100+
"$(execpath rust/daemon/src/ffi.rs)",
101+
"--cfg",
102+
'feature="cuttlefish"',
103+
"-o",
104+
"$(execpath netsim-daemon/src/ffi.rs.h)",
105+
"-o",
106+
"$(execpath netsim-daemon/src/ffi.rs.cc)",
107+
],
108+
tool = "@cxx.rs//:codegen",
109+
)
110+
111+
cc_library(
112+
name = "lib-netsim",
113+
srcs = [
114+
"src/backend/grpc_client.cc",
115+
"src/hci/bluetooth_facade.cc",
116+
"src/hci/hci_packet_transport.cc",
117+
"src/hci/rust_device.cc",
118+
"src/util/crash_report.cc",
119+
"src/util/ini_file.cc",
120+
"src/util/log.cc",
121+
"src/util/os_utils.cc",
122+
"src/util/string_utils.cc",
123+
":netsim_daemon_ffi",
124+
] + glob([
125+
"src/**/*.h",
126+
]),
127+
copts = [
128+
"-Wno-unused-parameter",
129+
"-g", # Produce debugging information.
130+
],
131+
defines = [
132+
# We use NETSIM_ANDROID_EMULATOR here to temporarily simplify crash
133+
# reporting infra.
134+
# TODO: Properly add breakpad, libunwindstack, etc.
135+
"NETSIM_ANDROID_EMULATOR",
136+
],
137+
includes = [
138+
"src",
139+
],
140+
linkstatic = True,
141+
deps = [
142+
":netsim_cc_grpc",
143+
":netsim_cc_proto",
144+
"@@//build_external/cxxbridge:cxx-bridge-header",
145+
"@grpc//:grpc++",
146+
"@jsoncpp",
147+
"@protobuf",
148+
"@rootcanal",
149+
],
150+
)

base/cvd/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bazel_dep(name = "boringssl", version = "0.20241024.0")
1313
bazel_dep(name = "brotli", version = "1.1.0")
1414
bazel_dep(name = "crc32c", version = "1.1.0")
1515
bazel_dep(name = "curl", version = "8.8.0.bcr.2")
16+
bazel_dep(name = "cxx.rs", version = "1.0.168")
1617
bazel_dep(name = "fmt", version = "10.2.1")
1718
bazel_dep(name = "freetype", version = "2.13.3")
1819
bazel_dep(name = "gflags", version = "2.2.2")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2+
3+
genrule(
4+
name = "cxx-bridge-header-gen",
5+
outs = [
6+
"rust/cxx.h",
7+
],
8+
cmd = "$(location @cxx.rs//:codegen) --header > $@",
9+
tools = ["@cxx.rs//:codegen"],
10+
)
11+
12+
cc_library(
13+
name = "cxx-bridge-header",
14+
hdrs = [":cxx-bridge-header-gen"],
15+
includes = ["."],
16+
visibility = ["//visibility:public"],
17+
)

0 commit comments

Comments
 (0)