# Copyright 2025 - The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the', help='License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an', help='AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """rootcanal bazel build rule""" load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_rust//rust:defs.bzl", "rust_library") package(default_visibility = ["//visibility:public"]) exports_files(["packets/link_layer_packets.pdl"]) proto_library( strip_import_prefix = "proto", name = "rootcanal-configuration-proto", srcs = [ "proto/rootcanal/configuration.proto", ], ) cc_proto_library( name = "rootcanal_configuration_cc_proto", deps = [":rootcanal-configuration-proto"], ) filegroup( name = "lib_sources", srcs = [ "lib/crypto/crypto.cc", "lib/hci/address.cc", "lib/hci/pcap_filter.cc", "lib/log.cc", ], visibility = ["//visibility:public"], ) cc_library( name = "rootcanal_defaults", # Maps to cflags copts = [ "-DGOOGLE_PROTOBUF_NO_RTTI", "-Wall", "-Werror", "-Wextra", "-fvisibility=hidden", ], # Maps to c_std and cpp_std local_defines = ["-std=c++20"], # Maps to include_dirs includes = [ "packages/modules/Bluetooth/tools/rootcanal/include", ], # Maps to header_libs and generated_headers deps = [ ], # Maps to visibility visibility = ["//visibility:public"], ) rust_library( name = "rootcanal_rs", srcs = glob(["rust/src/**/*.rs"]) + [ ":netsim_hci_packets_rust_gen", ":netsim_lmp_packets_rust_gen", ":netsim_llcp_packets_rust_gen", ], proc_macro_deps = [ "@num-derive", ], rustc_env = {"OUT_DIR": "../../packets"}, deps = [ "@bytes", "@num-bigint", "@num-traits", "@num-integer", "@pdl-runtime", "@pin-utils", "@rand", "@thiserror", ], ) # This rule converts `cc_library_host_shared`. # It links against the C++ standard library with `linkstatic = True`. cc_library( name = "lib_rootcanal_ffi", srcs = [ ":lib_sources", "model/controller/acl_connection.cc", "model/controller/acl_connection_handler.cc", "model/controller/controller_properties.cc", "model/controller/dual_mode_controller.cc", "model/controller/ffi.cc", "model/controller/le_advertiser.cc", "model/controller/link_layer_controller.cc", "model/controller/sco_connection.cc", "model/controller/vendor_commands/le_apcf.cc", "model/devices/device.cc", "model/setup/async_manager.cc", ], hdrs = glob(["include/**/*.h"] + ["model/controller/**/*.h"] + ["model/devices/*.h"] + ["model/setup/*.h"]) + [ ":rootcanal_bredr_bb_cxx_gen", ":rootcanal_hci_packets_cxx_gen", ":rootcanal_link_layer_packets_cxx_gen", "rust/include/rootcanal_rs.h", ], includes = [".", "include"], deps = [ ":rootcanal_defaults", ":generated_headers", "@pdl-runtime", "@pdl-compiler//:pdl_cxx_packet_runtime", ":rootcanal_configuration_cc_proto", "@fmtlib", ":rootcanal_rs", "@boringssl//:crypto", ], ) cc_library( name = "libbt-rootcanal", srcs = glob( ["model/controller/**/*.cc"] + ["model/devices/*.cc"] + ["model/hci/*.cc"] + ["model/setup/*.cc"] + ["net/**/*.cc"], exclude = ["model/controller/ffi.cc"], ) + [ ":lib_sources", ], hdrs = glob( ["include/**/*.h"] + ["model/controller/**/*.h"] + ["model/devices/*.h"] + ["model/hci/*.h"] + ["model/setup/*.h"] + ["net/**/*.h"], exclude = ["model/controller/ffi.h"], ) + [ "rust/include/rootcanal_rs.h", ], includes = [ ".", "include", ], deps = [ ":generated_headers", ":rootcanal_configuration_cc_proto", ":rootcanal_rs", "@pdl-compiler//:pdl_cxx_packet_runtime", "@fmtlib", "@boringssl//:crypto", ], ) cc_library( name = "generated_headers", hdrs = [ ":rootcanal_bredr_bb_cxx_gen", ":rootcanal_hci_packets_cxx_gen", ":rootcanal_link_layer_packets_cxx_gen", ], visibility = ["//visibility:public"], ) genrule( name = "rootcanal_hci_packets_cxx_gen", srcs = ["packets/hci_packets.pdl"], outs = ["packets/hci_packets.h"], cmd = "set -o pipefail; $(location @pdl-compiler//:pdlc) $(SRCS) | $(location @pdl-compiler//:pdl_cxx_generator) --namespace bluetooth::hci --include-header hci/address.h --output $(OUTS)", tools = ["@pdl-compiler//:pdlc", "@pdl-compiler//:pdl_cxx_generator"], ) genrule( name = "rootcanal_link_layer_packets_cxx_gen", srcs = ["packets/link_layer_packets.pdl"], outs = ["packets/link_layer_packets.h"], cmd = "set -o pipefail; $(location @pdl-compiler//:pdlc) $(SRCS) | $(location @pdl-compiler//:pdl_cxx_generator) --namespace model::packets --include-header hci/address.h --using-namespace bluetooth::hci --output $(OUTS)", tools = ["@pdl-compiler//:pdlc", "@pdl-compiler//:pdl_cxx_generator"], ) genrule( name = "rootcanal_bredr_bb_cxx_gen", srcs = ["packets/bredr_bb.pdl"], outs = ["bredr_bb.h"], cmd = "set -o pipefail; $(location @pdl-compiler//:pdlc) $(SRCS) | $(location @pdl-compiler//:pdl_cxx_generator) --namespace bredr_bb --include-header hci/address.h --using-namespace bluetooth::hci --output $(OUTS)", tools = ["@pdl-compiler//:pdlc", "@pdl-compiler//:pdl_cxx_generator"], ) genrule( name = "netsim_hci_packets_rust_gen", srcs = ["packets/hci_packets.pdl"], outs = ["packets/hci_packets.rs"], cmd = "$(location @pdl-compiler//:pdlc) --output-format rust $(SRCS) > $(OUTS)", tools = ["@pdl-compiler//:pdlc"], ) genrule( name = "netsim_lmp_packets_rust_gen", srcs = ["rust/lmp_packets.pdl"], outs = ["packets/lmp_packets.rs"], cmd = "$(location @pdl-compiler//:pdlc) --output-format rust $(SRCS) > $(OUTS)", tools = ["@pdl-compiler//:pdlc"], ) genrule( name = "netsim_llcp_packets_rust_gen", srcs = ["rust/llcp_packets.pdl"], outs = ["packets/llcp_packets.rs"], cmd = "$(location @pdl-compiler//:pdlc) --output-format rust $(SRCS) > $(OUTS)", tools = ["@pdl-compiler//:pdlc"], )