OSDN Git Service

rusty-gd: compile into libbluetooth
authorZach Johnson <zachoverflow@google.com>
Mon, 30 Nov 2020 17:17:18 +0000 (09:17 -0800)
committerZach Johnson <zachoverflow@google.com>
Wed, 2 Dec 2020 17:01:44 +0000 (09:01 -0800)
adds init flag entry point, currently prints flags

disable the BT apex since it's not shipped yet (won't be for a while)
and there are a bajillion rust libraries we'd need to add apex
availibility to.

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: I54cffe93d5819ffdc8229aef7be23f260483ab66

apex/Android.bp
gd/Android.bp
gd/common/init_flags.cc
gd/rust/common/Android.bp
gd/rust/common/src/init_flags.rs [new file with mode: 0644]
gd/rust/common/src/lib.rs
main/Android.bp

index fc143ba..3363123 100644 (file)
@@ -1,5 +1,6 @@
 apex {
     name: "com.android.bluetooth.updatable",
+    enabled: false,
 
     manifest: "apex_manifest.json",
 
index cffaf0c..116c324 100644 (file)
@@ -154,6 +154,7 @@ cc_defaults {
         "BluetoothGeneratedDumpsysDataSchema_h",
         "BluetoothGeneratedDumpsysBundledSchema_h",
         "BluetoothGeneratedPackets_h",
+        "libbt_common_bridge_header",
     ],
     shared_libs: [
         "libchrome",
@@ -162,7 +163,27 @@ cc_defaults {
     ],
     static_libs: [
         "libbluetooth-protos",
-    ]
+        "libbluetooth_rust_interop",
+        "libbt_common_ffi",
+        "libcxxbridge05",
+    ],
+}
+
+cc_library_static {
+    name: "libbluetooth_rust_interop",
+    generated_headers: ["libbt_common_bridge_header"],
+    generated_sources: ["libbt_common_bridge_code"],
+    cflags: [
+        "-Wno-unused-const-variable",
+    ],
+    host_supported: true,
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.bluetooth.updatable",
+    ],
+    static_libs: [
+        "libbt_common_ffi",
+    ],
 }
 
 cc_library {
index e62bddf..6a841fb 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "common/strings.h"
 #include "os/log.h"
+#include "src/init_flags.rs.h"
 
 namespace bluetooth {
 namespace common {
@@ -51,6 +52,13 @@ bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string&
 }
 
 void InitFlags::Load(const char** flags) {
+  rust::Vec<rust::String> rusted_flags = rust::Vec<rust::String>();
+  while (flags != nullptr && *flags != nullptr) {
+    rusted_flags.push_back(rust::String(*flags));
+    flags++;
+  }
+  init_flags_load(std::move(rusted_flags));
+
   SetAll(false);
   while (flags != nullptr && *flags != nullptr) {
     std::string flag_element = *flags;
index 61cc468..5db37a8 100644 (file)
@@ -7,6 +7,34 @@ rust_library {
         "libtokio",
         "libnix",
         "liblog_rust",
+        "libcxx",
+    ],
+    target: {
+        android: {
+            rustlibs: [
+                "libandroid_logger",
+            ],
+        },
+        host: {
+            rustlibs: [
+                "libenv_logger",
+            ],
+        },
+    },
+    host_supported: true,
+}
+
+rust_ffi_static {
+    name: "libbt_common_ffi",
+    stem: "libbt_common",
+    crate_name: "bt_common",
+    srcs: ["src/lib.rs"],
+    edition: "2018",
+    rustlibs: [
+        "libtokio",
+        "libnix",
+        "liblog_rust",
+        "libcxx",
     ],
     target: {
         android: {
@@ -33,5 +61,24 @@ rust_test_host {
         "libnix",
         "liblog_rust",
         "libenv_logger",
+        "libcxx",
     ],
 }
+
+genrule {
+    name: "libbt_common_bridge_header",
+    tools: ["cxxbridge"],
+    cmd: "$(location cxxbridge) $(in) --header > $(out)",
+    srcs: ["src/init_flags.rs"],
+    out: ["src/init_flags.rs.h"],
+}
+
+genrule {
+    name: "libbt_common_bridge_code",
+    tools: ["cxxbridge"],
+    cmd: "$(location cxxbridge) $(in) >> $(out)",
+    srcs: ["src/init_flags.rs"],
+    out: ["init_flags.cc"],
+}
+
+
diff --git a/gd/rust/common/src/init_flags.rs b/gd/rust/common/src/init_flags.rs
new file mode 100644 (file)
index 0000000..72d8e87
--- /dev/null
@@ -0,0 +1,16 @@
+use log::error;
+
+#[cxx::bridge(namespace = bluetooth::common)]
+mod ffi {
+    extern "Rust" {
+        fn init_flags_load(flags: Vec<String>);
+    }
+}
+
+fn init_flags_load(flags: Vec<String>) {
+    crate::init_logging();
+
+    for flag in flags {
+        error!("hello from rust: {}", flag);
+    }
+}
index 97ac682..1f38f72 100644 (file)
@@ -10,6 +10,8 @@ mod ready;
 #[macro_use]
 mod asserts;
 
+mod init_flags;
+
 /// Inits logging for Android
 #[cfg(target_os = "android")]
 pub fn init_logging() {
index f1ca7fd..7673b8b 100644 (file)
@@ -111,6 +111,9 @@ cc_library_shared {
         "libg722codec",
         "libudrv-uipc",
         "libbluetooth_gd", // Gabeldorsche
+        "libbluetooth_rust_interop",
+        "libbt_common_ffi",
+        "libcxxbridge05",
     ],
     whole_static_libs: [
         "libbt-bta",