Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 418c3e17 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge changes I2e7327a7,Iab1c8974,I786f3593

* changes:
  RootCanal: Simplify hci_packets.pdl
  RootCanal: Migrate to :pdl for the generation of rust lmp backend
  floss: Remove rootcanal build rules
parents f3495593 4e72f180
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ VALID_TARGETS = [
    'hosttools',  # Build the host tools (i.e. packetgen)
    'main',  # Build the main C++ codebase
    'prepare',  # Prepare the output directory (gn gen + rust setup)
    'rootcanal',  # Build Rust targets for RootCanal
    'rust',  # Build only the rust components + copy artifacts to output dir
    'test',  # Run the unit tests
    'utils',  # Build Floss utils
@@ -459,15 +458,6 @@ class HostBuild():
        """
        self._rust_build()

    def _target_rootcanal(self):
        """ Build rust artifacts for RootCanal in an already prepared environment.
        """
        cmd = ['cargo', 'build']
        if not self.args.rust_debug:
            cmd.append('--release')

        self.run_command('rust', cmd, cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)

    def _target_main(self):
        """ Build the main GN artifacts in an already prepared environment.
        """
@@ -485,7 +475,6 @@ class HostBuild():
            rust_test_cmd = rust_test_cmd + [self.args.test_name, "--", "--test-threads=1", "--nocapture"]

        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt'), env=self.env)
        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)

        # Host tests second based on host test list
        for t in HOST_TESTS:
@@ -566,7 +555,6 @@ class HostBuild():
        # Remove Cargo.lock that may have become generated
        cargo_lock_files = [
            os.path.join(self.platform_dir, 'bt', 'Cargo.lock'),
            os.path.join(self.platform_dir, 'bt', 'tools', 'rootcanal', 'Cargo.lock'),
        ]
        for lock_file in cargo_lock_files:
            try:
@@ -597,8 +585,6 @@ class HostBuild():
            self._target_prepare()
        elif self.target == 'hosttools':
            self._target_hosttools()
        elif self.target == 'rootcanal':
            self._target_rootcanal()
        elif self.target == 'rust':
            self._target_rust()
        elif self.target == 'docs':
+48 −1
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ corrosion_import_crate(

corrosion_set_env_vars(generate-canonical-tests CARGO_HOME=${Rust_CARGO_HOME})
corrosion_set_env_vars(pdl CARGO_HOME=${Rust_CARGO_HOME})
corrosion_set_hostbuild(pdl)

get_property(pdl_EXECUTABLE TARGET pdl PROPERTY IMPORTED_LOCATION_RELEASE)

# These tests depend on the tempfile crate which was not imported because
# the crate remove_dir_all does not have a compatible version.
@@ -15,12 +18,56 @@ set_tests_properties(cargo-test_pdl PROPERTIES DISABLED True)
set_tests_properties(cargo-test_generate-canonical-tests PROPERTIES DISABLED True)

android_license(
    TARGET "pdl"
    TARGET pdl
    LIBNAME None
    SPDX None
    LICENSE None
    LOCAL None)

# Generate the Rust/C++ backend for a .pdl specification file.
function(pdl_gen)
  # Parse arguments.
  set(options)
  set(oneValueArgs NAME INPUT OUTPUT LANG)
  cmake_parse_arguments(pdl "${options}" "${oneValueArgs}"
                        "${multiValueArgs}" ${ARGN})

  if(NOT pdl_NAME)
    message(FATAL_ERROR "Error: name not specified")
  endif()

  if(NOT pdl_INPUT)
    message(FATAL_ERROR "Error: output file not specified")
  endif()

  if(NOT pdl_OUTPUT)
    message(FATAL_ERROR "Error: output file not specified")
  endif()

  set(pdl_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/pdl_gen)
  set(pdl_OUTPUT "${pdl_OUTPUT_DIR}/${pdl_OUTPUT}")

  get_filename_component(pdl_INPUT_ABSOLUTE ${pdl_INPUT} ABSOLUTE)
  get_filename_component(pdl_OUTPUT_ABSOLUTE ${pdl_OUTPUT} ABSOLUTE)
  get_filename_component(pdl_OUTPUT_DIR ${pdl_OUTPUT_ABSOLUTE} DIRECTORY)
  set(${pdl_NAME} "${pdl_OUTPUT_ABSOLUTE}" PARENT_SCOPE)

  file(MAKE_DIRECTORY ${pdl_OUTPUT_DIR})

  if(pdl_LANG STREQUAL "rust")
    add_custom_command(
        OUTPUT "${pdl_OUTPUT_ABSOLUTE}"
        COMMAND
        ${pdl_EXECUTABLE}
                --output-format rust
                "${pdl_INPUT_ABSOLUTE}"
                    > "${pdl_OUTPUT_ABSOLUTE}"
        COMMENT "Generating rust module from ${pdl_INPUT}"
        VERBATIM
        DEPENDS pdl ${pdl_INPUT_ABSOLUTE})
  endif()
endfunction()

# ~~~
# ! foobar : Compile .pdl files to C++/Rust!
#
+6 −12
Original line number Diff line number Diff line
@@ -77,8 +77,7 @@ std::vector<uint8_t> PcapFilter::FilterHciCommand(
    case OpCode::LE_SET_PERIODIC_ADVERTISING_DATA:
      return FilterLeSetPeriodicAdvertisingData(command);
    case OpCode::LE_MULTI_ADVT: {
      auto le_multi_advt_command =
          LeMultiAdvtView::Create(LeAdvertisingCommandView::Create(command));
      auto le_multi_advt_command = LeMultiAdvtView::Create(command);
      ASSERT(le_multi_advt_command.IsValid());
      switch (le_multi_advt_command.GetSubCmd()) {
        case SubOcf::SET_DATA:
@@ -231,8 +230,7 @@ std::vector<uint8_t> PcapFilter::FilterWriteExtendedInquiryResponse(
// Replace the device names in the GAP entries of the advertising data.
std::vector<uint8_t> PcapFilter::FilterLeSetAdvertisingData(
    CommandView& command) {
  auto parameters = LeSetAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -244,8 +242,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetAdvertisingData(
// Replace the device names in the GAP entries of the scan response data.
std::vector<uint8_t> PcapFilter::FilterLeSetScanResponseData(
    CommandView& command) {
  auto parameters = LeSetScanResponseDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetScanResponseDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -257,8 +254,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetScanResponseData(
// Replace the device names in the GAP entries of the extended advertising data.
std::vector<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData(
    CommandView& command) {
  auto parameters = LeSetExtendedAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetExtendedAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -273,8 +269,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData(
// data.
std::vector<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData(
    CommandView& command) {
  auto parameters = LeSetExtendedScanResponseDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetExtendedScanResponseDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetScanResponseData();
@@ -289,8 +284,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData(
// data.
std::vector<uint8_t> PcapFilter::FilterLeSetPeriodicAdvertisingData(
    bluetooth::hci::CommandView& command) {
  auto parameters = LeSetPeriodicAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetPeriodicAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
+3 −10
Original line number Diff line number Diff line
@@ -34,16 +34,9 @@ rust_ffi {

genrule {
    name: "LmpGeneratedPackets_rust",
    tools: [
        "bluetooth_packetgen",
    ],
    cmd: "$(location bluetooth_packetgen) --include=packages/modules/Bluetooth/tools/rootcanal/lmp  --out=$(genDir) $(in) --rust",
    srcs: [
        "lmp_packets.pdl",
    ],
    out: [
        "lmp_packets.rs",
    ],
    defaults: ["pdl_rust_generator_defaults"],
    srcs: ["lmp_packets.pdl"],
    out: ["lmp_packets.rs"],
}

rust_test_host {
+15 −10
Original line number Diff line number Diff line
message(STATUS "Enabling bluetooth LMP module.")

# TODO(b/279494407): migrate hci packets to new generator
android_bluetooth_packet_gen(
  GENERATED HciGeneratedPackets_rs INCLUDES gd SRC hci/hci_packets.pdl
  SOURCE_DIR ${BT_ROOT} LANG rust)

android_bluetooth_packet_gen(
  GENERATED LmpGeneratedPackets_rs INCLUDES lmp SRC lmp_packets.pdl
    GENERATED hci_packets_rs INCLUDES packets SRC hci/hci_packets.pdl
    SOURCE_DIR ${ROOTCANAL_ROOT} LANG rust)

pdl_gen(
    NAME lmp_packets_rs
    INPUT ${ROOTCANAL_ROOT}/lmp/lmp_packets.pdl
    OUTPUT lmp_packets.rs
    LANG rust)

# This will automatically register all the tests as well.
corrosion_import_crate(MANIFEST_PATH ${ROOTCANAL_ROOT}/lmp/Cargo.toml FLAGS
                       --offline --verbose --verbose)
corrosion_set_env_vars(lmp
  LMP_PACKETS_PREBUILT=${LmpGeneratedPackets_rs}
  HCI_PACKETS_PREBUILT=${HciGeneratedPackets_rs}
  LMP_PACKETS_PREBUILT=${lmp_packets_rs}
  HCI_PACKETS_PREBUILT=${hci_packets_rs}
  CARGO_HOME=${Rust_CARGO_HOME})

android_license(TARGET "lmp" LIBNAME None SPDX None LICENSE None LOCAL None)

add_custom_target(lmp_rust_packets DEPENDS ${LmpGeneratedPackets_rs}
                                           ${HciGeneratedPackets_rs})
add_custom_target(lmp_rust_packets DEPENDS ${lmp_packets_rs}
                                           ${hci_packets_rs})

# Make sure we have the rust packets generated before we build them.
add_dependencies(cargo-build_lmp lmp_rust_packets)

# Enable lmp in rootcanal
# Enable lmp in rootcanal.
target_link_libraries(libbt-rootcanal PUBLIC lmp)
target_include_directories(libbt-rootcanal
    PUBLIC ${ROOTCANAL_ROOT}/lmp/include)
Loading