• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1message(STATUS "Adding rust ${CMAKE_CURRENT_LIST_DIR}/Cargo.toml")
2
3# Delete any old Cargo.lock files
4file(REMOVE ${CMAKE_CURRENT_LIST_DIR}/Cargo.lock)
5
6# This will automatically register all the tests as well.
7corrosion_import_crate(MANIFEST_PATH Cargo.toml FLAGS --offline --verbose)
8corrosion_set_env_vars(netsim-common CARGO_HOME=${Rust_CARGO_HOME})
9corrosion_set_env_vars(
10  netsim-daemon
11  LINK_LAYER_PACKETS_PREBUILT=${RootCanalGeneratedPackets_rs}
12  NETLINK_PACKETS_PREBUILT=${NetlinkPackets_rs}
13  MAC80211_HWSIM_PACKETS_PREBUILT=${Mac80211HwsimPackets_rs}
14  IEEE80211_PACKETS_PREBUILT=${Ieee80211Packets_rs}
15  CARGO_HOME=${Rust_CARGO_HOME}
16  GRPCIO_SYS_GRPC_INCLUDE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../external/grpc/include"
17)
18
19corrosion_set_env_vars(
20  netsim-cli
21  CARGO_HOME=${Rust_CARGO_HOME}
22  GRPCIO_SYS_GRPC_INCLUDE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../external/grpc/include"
23)
24corrosion_set_env_vars(
25  netsim-proto
26  CARGO_HOME=${Rust_CARGO_HOME}
27  GRPCIO_SYS_GRPC_INCLUDE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../external/grpc/include"
28)
29
30add_custom_target(
31  netsim_rust_packets
32  DEPENDS pdl_gen-RootCanalGeneratedPackets_rs pdl_gen-NetlinkPackets_rs
33          pdl_gen-Ieee80211Packets_rs pdl_gen-Mac80211HwsimPackets_rs)
34
35# Make sure we have the rust packets generated before we build them.
36add_dependencies(cargo-build_netsim-daemon netsim_rust_packets)
37
38# cxx crates
39if(WIN32)
40  # 1. Set CMAKE_CXX_FLAGS, as it is not set in Rust crates imported by
41  #    corrosion.
42  # 2. Set RUST_CXX_NO_EXCEPTIONS preprocesor definition for cxx crate to disable
43  #    compilation error message of "cannot use 'throw' with exceptions".
44  # 3. MSVC uses environment variable "CL" to prepend arguments to the
45  #    command-line arguments. However, we verified MSVC also supports CXXFLAGS,
46  #    which is used by cc crate.
47  # 4. This isn't needed in mac and Linux because corrosion doesn't pass
48  #    -fno-exception flag.
49  set(CXXFLAGS "${CMAKE_CXX_FLAGS} /DRUST_CXX_NO_EXCEPTIONS")
50  corrosion_set_env_vars(netsim-cli CXXFLAGS=${CXXFLAGS})
51  corrosion_set_env_vars(netsim-daemon CXXFLAGS=${CXXFLAGS})
52endif()
53
54if(LINUX)
55  # b/260271048
56  set(RUSTFLAGS "-Clink-args=-Wl,-rpath,${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
57  corrosion_add_target_rustflags(netsim-cli ${RUSTFLAGS})
58  corrosion_add_target_rustflags(netsim-daemon ${RUSTFLAGS})
59endif()
60
61add_subdirectory(proto)
62
63# Steps to generate protobuf -> rust files are as follows:
64#
65# 1. Install protobuf for protoc binary.
66#
67# Linux: sudo apt-get install protobuf-compiler
68#
69# Mac: brew install protobuf
70#
71# 1. Uncomment the following lines in rust/proto/Cargo.toml. build =
72#    "build_cargo.rs" protobuf = "=3.2.0" protobuf-codegen = "3.2.0"
73# 2. export CARGO_HOME=$REPO_EMU/tools/netsim/objs/rust/.cargo
74# 3. cd $REPO_EMU/tools/netsim
75# 4. cargo build --manifest-path rust/proto/Cargo.toml
76# 5. git checkout rust/proto/Cargo.toml
77# 6. bash scripts/format_code.sh
78
79android_license(TARGET "netsim-daemon" LIBNAME None SPDX None LICENSE None
80                LOCAL None)
81android_license(TARGET "netsim-proto" LIBNAME None SPDX None LICENSE None
82                LOCAL None)
83
84add_library(netsim-cli-rust-lib INTERFACE)
85
86target_link_libraries(netsim-cli-rust-lib INTERFACE netsim-proto netsim-cli)
87
88android_license(TARGET netsim-cli-rust-lib LIBNAME None SPDX None LICENSE None
89                LOCAL None)
90