diff options
author | Chih-Yu Huang <akahuang@google.com> | 2022-03-15 13:50:18 +0900 |
---|---|---|
committer | Chih-Yu Huang <akahuang@google.com> | 2022-03-16 10:10:55 +0900 |
commit | e374838eaf454b5c1c96c3b9f0a0b5b2a99b025a (patch) | |
tree | f42cc80b41f2ee63898c99cc736ddf9ff535838e /src | |
parent | ce273bbea6112268fd90fdfc900d42929e9dd923 (diff) | |
download | uwb-e374838eaf454b5c1c96c3b9f0a0b5b2a99b025a.tar.gz |
Split uwb_uci_packets to separated crate
This CL follows the Android's best practice [1] to create a
separated crate for the generated rust code, and supports Cargo build
system for the crate.
[1]: https://source.android.com/setup/build/rust/building-rust-modules/source-code-generators/source-code-gen-intro
Bug: 224686845
Test: mmm external/uwb -j32
Test: "cargo test" at external/uwb/src/rust/uwb_uci_packets/ folder
Test: atest libuwb_uci_packet_tests
Change-Id: If1c86588aef6736b195e6fc302d7ce11ff8d0dd8
Diffstat (limited to 'src')
-rwxr-xr-x | src/Android.bp | 32 | ||||
-rw-r--r-- | src/rust/uwb_uci_packets/Cargo.toml | 11 | ||||
-rw-r--r-- | src/rust/uwb_uci_packets/build.rs | 39 | ||||
-rw-r--r-- | src/rust/uwb_uci_packets/src/lib.rs | 22 | ||||
-rw-r--r-- | src/rust/uwb_uci_packets/uci_packets.pdl (renamed from src/rust/uci_packets.pdl) | 0 |
5 files changed, 89 insertions, 15 deletions
diff --git a/src/Android.bp b/src/Android.bp index 2e60932..618e7bc 100755 --- a/src/Android.bp +++ b/src/Android.bp @@ -64,11 +64,23 @@ rust_test { auto_gen_config: true, } -rust_test { - name: "libuwb_uci_packet_tests", +rust_defaults { + name: "libuwb_uci_packet_defaults", srcs: [ + "rust/uwb_uci_packets/src/lib.rs", ":UwbGeneratedPackets_rust", ], + proc_macros: ["libnum_derive"], + rustlibs:[ + "libbytes", + "libnum_traits", + "libthiserror", + ], +} + +rust_test { + name: "libuwb_uci_packet_tests", + defaults: ["libuwb_uci_packet_defaults"], test_suites: [ "general-tests", "mts-uwb" @@ -87,27 +99,17 @@ rust_test { }, }, auto_gen_config: true, - proc_macros: ["libnum_derive"], rustlibs:[ "android.hardware.uwb-V1-rust", - "libbytes", "liblog_rust", - "libnum_traits", - "libthiserror", "libuwb_uci_rust", ], } rust_library { name: "libuwb_uci_packets", + defaults: ["libuwb_uci_packet_defaults"], crate_name: "uwb_uci_packets", - srcs: [":UwbGeneratedPackets_rust"], - proc_macros: ["libnum_derive"], - rustlibs: [ - "libbytes", - "libnum_traits", - "libthiserror", - ], apex_available: [ "com.android.uwb", ], @@ -121,9 +123,9 @@ genrule { ], cmd: "$(location bluetooth_packetgen) --include=external/uwb/src --out=$(genDir) $(in) --rust", srcs: [ - "rust/uci_packets.pdl", + "rust/uwb_uci_packets/uci_packets.pdl", ], out: [ - "rust/uci_packets.rs", + "rust/uwb_uci_packets/uci_packets.rs", ], } diff --git a/src/rust/uwb_uci_packets/Cargo.toml b/src/rust/uwb_uci_packets/Cargo.toml new file mode 100644 index 0000000..4f88316 --- /dev/null +++ b/src/rust/uwb_uci_packets/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "uwb_uci_packets" +version = "0.0.1" +edition = "2018" + +[dependencies] +bytes = "*" +num-derive = "*" +num-traits = "*" +thiserror = "*" +walkdir = "*" diff --git a/src/rust/uwb_uci_packets/build.rs b/src/rust/uwb_uci_packets/build.rs new file mode 100644 index 0000000..bc30c36 --- /dev/null +++ b/src/rust/uwb_uci_packets/build.rs @@ -0,0 +1,39 @@ +// 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. + +use std::env; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-changed=uci_packets.pdl"); + + // Generate the rust code by bluetooth_packetgen. + // The binary should be compiled by `m bluetooth_packetgen -j32` before calling cargo. + let out_dir = env::var_os("OUT_DIR").unwrap(); + let output = Command::new("env") + .arg("bluetooth_packetgen") + .arg("--out=".to_owned() + out_dir.as_os_str().to_str().unwrap()) + .arg("--include=.") + .arg("--rust") + .arg("uci_packets.pdl") + .output() + .unwrap(); + + eprintln!( + "Status: {}, stdout: {}, stderr: {}", + output.status, + String::from_utf8_lossy(output.stdout.as_slice()), + String::from_utf8_lossy(output.stderr.as_slice()) + ); +} diff --git a/src/rust/uwb_uci_packets/src/lib.rs b/src/rust/uwb_uci_packets/src/lib.rs new file mode 100644 index 0000000..224d594 --- /dev/null +++ b/src/rust/uwb_uci_packets/src/lib.rs @@ -0,0 +1,22 @@ +// 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. + +#![allow(clippy::all)] +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(unused)] +#![allow(missing_docs)] + +include!(concat!(env!("OUT_DIR"), "/uci_packets.rs")); diff --git a/src/rust/uci_packets.pdl b/src/rust/uwb_uci_packets/uci_packets.pdl index 3f0e95f..3f0e95f 100644 --- a/src/rust/uci_packets.pdl +++ b/src/rust/uwb_uci_packets/uci_packets.pdl |