Loading system/gd/rust/common/Android.bp +158 −19 Original line number Diff line number Diff line Loading @@ -7,12 +7,10 @@ package { default_applicable_licenses: ["system_bt_license"], } rust_library { name : "libbt_common", defaults: ["gd_rust_defaults"], crate_name: "bt_common", srcs: ["src/lib.rs"], edition: "2018", defaults: ["libbt_common_defaults"], rustlibs: [ "libtokio", "libnix", Loading @@ -37,9 +35,131 @@ rust_library { ], }, }, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "Tiramisu", } rust_defaults { name: "libbt_common_defaults", defaults: ["gd_rust_defaults"], crate_name: "bt_common", srcs: ["src/lib.rs"], rustlibs: [ "libtokio", "libnix", "liblazy_static", "liblog_rust", "libcxx", "libgrpcio", "libbt_packets", "libfutures", "libnum_traits", "libnix", "liblog_rust", "libbt_facade_helpers", "libenv_logger", ], proc_macros: [ "libpaste", ], whole_static_libs: [ "libbt_keystore_cc", ], } rust_ffi_static { name: "libbt_common_ffi", defaults: ["libbt_common_defaults"], target: { android: { rustlibs: [ "librustutils", "libandroid_logger", ] }, }, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_static { name: "libbt_common_bridge", defaults: ["gd_ffi_defaults"], generated_headers: [ "libbt_common_bridge_header", "cxx-bridge-header", ], generated_sources: [ "libbt_common_bridge_code", ], export_generated_headers: [ "libbt_common_bridge_header", "cxx-bridge-header", ], include_dirs: [ "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/gd/rust/common", ], header_libs: ["libbt_keystore_cc_headers"], export_header_lib_headers: ["libbt_keystore_cc_headers"], cflags: [ "-Wno-unused-const-variable", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], shared_libs: [ "libchrome", ], min_sdk_version: "30", } cc_library_static { name: "libbt_keystore_cc", defaults: ["gd_ffi_defaults"], header_libs: ["libbt_keystore_cc_headers"], srcs: ["keystore/fake_bt_keystore.cc"], generated_headers: ["libbt_common_bridge_header", "cxx-bridge-header"], generated_sources: ["libbt_common_bridge_code"], shared_libs: [ "libchrome", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_headers { name: "libbt_keystore_cc_headers", local_include_dirs: ["keystore"], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_static { name: "libbluetooth_common_rust_interop", defaults: ["gd_ffi_defaults"], whole_static_libs: [ "libbt_common_bridge", "libbt_common_ffi", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", Loading @@ -47,8 +167,25 @@ rust_library { min_sdk_version: "30", } genrule { name: "libbt_common_bridge_header", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) --header > $(out)", srcs: ["src/bridge.rs"], out: ["src/bridge.rs.h"], } genrule { name: "libbt_common_bridge_code", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) >> $(out)", srcs: ["src/bridge.rs"], out: ["bridge.cc"], } rust_test_host { name: "libbt_common_inline_tests", defaults: ["gd_rust_defaults"], srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, Loading @@ -57,9 +194,11 @@ rust_test_host { "libnix", "liblazy_static", "liblog_rust", "libfutures", "libenv_logger", "libcxx", "libgrpcio", "libbt_common", "libcxx", ], proc_macros: [ "libpaste", Loading system/gd/rust/common/Cargo.toml +5 −1 Original line number Diff line number Diff line Loading @@ -19,13 +19,17 @@ version = "0.0.1" edition = "2018" [dependencies] cxx = "*" cxx = { version = "=1.0.42", features = ["c++17"] } env_logger = "*" grpcio = "*" lazy_static = "*" log = "*" nix = "*" tokio = { version = "*", features = ['bytes', 'macros', 'net', 'rt-multi-thread', 'time'] } futures = "*" [build-dependencies] cxx-build = "1.0" # Proc Macro dependency paste = "*" Loading system/gd/rust/common/keystore/fake_bt_keystore.cc 0 → 100644 +22 −0 Original line number Diff line number Diff line //#include "string" #include "keystore/fake_bt_keystore.h" #include <algorithm> #include <functional> #include <memory> namespace bluetooth { namespace fake_bluetooth_keystore { class BluetoothKeystoreInterface::impl { friend BluetoothKeystoreInterface; }; BluetoothKeystoreInterface::BluetoothKeystoreInterface() : impl(new class BluetoothKeystoreInterface::impl) {} std::unique_ptr<BluetoothKeystoreInterface> new_bt_keystore_interface() { return std::make_unique<BluetoothKeystoreInterface>(); } } // namespace fake_bluetooth_keystore } // namespace bluetooth system/gd/rust/common/keystore/fake_bt_keystore.h 0 → 100644 +23 −0 Original line number Diff line number Diff line #pragma once #include <memory> #include "rust/cxx.h" namespace bluetooth { namespace fake_bluetooth_keystore { class BluetoothKeystoreInterface { public: BluetoothKeystoreInterface(); private: class impl; std::shared_ptr<impl> impl; }; std::unique_ptr<BluetoothKeystoreInterface> new_bt_keystore_interface(); } // namespace fake_bluetooth_keystore } // namespace bluetooth #include "src/bridge.rs.h" No newline at end of file system/gd/rust/common/src/asserts.rs +3 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ macro_rules! assert_near { ($thing:expr, $expected:expr, $error:expr) => { match (&$thing, &$expected, &$error) { (thing_val, expected_val, error_val) => { if thing_val < &(expected_val - error_val) || thing_val > &(expected_val + error_val) { if thing_val < &(expected_val - error_val) || thing_val > &(expected_val + error_val) { panic!( "assertion failed: {:?} is not within {:?} of {:?}", &*thing_val, &*error_val, &*expected_val Loading Loading
system/gd/rust/common/Android.bp +158 −19 Original line number Diff line number Diff line Loading @@ -7,12 +7,10 @@ package { default_applicable_licenses: ["system_bt_license"], } rust_library { name : "libbt_common", defaults: ["gd_rust_defaults"], crate_name: "bt_common", srcs: ["src/lib.rs"], edition: "2018", defaults: ["libbt_common_defaults"], rustlibs: [ "libtokio", "libnix", Loading @@ -37,9 +35,131 @@ rust_library { ], }, }, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "Tiramisu", } rust_defaults { name: "libbt_common_defaults", defaults: ["gd_rust_defaults"], crate_name: "bt_common", srcs: ["src/lib.rs"], rustlibs: [ "libtokio", "libnix", "liblazy_static", "liblog_rust", "libcxx", "libgrpcio", "libbt_packets", "libfutures", "libnum_traits", "libnix", "liblog_rust", "libbt_facade_helpers", "libenv_logger", ], proc_macros: [ "libpaste", ], whole_static_libs: [ "libbt_keystore_cc", ], } rust_ffi_static { name: "libbt_common_ffi", defaults: ["libbt_common_defaults"], target: { android: { rustlibs: [ "librustutils", "libandroid_logger", ] }, }, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_static { name: "libbt_common_bridge", defaults: ["gd_ffi_defaults"], generated_headers: [ "libbt_common_bridge_header", "cxx-bridge-header", ], generated_sources: [ "libbt_common_bridge_code", ], export_generated_headers: [ "libbt_common_bridge_header", "cxx-bridge-header", ], include_dirs: [ "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/gd/rust/common", ], header_libs: ["libbt_keystore_cc_headers"], export_header_lib_headers: ["libbt_keystore_cc_headers"], cflags: [ "-Wno-unused-const-variable", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], shared_libs: [ "libchrome", ], min_sdk_version: "30", } cc_library_static { name: "libbt_keystore_cc", defaults: ["gd_ffi_defaults"], header_libs: ["libbt_keystore_cc_headers"], srcs: ["keystore/fake_bt_keystore.cc"], generated_headers: ["libbt_common_bridge_header", "cxx-bridge-header"], generated_sources: ["libbt_common_bridge_code"], shared_libs: [ "libchrome", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_headers { name: "libbt_keystore_cc_headers", local_include_dirs: ["keystore"], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", ], min_sdk_version: "30", } cc_library_static { name: "libbluetooth_common_rust_interop", defaults: ["gd_ffi_defaults"], whole_static_libs: [ "libbt_common_bridge", "libbt_common_ffi", ], host_supported: true, apex_available: [ "//apex_available:platform", "com.android.bluetooth", Loading @@ -47,8 +167,25 @@ rust_library { min_sdk_version: "30", } genrule { name: "libbt_common_bridge_header", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) --header > $(out)", srcs: ["src/bridge.rs"], out: ["src/bridge.rs.h"], } genrule { name: "libbt_common_bridge_code", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) >> $(out)", srcs: ["src/bridge.rs"], out: ["bridge.cc"], } rust_test_host { name: "libbt_common_inline_tests", defaults: ["gd_rust_defaults"], srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, Loading @@ -57,9 +194,11 @@ rust_test_host { "libnix", "liblazy_static", "liblog_rust", "libfutures", "libenv_logger", "libcxx", "libgrpcio", "libbt_common", "libcxx", ], proc_macros: [ "libpaste", Loading
system/gd/rust/common/Cargo.toml +5 −1 Original line number Diff line number Diff line Loading @@ -19,13 +19,17 @@ version = "0.0.1" edition = "2018" [dependencies] cxx = "*" cxx = { version = "=1.0.42", features = ["c++17"] } env_logger = "*" grpcio = "*" lazy_static = "*" log = "*" nix = "*" tokio = { version = "*", features = ['bytes', 'macros', 'net', 'rt-multi-thread', 'time'] } futures = "*" [build-dependencies] cxx-build = "1.0" # Proc Macro dependency paste = "*" Loading
system/gd/rust/common/keystore/fake_bt_keystore.cc 0 → 100644 +22 −0 Original line number Diff line number Diff line //#include "string" #include "keystore/fake_bt_keystore.h" #include <algorithm> #include <functional> #include <memory> namespace bluetooth { namespace fake_bluetooth_keystore { class BluetoothKeystoreInterface::impl { friend BluetoothKeystoreInterface; }; BluetoothKeystoreInterface::BluetoothKeystoreInterface() : impl(new class BluetoothKeystoreInterface::impl) {} std::unique_ptr<BluetoothKeystoreInterface> new_bt_keystore_interface() { return std::make_unique<BluetoothKeystoreInterface>(); } } // namespace fake_bluetooth_keystore } // namespace bluetooth
system/gd/rust/common/keystore/fake_bt_keystore.h 0 → 100644 +23 −0 Original line number Diff line number Diff line #pragma once #include <memory> #include "rust/cxx.h" namespace bluetooth { namespace fake_bluetooth_keystore { class BluetoothKeystoreInterface { public: BluetoothKeystoreInterface(); private: class impl; std::shared_ptr<impl> impl; }; std::unique_ptr<BluetoothKeystoreInterface> new_bt_keystore_interface(); } // namespace fake_bluetooth_keystore } // namespace bluetooth #include "src/bridge.rs.h" No newline at end of file
system/gd/rust/common/src/asserts.rs +3 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ macro_rules! assert_near { ($thing:expr, $expected:expr, $error:expr) => { match (&$thing, &$expected, &$error) { (thing_val, expected_val, error_val) => { if thing_val < &(expected_val - error_val) || thing_val > &(expected_val + error_val) { if thing_val < &(expected_val - error_val) || thing_val > &(expected_val + error_val) { panic!( "assertion failed: {:?} is not within {:?} of {:?}", &*thing_val, &*error_val, &*expected_val Loading