aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Duarte <licorne@google.com>2021-10-28 09:58:18 +0000
committerDavid Duarte <licorne@google.com>2021-10-29 13:22:15 +0000
commit0850cf467a636323e3325d37fc435cca4e85da69 (patch)
tree3c599807d021ecc4dd95bbd0c282c149397068da
parent9639a1f376a76faa71c3f1aad5d05436f4742cd1 (diff)
downloadbt-0850cf467a636323e3325d37fc435cca4e85da69.tar.gz
topshim/facade: Don't link with libbluetooth twice
libbluetooth was linked statically and dynamically causing a lot of issue because of duplicated instances, to fix that we only link with libbluetooth statically. Linking statically with libluetooth is not straightforward because of the dependency with bt_shim that depends on rust crates that are used by bt_topshim_facade too, leading to linking twice with theses libs and so the linker complaining of duplicate symbols. To fix that we instead pass bt_shim as dependency of bt_topshim_facade so the rust compiler will take care of only including the transitive dependencies once Test: m bt_topshim_facade Test: out/host/linux-x86/bin/bt_topshim_facade Change-Id: Ic24f383a4b2f9eda17f33dd344a90e416c482582
-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/facade/Android.bp17
-rw-r--r--gd/rust/topshim/facade/src/main.rs12
5 files changed, 68 insertions, 14 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/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();