summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Rahul Arya <aryarahul@google.com> 2023-01-31 23:31:35 +0000
committer Rahul Arya <aryarahul@google.com> 2023-01-31 23:31:35 +0000
commit3d401dae9535cf142cdebb0cc46cb17feed6eb30 (patch)
tree84aa38cc6760fc0f54f6f8d3acef86d4cf2e0aa5
parentcaa5be2f685b7d52c850986d1b7eb19a71e655d2 (diff)
[Private GATT] Initial boilerplate
Bug: 255880936 Test: compiles Change-Id: Ia835784365e6fa6cf8a4bd23c088b1fb2dbe0ed9
-rw-r--r--android/app/Android.bp2
-rw-r--r--system/gd/dumpsys/bundler/Android.bp1
-rw-r--r--system/gd/rust/common/Cargo.toml4
-rw-r--r--system/gd/rust/common/build.rs16
-rw-r--r--system/gd/rust/shim/Android.bp8
-rw-r--r--system/main/Android.bp3
-rw-r--r--system/rust/Android.bp84
-rw-r--r--system/rust/Cargo.toml38
-rw-r--r--system/rust/build.rs30
-rw-r--r--system/rust/src/lib.rs27
-rw-r--r--system/rust/src/packets.pdl1
-rw-r--r--system/rust/src/packets.rs9
12 files changed, 211 insertions, 12 deletions
diff --git a/android/app/Android.bp b/android/app/Android.bp
index 20cff726bd..97298b184a 100644
--- a/android/app/Android.bp
+++ b/android/app/Android.bp
@@ -90,7 +90,7 @@ cc_library {
include_dirs: [
"packages/modules/Bluetooth/system/types",
],
- whole_static_libs: [
+ static_libs: [
"libbte",
"libbt-bta-core",
"libbt-common",
diff --git a/system/gd/dumpsys/bundler/Android.bp b/system/gd/dumpsys/bundler/Android.bp
index 41f554991b..542c7c49fd 100644
--- a/system/gd/dumpsys/bundler/Android.bp
+++ b/system/gd/dumpsys/bundler/Android.bp
@@ -31,6 +31,7 @@ genrule {
visibility: [
"//packages/modules/Bluetooth/system/gd",
"//packages/modules/Bluetooth/system/main",
+ "//packages/modules/Bluetooth/system/rust",
],
tools: [
"flatc",
diff --git a/system/gd/rust/common/Cargo.toml b/system/gd/rust/common/Cargo.toml
index becc5d5c52..40f53a2a33 100644
--- a/system/gd/rust/common/Cargo.toml
+++ b/system/gd/rust/common/Cargo.toml
@@ -36,3 +36,7 @@ tokio = { version = "1.0", features = ['bytes', 'macros', 'net', 'rt-multi-threa
[lib]
crate-type = ["rlib"]
+
+[features]
+default = ["keystore"]
+keystore = []
diff --git a/system/gd/rust/common/build.rs b/system/gd/rust/common/build.rs
index 73a5adbd9d..fa0a8de7f4 100644
--- a/system/gd/rust/common/build.rs
+++ b/system/gd/rust/common/build.rs
@@ -1,12 +1,14 @@
fn main() {
- let target_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap();
-
// Link the keystore static lib and make sure to use -lc++
- println!("cargo:rustc-link-lib=static=bt_keystore_cc");
- println!("cargo:rustc-link-search=native={}", target_dir.clone().into_string().unwrap());
- println!("cargo:rustc-link-lib=c++");
+ #[cfg(feature = "keystore")]
+ {
+ let target_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap();
+ println!("cargo:rustc-link-lib=static=bt_keystore_cc");
+ println!("cargo:rustc-link-search=native={}", target_dir.clone().into_string().unwrap());
+ println!("cargo:rustc-link-lib=c++");
+ // Re-run if this file changed.
+ println!("cargo:rerun-if-changed={}", target_dir.into_string().unwrap());
+ }
- // Re-run if static libs or this file changed.
- println!("cargo:rerun-if-changed={}", target_dir.into_string().unwrap());
println!("cargo:rerun-if-changed=build.rs");
}
diff --git a/system/gd/rust/shim/Android.bp b/system/gd/rust/shim/Android.bp
index eaf1d20aa8..23fdeba7f6 100644
--- a/system/gd/rust/shim/Android.bp
+++ b/system/gd/rust/shim/Android.bp
@@ -50,6 +50,10 @@ rust_defaults {
static_libs: [
"libbt_callbacks_cxx",
],
+ apex_available: [
+ "com.android.btservices",
+ ],
+ min_sdk_version: "30",
}
rust_library_rlib {
@@ -60,10 +64,6 @@ rust_library_rlib {
rust_ffi_static {
name: "libbt_shim_ffi",
defaults: ["libbt_shim_defaults"],
- apex_available: [
- "com.android.btservices",
- ],
- min_sdk_version: "30",
}
cc_library_static {
diff --git a/system/main/Android.bp b/system/main/Android.bp
index 6a9d565fd9..45ad6a3d07 100644
--- a/system/main/Android.bp
+++ b/system/main/Android.bp
@@ -90,6 +90,9 @@ cc_library {
"system/security/keystore/include",
"hardware/interfaces/keymaster/4.0/support/include",
],
+ whole_static_libs: [
+ "libbluetooth_core_rs",
+ ],
logtags: ["../../EventLogTags.logtags"],
// Shared library link options.
// References to global symbols and functions should bind to the library
diff --git a/system/rust/Android.bp b/system/rust/Android.bp
new file mode 100644
index 0000000000..3e0f2cb8bb
--- /dev/null
+++ b/system/rust/Android.bp
@@ -0,0 +1,84 @@
+rust_defaults {
+ name: "libbluetooth_core_rs_defaults",
+ min_sdk_version: "Tiramisu",
+ dylib: {
+ enabled: false,
+ },
+ srcs: ["src/lib.rs", ":bluetooth_core_rust_packets"],
+ shared_libs: [
+ "libbase",
+ ],
+ static_libs: [
+ "libbluetooth-core",
+ "libbt_shim_bridge",
+ "libbt_shim_ffi",
+
+ "libchrome",
+ "libmodpb64",
+ "libevent",
+ ],
+ proc_macros: [
+ "libasync_trait",
+ "libpaste",
+ ],
+ rustlibs: [
+ "liblog_rust",
+ "libcxx",
+ "libtokio",
+ "libbt_common",
+
+ // needed to work around duplicate symbols
+ // caused by bug in Soong
+ "libbt_shim",
+ ],
+ features: [
+ // used to hide libbt_shim in Cargo builds, but
+ // expose it to Soong to work around linker bug
+ "via_android_bp",
+ ],
+ target: {
+ android: {
+ shared_libs: [
+ "android.hardware.bluetooth@1.0",
+ "android.hardware.bluetooth@1.1",
+ "android.system.suspend.control-V1-ndk",
+ "android.system.suspend-V1-ndk",
+ "libbinder_ndk",
+ "libcutils",
+ "libhidlbase",
+ "libutils",
+ "libstatslog_bt",
+ ],
+ },
+ },
+ apex_available: ["com.android.btservices"],
+}
+
+rust_ffi_static {
+ name: "libbluetooth_core_rs",
+ crate_name: "bluetooth_core",
+ defaults: ["libbluetooth_core_rs_defaults"],
+ target: {
+ android: {
+ rustlibs: [
+ "libandroid_logger",
+ ],
+ },
+ },
+ host_supported: true,
+}
+
+rust_test_host {
+ name: "libbluetooth_core_rs_test",
+ defaults: ["libbluetooth_core_rs_defaults"],
+ rustlibs: [
+ "libtokio_test",
+ ],
+}
+
+genrule {
+ name: "bluetooth_core_rust_packets",
+ defaults: ["pdl_rust_noalloc_generator_defaults"],
+ srcs: ["src/packets.pdl"],
+ out: ["_packets.rs"],
+}
diff --git a/system/rust/Cargo.toml b/system/rust/Cargo.toml
new file mode 100644
index 0000000000..972b230941
--- /dev/null
+++ b/system/rust/Cargo.toml
@@ -0,0 +1,38 @@
+#
+# Copyright 2022 Google, Inc.
+#
+# 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.
+
+[package]
+name = "bluetooth_core"
+version = "0.0.1"
+edition = "2021"
+
+[dependencies]
+bt_common = { path = "../gd/rust/common", default-features = false }
+
+# External dependencies
+# Note: source-of-truth is Android.bp, these are mirrored solely for IDE convenient
+log = "*"
+cxx = "*"
+android_logger = "*"
+jni = "*"
+paste = "*"
+async-trait = "*"
+tokio-test = "0.4.2"
+tokio = { version = "1.23.0", features = ["macros"] }
+
+[lib]
+crate-type = ["rlib"]
+
+[workspace]
diff --git a/system/rust/build.rs b/system/rust/build.rs
new file mode 100644
index 0000000000..f0e49e69df
--- /dev/null
+++ b/system/rust/build.rs
@@ -0,0 +1,30 @@
+use std::{
+ env,
+ fs::File,
+ path::Path,
+ process::{Command, Stdio},
+};
+
+fn main() {
+ let out_dir = env::var_os("OUT_DIR").unwrap();
+ let dest_path = Path::new(&out_dir).join("_packets.rs");
+ let dest_file = File::create(dest_path).unwrap();
+
+ let pdl = Command::new("pdl")
+ .args(&["--output-format", "rust_no_alloc", "src/packets.pdl"])
+ .stdout(Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ let mut rustfmt =
+ Command::new("rustfmt").stdin(pdl.stdout.unwrap()).stdout(dest_file).spawn().unwrap();
+
+ rustfmt.wait().unwrap();
+
+ if let Some(err) = rustfmt.stderr {
+ panic!("{:?}", err);
+ }
+
+ println!("cargo:rerun-if-changed=build.rs");
+ println!("cargo:rerun-if-changed=src/packets.pdl");
+}
diff --git a/system/rust/src/lib.rs b/system/rust/src/lib.rs
new file mode 100644
index 0000000000..7c2d647834
--- /dev/null
+++ b/system/rust/src/lib.rs
@@ -0,0 +1,27 @@
+// Copyright 2022, 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.
+
+//! The core event loop for Rust modules. Here Rust modules are started in
+//! dependency order.
+
+#![feature(mixed_integer_ops)]
+
+#[cfg(feature = "via_android_bp")]
+mod do_not_use {
+ // DO NOT USE
+ #[allow(unused)]
+ use bt_shim::*;
+}
+
+pub mod packets;
diff --git a/system/rust/src/packets.pdl b/system/rust/src/packets.pdl
new file mode 100644
index 0000000000..593e09d58d
--- /dev/null
+++ b/system/rust/src/packets.pdl
@@ -0,0 +1 @@
+little_endian_packets
diff --git a/system/rust/src/packets.rs b/system/rust/src/packets.rs
new file mode 100644
index 0000000000..db0fcf6b20
--- /dev/null
+++ b/system/rust/src/packets.rs
@@ -0,0 +1,9 @@
+// Casing inherited from PDL
+#![allow(non_snake_case)]
+#![allow(non_camel_case_types)]
+#![allow(warnings, missing_docs)]
+#![allow(clippy::all)]
+// this is now stable
+#![feature(mixed_integer_ops)]
+
+include!(concat!(env!("OUT_DIR"), "/_packets.rs"));