1// Copyright 2022 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://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,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    default_visibility: [
17        "//tools/netsim:__subpackages__",
18        "//device/google/cuttlefish/build:__subpackages__",
19    ],
20    default_applicable_licenses: ["tools_netsim_license"],
21}
22
23// Added automatically by a large-scale-change
24// See: http://go/android-license-faq
25license {
26    name: "tools_netsim_license",
27    visibility: [":__subpackages__"],
28    license_kinds: [
29        "SPDX-license-identifier-Apache-2.0",
30    ],
31    license_text: [
32        "LICENSE",
33    ],
34}
35
36cc_defaults {
37    name: "netsim_defaults",
38    cflags: [
39        "-Wno-unused-parameter",
40        "-g", // Produce debugging information.
41    ],
42    ldflags: ["-rdynamic"], // Allow obtaining backtraces for debugging.
43    local_include_dirs: [
44        "src",
45    ],
46    shared_libs: [
47        "libgrpc++",
48        "libprotobuf-cpp-full",
49    ],
50    generated_headers: [
51        "FrontendStub_h",
52    ],
53    generated_sources: [
54        "FrontendStub_cc",
55    ],
56}
57
58rust_defaults {
59    name: "libnetsim_daemon_defaults",
60    features: ["cuttlefish"],
61    rlibs: [
62        "libbytes",
63        "libclap",
64        "libcxx",
65        "libanyhow",
66        "libdata_encoding",
67        "libfutures",
68        "libfutures_channel",
69        "libfutures_executor",
70        "libfutures_util",
71        "libglam",
72        "libgrpcio",
73        "libnetsim_proto",
74        "libhttp",
75        "libnetsim_common",
76        "libpdl_runtime",
77        "libpica",
78        "libprotobuf",
79        "libprotobuf_json_mapping",
80        "librand",
81        "libregex",
82        "libserde",
83        "libserde_json",
84        "libthiserror",
85        "libtokio",
86        "libtokio_stream",
87        "libtungstenite",
88        "liblazy_static",
89        "liblog_rust",
90        "libopenssl",
91    ],
92    static_libs: ["libgrpc_wrap"],
93    srcs: [
94        "rust/daemon/src/lib.rs",
95        ":netsim_netlink_rust_gen",
96        ":netsim_mac80211_hwsim_rust_gen",
97        ":netsim_ieee80211_rust_gen",
98        ":rootcanal_link_layer_packets_rust_gen",
99    ],
100}
101
102rust_ffi_host_static {
103    name: "libnetsim_daemon",
104    crate_name: "netsim_daemon",
105    defaults: ["libnetsim_daemon_defaults"],
106}
107
108rust_test_host {
109    name: "libnetsim_daemon_tests",
110    defaults: ["libnetsim_daemon_defaults"],
111    test_suites: ["general_tests"],
112}
113
114genrule {
115    name: "netsim_daemon_cc",
116    tools: ["cxxbridge"],
117    cmd: "$(location cxxbridge) $(in) --cfg feature=\\\"cuttlefish\\\" >> $(out)",
118    srcs: ["rust/daemon/src/ffi.rs"],
119    out: ["netsim-daemon/src/ffi.rs.cc"],
120}
121
122genrule {
123    name: "netsim_daemon_h",
124    tools: ["cxxbridge"],
125    cmd: "$(location cxxbridge) $(in) --cfg feature=\\\"cuttlefish\\\" --header >> $(out)",
126    srcs: ["rust/daemon/src/ffi.rs"],
127    out: ["netsim-daemon/src/ffi.rs.h"],
128}
129
130genrule {
131    name: "netsim_cli_cc",
132    tools: ["cxxbridge"],
133    cmd: "$(location cxxbridge) $(in) >> $(out)",
134    srcs: ["rust/cli/src/ffi.rs"],
135    out: ["netsim-cli/src/ffi.rs.cc"],
136}
137
138genrule {
139    name: "netsim_cli_h",
140    tools: ["cxxbridge"],
141    cmd: "$(location cxxbridge) $(in) --header >> $(out)",
142    srcs: ["rust/cli/src/ffi.rs"],
143    out: ["netsim-cli/src/ffi.rs.h"],
144}
145
146genrule {
147    name: "netsim_netlink_rust_gen",
148    defaults: ["pdl_rust_generator_defaults"],
149    srcs: ["pdl/netlink.pdl"],
150    out: ["netlink_packets.rs"],
151}
152
153genrule {
154    name: "netsim_mac80211_hwsim_rust_gen",
155    defaults: ["pdl_rust_generator_defaults"],
156    srcs: ["pdl/mac80211_hwsim.pdl"],
157    out: ["mac80211_hwsim_packets.rs"],
158}
159
160genrule {
161    name: "netsim_ieee80211_rust_gen",
162    defaults: ["pdl_rust_generator_defaults"],
163    srcs: ["pdl/ieee80211.pdl"],
164    out: ["ieee80211_packets.rs"],
165}
166
167cc_library_host_static {
168    name: "lib-netsim",
169    defaults: ["netsim_defaults"],
170    srcs: [
171        "src/core/server.cc",
172        "src/frontend/frontend_client_stub.cc",
173        "src/frontend/frontend_server.cc",
174        "src/backend/grpc_server.cc",
175        "src/backend/grpc_client.cc",
176        "src/hci/bluetooth_facade.cc",
177        "src/hci/hci_packet_transport.cc",
178        "src/hci/rust_device.cc",
179        "src/util/crash_report.cc",
180        "src/util/ini_file.cc",
181        "src/util/log.cc",
182        "src/util/os_utils.cc",
183        "src/util/string_utils.cc",
184        "src/wifi/wifi_facade.cc",
185    ],
186    generated_headers: [
187        "cxx-bridge-header",
188        "netsim_daemon_h",
189        "PacketStreamerStub_h",
190    ],
191    generated_sources: [
192        "netsim_daemon_cc",
193        "PacketStreamerStub_cc",
194    ],
195    shared_libs: [
196        "libbase",
197        "libgrpc++",
198        "libcrypto",
199        "libunwindstack",
200    ],
201    static_libs: [
202        "breakpad_client",
203        "libjsoncpp",
204        "libprotobuf-cpp-full",
205        "libscriptedbeaconpayload-protos-lite",
206        "lib-netsimd-proto",
207    ],
208    whole_static_libs: [
209        "libbt-rootcanal",
210    ],
211}
212
213netsim_ui_modules = [
214    "netsim_ui_index.html",
215    "netsim_ui_js_cube-sprite.js",
216    "netsim_ui_js_customize-map-button.js",
217    "netsim_ui_js_device-dragzone.js",
218    "netsim_ui_js_device-dropzone.js",
219    "netsim_ui_js_device-info.js",
220    "netsim_ui_js_device-list.js",
221    "netsim_ui_js_device-map.js",
222    "netsim_ui_js_device-observer.js",
223    "netsim_ui_js_license-info.js",
224    "netsim_ui_js_navigation-bar.js",
225    "netsim_ui_js_netsim-app.js",
226    "netsim_ui_js_packet-info.js",
227    "netsim_ui_js_pyramid-sprite.js",
228    "netsim_ui_tslib",
229    "netsim_ui_assets_grid-background.svg",
230    "netsim_ui_assets_hexagonal-background.png",
231    "netsim_ui_assets_netsim-logo-b.svg",
232    "netsim_ui_assets_netsim-logo.svg",
233    "netsim_ui_assets_polar-background.svg",
234]
235
236cc_binary_host {
237    name: "netsimd",
238    defaults: ["netsim_defaults"],
239    srcs: [
240        "rust/netsimd.cc",
241    ],
242    generated_headers: [
243        "cxx-bridge-header",
244        "netsim_daemon_h",
245    ],
246    shared_libs: [
247        "libbase",
248        "libgrpc++",
249        "libcap",
250        "libcrypto",
251        "libssl",
252        "libunwindstack",
253        "libz", // TODO: Remove for native rust binary
254    ],
255    static_libs: [
256        "breakpad_client",
257        "libprotobuf-cpp-full",
258        "libscriptedbeaconpayload-protos-lite", // TODO: Remove this after using pdl library.
259        "lib-netsimd-proto",
260        "lib-netsim",
261        "lib-netsim-frontend-proto",
262        "libgrpc_wrap",
263        "librootcanal_rs",
264    ],
265    whole_static_libs: [
266        "libnetsim_daemon",
267        "libbt-rootcanal",
268    ],
269    ldflags: ["-Wl,--allow-multiple-definition"],
270    required: netsim_ui_modules,
271    strip: {
272        keep_symbols_and_debug_frame: true,
273    },
274}
275
276cc_test_host {
277    name: "netsim-test",
278    defaults: ["netsim_defaults"],
279    srcs: [
280        "src/util/ini_file_test.cc",
281        "src/util/os_utils_test.cc",
282        "src/util/string_utils_test.cc",
283    ],
284    generated_headers: [
285        "cxx-bridge-header",
286        "netsim_daemon_h",
287    ],
288    shared_libs: [
289        "libgrpc++",
290        "libcrypto",
291        "libbase",
292        "libunwindstack",
293        "libssl",
294        "libz", // TODO: Remove for native rust binary
295    ],
296    static_libs: [
297        "breakpad_client",
298        "libgrpc_wrap",
299        "libjsoncpp",
300        "libprotobuf-cpp-full",
301        "libscriptedbeaconpayload-protos-lite", // TODO: Remove this after using pdl library.
302        "lib-netsim-frontend-proto",
303        "lib-netsim",
304        "lib-netsimd-proto",
305        "librootcanal_rs",
306    ],
307    whole_static_libs: [
308        "libnetsim_daemon",
309        "libbt-rootcanal",
310    ],
311    ldflags: ["-Wl,--allow-multiple-definition"],
312}
313
314rust_library_host {
315    name: "libnetsim_proto",
316    features: ["cuttlefish"],
317    crate_name: "netsim_proto",
318    srcs: ["rust/proto/src/lib.rs"],
319    rustlibs: [
320        "libprotobuf",
321        "libgrpcio",
322    ],
323}
324
325rust_defaults {
326    name: "libnetsim_common_defaults",
327    srcs: ["rust/common/src/lib.rs"],
328    rustlibs: [
329        "libanyhow",
330        "libchrono",
331        "librand",
332        "liblibc",
333        "liblog_rust",
334        "libenv_logger",
335        "libzip",
336    ],
337}
338
339rust_library_host {
340    name: "libnetsim_common",
341    crate_name: "netsim_common",
342    defaults: ["libnetsim_common_defaults"],
343}
344
345rust_test_host {
346    name: "libnetsim_common_inline_tests",
347    defaults: ["libnetsim_common_defaults"],
348    test_suites: ["general_tests"],
349}
350
351cc_library_host_static {
352    name: "lib-netsim-frontend-client",
353    defaults: ["netsim_defaults"],
354    srcs: [
355        "src/frontend/frontend_client.cc",
356        "src/util/ini_file.cc",
357        "src/util/log.cc",
358        "src/util/os_utils.cc",
359        "src/util/string_utils.cc",
360    ],
361    generated_headers: [
362        "cxx-bridge-header",
363        "netsim_cli_h",
364    ],
365    shared_libs: ["libgrpc++"],
366    generated_sources: ["netsim_cli_cc"],
367    static_libs: [
368        "libprotobuf-cpp-full",
369        "lib-netsim-frontend-proto",
370    ],
371}
372
373rust_defaults {
374    name: "netsim_cli_defaults",
375    rustlibs: [
376        "libclap",
377        "libcxx",
378        "libhex",
379        "libnetsim_common",
380        "libnetsim_proto",
381        "libprotobuf",
382        "libtracing",
383    ],
384}
385
386rust_defaults {
387    name: "netsim_cli_cc_defaults",
388    shared_libs: ["libgrpc++"],
389    static_libs: [
390        "lib-netsim-frontend-client",
391        "lib-netsim-frontend-proto",
392        "libprotobuf-cpp-full",
393    ],
394}
395
396rust_test_host {
397    name: "libnetsim_cli_tests",
398    srcs: ["rust/cli/src/lib.rs"],
399    defaults: ["netsim_cli_defaults"],
400    test_suites: ["general_tests"],
401}
402
403rust_library_host {
404    name: "libnetsim_cli",
405    crate_name: "netsim_cli",
406    srcs: ["rust/cli/src/lib.rs"],
407    defaults: [
408        "netsim_cli_defaults",
409        "netsim_cli_cc_defaults",
410    ],
411}
412
413rust_binary_host {
414    name: "netsim",
415    srcs: ["rust/cli/bin/netsim.rs"],
416    rustlibs: [
417        "libnetsim_cli",
418    ],
419}
420
421rust_binary_host {
422    name: "netsim_test_client",
423    srcs: ["rust/frontend/src/netsim_test_client.rs"],
424    rustlibs: [
425        "libgrpcio",
426        "libnetsim_proto",
427        "libprotobuf",
428        "libnetsim_common",
429    ],
430}
431
432rust_binary_host {
433    name: "netsim_test_server",
434    srcs: ["rust/frontend/src/netsim_test_server.rs"],
435    rustlibs: [
436        "libgrpcio",
437        "libnetsim_proto",
438        "libprotobuf",
439        "libnetsim_common",
440        "libfutures",
441    ],
442}
443