• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1set(BT_ROOT ${AOSP_ROOT}/packages/modules/Bluetooth)
2set(ROOTCANAL_ROOT ${AOSP_ROOT}/packages/modules/Bluetooth/tools/rootcanal)
3set(PDL_ROOT ${AOSP_ROOT}/external/rust/crates/pdl-compiler)
4
5corrosion_import_crate(
6    MANIFEST_PATH ${PDL_ROOT}/Cargo.toml
7    FLAGS --offline --verbose --verbose)
8
9corrosion_set_env_vars(pdlc CARGO_HOME=${Rust_CARGO_HOME})
10corrosion_set_hostbuild(pdlc)
11
12get_property(pdlc_EXECUTABLE TARGET pdlc PROPERTY EXECUTABLE_PATH)
13
14# These tests depend on the tempfile crate which was not imported because
15# the crate remove_dir_all does not have a compatible version.
16set_tests_properties(cargo-test_pdlc PROPERTIES DISABLED True)
17
18android_license(
19    TARGET pdlc
20    LIBNAME None
21    SPDX None
22    LICENSE None
23    LOCAL None)
24
25# Generate the Rust/C++ backend for a .pdl specification file.
26function(pdl_gen)
27  # Parse arguments.
28  set(options)
29  set(oneValueArgs NAME INPUT OUTPUT LANG NAMESPACE)
30  set(multiValueArgs USING INCLUDE)
31  cmake_parse_arguments(pdl "${options}" "${oneValueArgs}"
32                        "${multiValueArgs}" ${ARGN})
33
34  if(NOT pdl_NAME)
35    message(FATAL_ERROR "Error: name not specified")
36  endif()
37
38  if(NOT pdl_INPUT)
39    message(FATAL_ERROR "Error: output file not specified")
40  endif()
41
42  if(NOT pdl_OUTPUT)
43    message(FATAL_ERROR "Error: output file not specified")
44  endif()
45
46  set(pdl_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/pdl_gen)
47  set(pdl_OUTPUT "${pdl_OUTPUT_DIR}/${pdl_OUTPUT}")
48
49  get_filename_component(pdl_INPUT_ABSOLUTE ${pdl_INPUT} ABSOLUTE)
50  get_filename_component(pdl_OUTPUT_ABSOLUTE ${pdl_OUTPUT} ABSOLUTE)
51  get_filename_component(pdl_OUTPUT_DIR ${pdl_OUTPUT_ABSOLUTE} DIRECTORY)
52  set(${pdl_NAME} "${pdl_OUTPUT_ABSOLUTE}" CACHE STRING "PDL output filepath for ${pdl_NAME}" FORCE)
53
54  file(MAKE_DIRECTORY ${pdl_OUTPUT_DIR})
55
56  if((pdl_LANG STREQUAL "rust") OR (pdl_LANG STREQUAL "rust_legacy"))
57    add_custom_command(
58        OUTPUT "${pdl_OUTPUT_ABSOLUTE}"
59        COMMAND
60        ${pdlc_EXECUTABLE}
61                --output-format "${pdl_LANG}"
62                "${pdl_INPUT_ABSOLUTE}"
63                    > "${pdl_OUTPUT_ABSOLUTE}"
64        COMMENT "Generating rust module from ${pdl_INPUT}"
65        VERBATIM
66        DEPENDS pdlc ${pdl_INPUT_ABSOLUTE})
67  endif()
68
69  if(pdl_LANG STREQUAL "c++")
70    if(NOT pdl_NAMESPACE)
71        message(FATAL_ERROR "Error: namespace not specified")
72    endif()
73
74    foreach(namespace ${pdl_USING})
75        list(APPEND pdl_FLAGS --using-namespace)
76        list(APPEND pdl_FLAGS ${namespace})
77    endforeach()
78    foreach(header ${pdl_INCLUDE})
79        list(APPEND pdl_FLAGS --include-header)
80        list(APPEND pdl_FLAGS ${header})
81    endforeach()
82
83    add_custom_command(
84        OUTPUT "${pdl_OUTPUT_ABSOLUTE}.json"
85        COMMAND
86        ${pdlc_EXECUTABLE}
87                --output-format json
88                "${pdl_INPUT_ABSOLUTE}"
89                    > "${pdl_OUTPUT_ABSOLUTE}.json"
90        COMMENT "Analyzing ${pdl_INPUT}"
91        VERBATIM
92        DEPENDS pdlc ${pdl_INPUT_ABSOLUTE})
93
94    add_custom_command(
95        OUTPUT "${pdl_OUTPUT_ABSOLUTE}"
96        COMMAND
97        ${PDL_ROOT}/scripts/generate_cxx_backend.py
98                --input "${pdl_OUTPUT_ABSOLUTE}.json"
99                --output "${pdl_OUTPUT_ABSOLUTE}"
100                --namespace ${pdl_NAMESPACE}
101                ${pdl_FLAGS}
102        COMMENT "Generating c++ header from ${pdl_INPUT}"
103        VERBATIM
104        DEPENDS pdlc ${pdl_OUTPUT_ABSOLUTE}.json)
105  endif()
106
107  add_custom_target("pdl_gen-${pdl_NAME}" DEPENDS ${pdl_OUTPUT_ABSOLUTE})
108endfunction()
109
110pdl_gen(
111  NAME BluetoothGeneratedPackets_h
112  INPUT ${ROOTCANAL_ROOT}/packets/hci_packets.pdl
113  OUTPUT packets/hci_packets.h
114  LANG c++
115  NAMESPACE "bluetooth::hci"
116  INCLUDE "hci/address.h")
117
118pdl_gen(
119  NAME RootCanalGeneratedPackets_h
120  INPUT ${ROOTCANAL_ROOT}/packets/link_layer_packets.pdl
121  OUTPUT packets/link_layer_packets.h
122  LANG c++
123  NAMESPACE model::packets
124  INCLUDE "hci/address.h"
125  USING "bluetooth::hci")
126
127pdl_gen(
128  NAME RootCanalGeneratedPackets_rs
129  INPUT ${ROOTCANAL_ROOT}/packets/link_layer_packets.pdl
130  OUTPUT link_layer_packets.rs
131  LANG rust_legacy)
132
133android_add_library(
134  TARGET librootcanal_config LICENSE Apache-2.0
135  SOURCE_DIR ${ROOTCANAL_ROOT} SRC ${librootcanal_config_src})
136
137protobuf_generate_with_plugin(
138  TARGET librootcanal_config
139  PROTOS ${ROOTCANAL_ROOT}/proto/rootcanal/configuration.proto
140  APPEND_PATH
141  PROTOPATH -I${AOSP_ROOT}/external/protobuf/src
142  PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto/rootcanal)
143
144target_include_directories(
145  librootcanal_config
146  PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/proto ${AOSP_ROOT}/external/protobuf/src)
147
148target_link_libraries(librootcanal_config
149                      PRIVATE protobuf::libprotobuf)
150
151add_library(libbt-rootcanal.headers INTERFACE)
152target_include_directories(libbt-rootcanal.headers INTERFACE ${ROOTCANAL_ROOT})
153target_link_libraries(libbt-rootcanal.headers
154                      INTERFACE android-emu-base-headers)
155android_license(TARGET "libbt-rootcanal.headers" LIBNAME None SPDX Apache-2.0
156                LICENSE Apache-2.0 LOCAL "${BT_ROOT}/NOTICE")
157
158android_add_library(
159  TARGET librootcanal_log
160  LICENSE Apache-2.0
161  SOURCE_DIR ${ROOTCANAL_ROOT}
162  SRC lib/log.cc
163      ${AOSP_ROOT}/external/fmtlib/src/format.cc)
164
165target_include_directories(
166  librootcanal_log PUBLIC
167    ${ROOTCANAL_ROOT}/include
168    ${AOSP_ROOT}/external/fmtlib/include)
169
170android_add_library(
171  TARGET libbt-rootcanal
172  LICENSE Apache-2.0
173  SOURCE_DIR ${ROOTCANAL_ROOT}
174  SRC ${BluetoothGeneratedPackets_h}
175      ${RootCanalGeneratedPackets_h}
176      lib/crypto/crypto.cc
177      lib/hci/address.cc
178      lib/hci/pcap_filter.cc
179      lib/log.cc
180      model/controller/acl_connection.cc
181      model/controller/acl_connection_handler.cc
182      model/controller/controller_properties.cc
183      model/controller/dual_mode_controller.cc
184      model/controller/le_advertiser.cc
185      model/controller/link_layer_controller.cc
186      model/controller/sco_connection.cc
187      model/controller/vendor_commands/le_apcf.cc
188      model/devices/beacon.cc
189      model/devices/device.cc
190      model/devices/hci_device.cc
191      model/devices/link_layer_socket_device.cc
192      model/devices/sniffer.cc
193      model/hci/h4_data_channel_packetizer.cc
194      model/hci/h4_parser.cc
195      model/hci/hci_sniffer.cc
196      model/hci/hci_socket_transport.cc
197      model/setup/device_boutique.cc
198      model/setup/phy_device.cc
199      model/setup/phy_layer.cc
200      model/setup/test_channel_transport.cc
201      model/setup/test_command_handler.cc
202      model/setup/test_model.cc
203  LINUX net/posix/posix_async_socket.cc
204        net/posix/posix_async_socket_connector.cc
205        net/posix/posix_async_socket_server.cc
206  DARWIN net/posix/posix_async_socket.cc
207         net/posix/posix_async_socket_connector.cc
208         net/posix/posix_async_socket_server.cc
209  DEPS android-emu-base
210       android-emu-base-headers
211       android-emu-base-logging
212       crypto
213       librootcanal_config)
214
215target_link_libraries(
216  libbt-rootcanal
217  PUBLIC librootcanal_log)
218
219target_include_directories(
220  libbt-rootcanal
221  PUBLIC ${ROOTCANAL_ROOT}/include
222         ${ROOTCANAL_ROOT}
223         ${PDL_ROOT}/scripts
224         ${CMAKE_CURRENT_BINARY_DIR}/pdl_gen
225         ${CMAKE_CURRENT_BINARY_DIR}/config)
226
227target_compile_options(libbt-rootcanal
228                       PUBLIC -Wno-inconsistent-missing-override)
229
230add_subdirectory(rust)
231