aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-11-03 16:13:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-03 16:13:33 +0000
commit2708654d99180d87f865039d8fb272b471926aab (patch)
treed05cf75fda6f7c210b54392868d973aacf08703f
parentfc6625b245433d4b59d2468864efb9b77ccaf432 (diff)
parent33f5b91d8fbd8006042c98a6af999d10d26cc185 (diff)
downloadbt-2708654d99180d87f865039d8fb272b471926aab.tar.gz
Merge changes I98a14186,Ic24f383a
* changes: topshim: Add controller shim topshim/facade: Don't link with libbluetooth twice
-rw-r--r--btcore/Android.bp15
-rw-r--r--btif/Android.bp15
-rw-r--r--gd/rust/shim/Android.bp23
-rw-r--r--gd/rust/topshim/Android.bp3
-rw-r--r--gd/rust/topshim/BUILD.gn7
-rw-r--r--gd/rust/topshim/controller/controller_shim.cc54
-rw-r--r--gd/rust/topshim/controller/controller_shim.h49
-rw-r--r--gd/rust/topshim/facade/Android.bp17
-rw-r--r--gd/rust/topshim/facade/src/main.rs12
-rw-r--r--gd/rust/topshim/facade/utils.proto13
-rw-r--r--gd/rust/topshim/src/controller.rs32
-rw-r--r--gd/rust/topshim/src/lib.rs1
12 files changed, 225 insertions, 16 deletions
diff --git a/btcore/Android.bp b/btcore/Android.bp
index f96877f61..ea71c7914 100644
--- a/btcore/Android.bp
+++ b/btcore/Android.bp
@@ -8,8 +8,8 @@ package {
default_applicable_licenses: ["system_bt_license"],
}
-cc_library_static {
- name: "libbtcore",
+cc_defaults {
+ name: "libbtcore_defaults",
defaults: ["fluoride_defaults"],
local_include_dirs: ["include"],
include_dirs: [
@@ -35,6 +35,17 @@ cc_library_static {
},
}
+cc_library_static {
+ name: "libbtcore",
+ defaults: ["libbtcore_defaults"],
+}
+
+cc_library_static {
+ name: "libbtcore-static",
+ defaults: ["libbtcore_defaults"],
+ cflags: ["-DSTATIC_LIBBLUETOOTH"],
+}
+
cc_library_headers {
name: "libbtcore_headers",
defaults: ["libchrome_support_defaults"],
diff --git a/btif/Android.bp b/btif/Android.bp
index 238f964e9..bbdcebddc 100644
--- a/btif/Android.bp
+++ b/btif/Android.bp
@@ -88,8 +88,8 @@ genrule {
}
// libbtif static library for target
-cc_library_static {
- name: "libbtif",
+cc_defaults {
+ name: "libbtif_defaults",
defaults: ["fluoride_defaults"],
include_dirs: btifCommonIncludes,
srcs: [
@@ -195,6 +195,17 @@ cc_library_static {
host_supported: true,
}
+cc_library_static {
+ name: "libbtif",
+ defaults: ["libbtif_defaults"],
+}
+
+cc_library_static {
+ name: "libbtif-static",
+ defaults: ["libbtif_defaults"],
+ cflags: ["-DSTATIC_LIBBLUETOOTH"],
+}
+
// btif unit tests for target
cc_test {
name: "net_test_btif",
diff --git a/gd/rust/shim/Android.bp b/gd/rust/shim/Android.bp
index 6db3bfde1..b5b60426f 100644
--- a/gd/rust/shim/Android.bp
+++ b/gd/rust/shim/Android.bp
@@ -26,8 +26,8 @@ cc_defaults {
},
}
-rust_ffi_static {
- name: "libbt_shim_ffi",
+rust_defaults {
+ name: "libbt_shim_defaults",
defaults: ["gd_rust_defaults"],
crate_name: "bt_shim",
srcs: ["src/lib.rs"],
@@ -51,8 +51,18 @@ rust_ffi_static {
],
}
+rust_library_rlib {
+ name: "libbt_shim",
+ defaults: ["libbt_shim_defaults"],
+}
+
+rust_ffi_static {
+ name: "libbt_shim_ffi",
+ defaults: ["libbt_shim_defaults"],
+}
+
cc_library_static {
- name: "libbluetooth_rust_interop",
+ name: "libbt_shim_bridge",
defaults: ["gd_ffi_defaults"],
generated_headers: [
"libbt_init_flags_bridge_header",
@@ -87,9 +97,16 @@ cc_library_static {
shared_libs: [
"libchrome",
],
+}
+
+cc_library_static {
+ name: "libbluetooth_rust_interop",
+ defaults: ["gd_ffi_defaults"],
whole_static_libs: [
+ "libbt_shim_bridge",
"libbt_shim_ffi",
],
+ host_supported: true,
}
cc_library_static {
diff --git a/gd/rust/topshim/Android.bp b/gd/rust/topshim/Android.bp
index 95326a631..1e9677ec0 100644
--- a/gd/rust/topshim/Android.bp
+++ b/gd/rust/topshim/Android.bp
@@ -51,6 +51,7 @@ cc_library_static {
"btif/btif_shim.cc",
"gatt/gatt_shim.cc",
"hfp/hfp_shim.cc",
+ "controller/controller_shim.cc",
],
generated_headers: ["libbt_topshim_bridge_header", "cxx-bridge-header"],
generated_sources: ["libbt_topshim_bridge_code"],
@@ -76,6 +77,7 @@ gensrcs {
"src/profiles/avrcp.rs",
"src/profiles/hfp.rs",
"src/profiles/gatt.rs",
+ "src/controller.rs",
],
output_extension: "rs.h",
export_include_dirs: ["."],
@@ -91,6 +93,7 @@ gensrcs {
"src/profiles/avrcp.rs",
"src/profiles/hfp.rs",
"src/profiles/gatt.rs",
+ "src/controller.rs",
],
output_extension: "cc",
export_include_dirs: ["."],
diff --git a/gd/rust/topshim/BUILD.gn b/gd/rust/topshim/BUILD.gn
index d6e225296..bf986cb4b 100644
--- a/gd/rust/topshim/BUILD.gn
+++ b/gd/rust/topshim/BUILD.gn
@@ -29,6 +29,7 @@ cxxbridge_header("btif_bridge_header") {
"src/profiles/avrcp.rs",
"src/profiles/hfp.rs",
"src/profiles/gatt.rs",
+ "src/controller.rs",
]
all_dependent_configs = [ ":rust_topshim_config" ]
deps = [":cxxlibheader"]
@@ -41,8 +42,9 @@ cxxbridge_cc("btif_bridge_code") {
"src/profiles/avrcp.rs",
"src/profiles/hfp.rs",
"src/profiles/gatt.rs",
+ "src/controller.rs",
]
- deps = [":btif_bridge_header"]
+ deps = [":btif_bridge_header", "//bt/gd:BluetoothGeneratedPackets_h"]
configs = [ "//bt/gd:gd_defaults" ]
}
@@ -53,9 +55,10 @@ source_set("btif_cxx_bridge_code") {
"btav_sink/btav_sink_shim.cc",
"hfp/hfp_shim.cc",
"gatt/gatt_shim.cc",
+ "controller/controller_shim.cc",
]
- deps = [":btif_bridge_header"]
+ deps = [":btif_bridge_header", "//bt/gd:BluetoothGeneratedPackets_h"]
configs += ["//bt/gd:gd_defaults"]
}
diff --git a/gd/rust/topshim/controller/controller_shim.cc b/gd/rust/topshim/controller/controller_shim.cc
new file mode 100644
index 000000000..cd04f4f8f
--- /dev/null
+++ b/gd/rust/topshim/controller/controller_shim.cc
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "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 "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.
+ */
+
+#include "gd/rust/topshim/controller/controller_shim.h"
+
+#include <memory>
+
+#include "rust/cxx.h"
+#include "src/controller.rs.h"
+#include "types/raw_address.h"
+
+namespace bluetooth {
+namespace topshim {
+namespace rust {
+namespace internal {
+static ControllerIntf* g_controller_intf;
+
+static RustRawAddress to_rust_address(const RawAddress& address) {
+ RustRawAddress raddr;
+ std::copy(std::begin(address.address), std::end(address.address), std::begin(raddr.address));
+ return raddr;
+}
+} // namespace internal
+
+ControllerIntf::~ControllerIntf() {}
+
+std::unique_ptr<ControllerIntf> GetControllerInterface() {
+ if (internal::g_controller_intf) std::abort();
+ auto controller_intf = std::make_unique<ControllerIntf>();
+ internal::g_controller_intf = controller_intf.get();
+ return controller_intf;
+}
+
+RustRawAddress ControllerIntf::read_local_addr() const {
+ if (!controller_) std::abort();
+ return internal::to_rust_address(*controller_->get_address());
+}
+
+} // namespace rust
+} // namespace topshim
+} // namespace bluetooth
diff --git a/gd/rust/topshim/controller/controller_shim.h b/gd/rust/topshim/controller/controller_shim.h
new file mode 100644
index 000000000..b817ee913
--- /dev/null
+++ b/gd/rust/topshim/controller/controller_shim.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "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 "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.
+ */
+#ifndef GD_RUST_TOPSHIM_CONTROLLER_SHIM
+#define GD_RUST_TOPSHIM_CONTROLLER_SHIM
+
+#include <memory>
+
+#include "main/shim/controller.h"
+#include "rust/cxx.h"
+#include "types/raw_address.h"
+
+namespace bluetooth {
+namespace topshim {
+namespace rust {
+
+struct RustRawAddress;
+
+class ControllerIntf {
+ public:
+ ControllerIntf() : controller_(controller_get_interface()) {}
+ ~ControllerIntf();
+
+ RustRawAddress read_local_addr() const;
+
+ private:
+ const controller_t* controller_;
+};
+
+// ControllerIntf* GetControllerInterface();
+std::unique_ptr<ControllerIntf> GetControllerInterface();
+
+} // namespace rust
+} // namespace topshim
+} // namespace bluetooth
+
+#endif // GD_RUST_TOPSHIM_CONTROLLER_SHIM \ No newline at end of file
diff --git a/gd/rust/topshim/facade/Android.bp b/gd/rust/topshim/facade/Android.bp
index f0e185aaa..a92671bb3 100644
--- a/gd/rust/topshim/facade/Android.bp
+++ b/gd/rust/topshim/facade/Android.bp
@@ -12,6 +12,7 @@ rust_binary_host {
defaults: ["gd_rust_defaults"],
crate_name: "bt_topshim_facade",
srcs: ["src/main.rs"],
+ ld_flags: ["-fsanitize=undefined", "-fsanitize-minimal-runtime"],
rustlibs: [
"libbluetooth_rs",
"libbt_common",
@@ -25,17 +26,18 @@ rust_binary_host {
"libbt_facade_helpers",
"libbt_topshim",
"libbt_topshim_facade_protobuf",
+ "libbt_shim",
],
static_libs: [
"libbt_topshim_cxx",
"libbt-bta",
"libbt-common",
"libbtdevice",
- "libbtif",
+ "libbtif-static",
"libbt-hci",
"libbt-stack",
"libbt-utils",
- "libbtcore",
+ "libbtcore-static",
"libosi",
"libbt-protos-lite",
"libbte",
@@ -46,18 +48,19 @@ rust_binary_host {
"liblc3codec",
"libudrv-uipc",
"libbluetooth_gd", // Gabeldorsche
- "libbluetooth_rust_interop",
"libbluetooth-dumpsys",
+ "libbluetooth-types",
"libflatbuffers-cpp",
+ "libbt_shim_bridge",
],
shared_libs: [
"libcrypto",
- "libbluetooth",
"libchrome",
+ "liblog",
+ "libcutils",
+ "libgrpc++",
+ "libgrpc_wrap"
],
- sanitize: {
- never: true,
- },
proc_macros: [
"libpaste",
],
diff --git a/gd/rust/topshim/facade/src/main.rs b/gd/rust/topshim/facade/src/main.rs
index 073693333..44d27aa49 100644
--- a/gd/rust/topshim/facade/src/main.rs
+++ b/gd/rust/topshim/facade/src/main.rs
@@ -21,6 +21,18 @@ use tokio::runtime::Runtime;
mod adapter_service;
mod media_service;
+// This is needed for linking, libbt_shim_bridge needs symbols defined by
+// bt_shim, however bt_shim depends on rust crates (future, tokio) that
+// we use too, if we build and link them separately we ends with duplicate
+// symbols. To solve that we build bt_shim with bt_topshim_facade so the rust
+// compiler share the transitive dependencies.
+//
+// The `::*` is here to circuvent the single_component_path_imports from
+// clippy that is denied on the rust command line so we can't just allow it.
+// This is fine for now since bt_shim doesn't export anything
+#[allow(unused)]
+use bt_shim::*;
+
fn main() {
let sigint = install_sigint();
bt_common::init_logging();
diff --git a/gd/rust/topshim/facade/utils.proto b/gd/rust/topshim/facade/utils.proto
new file mode 100644
index 000000000..9f0fd5cf0
--- /dev/null
+++ b/gd/rust/topshim/facade/utils.proto
@@ -0,0 +1,13 @@
+syntax = "proto3";
+
+package blueberry;
+
+message Empty {}
+
+message BluetoothAddress {
+ bytes address = 1;
+}
+
+service ReadOnlyProperty {
+ rpc ReadLocalAddress(Empty) returns (BluetoothAddress) {}
+} \ No newline at end of file
diff --git a/gd/rust/topshim/src/controller.rs b/gd/rust/topshim/src/controller.rs
new file mode 100644
index 000000000..198492822
--- /dev/null
+++ b/gd/rust/topshim/src/controller.rs
@@ -0,0 +1,32 @@
+#[cxx::bridge(namespace = bluetooth::topshim::rust)]
+mod ffi {
+ pub struct RustRawAddress {
+ address: [u8; 6],
+ }
+
+ unsafe extern "C++" {
+ include!("controller/controller_shim.h");
+
+ type ControllerIntf;
+
+ fn GetControllerInterface() -> UniquePtr<ControllerIntf>;
+ fn read_local_addr(self: &ControllerIntf) -> RustRawAddress;
+ }
+}
+
+pub struct Controller {
+ internal: cxx::UniquePtr<ffi::ControllerIntf>,
+}
+
+unsafe impl Send for Controller {}
+
+impl Controller {
+ pub fn new() -> Controller {
+ let intf = ffi::GetControllerInterface();
+ Controller { internal: intf }
+ }
+
+ pub fn read_local_addr(&mut self) -> [u8; 6] {
+ self.internal.read_local_addr().address
+ }
+}
diff --git a/gd/rust/topshim/src/lib.rs b/gd/rust/topshim/src/lib.rs
index a28f2aa26..c240ba811 100644
--- a/gd/rust/topshim/src/lib.rs
+++ b/gd/rust/topshim/src/lib.rs
@@ -8,5 +8,6 @@ extern crate bitflags;
pub mod bindings;
pub mod btif;
+pub mod controller;
pub mod profiles;
pub mod topstack;