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

Commit e19c23ef authored by David Duarte's avatar David Duarte
Browse files

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
parent d05ca97f
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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"],
+13 −2
Original line number Diff line number Diff line
@@ -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",
+20 −3
Original line number Diff line number Diff line
@@ -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 {
+10 −7
Original line number Diff line number Diff line
@@ -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",
    ],
+12 −0
Original line number Diff line number Diff line
@@ -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();