diff options
-rwxr-xr-x | build.py | 9 | ||||
-rw-r--r-- | system/gd/rust/packets/build.rs | 21 | ||||
-rw-r--r-- | tools/rootcanal/Cargo.toml | 20 | ||||
-rw-r--r-- | tools/rootcanal/lmp/Cargo.toml | 36 | ||||
-rw-r--r-- | tools/rootcanal/lmp/build.rs | 68 |
5 files changed, 152 insertions, 2 deletions
@@ -65,6 +65,7 @@ VALID_TARGETS = [ 'docs', # Build Rust docs 'main', # Build the main C++ codebase 'prepare', # Prepare the output directory (gn gen + rust setup) + 'rootcanal', # Build Rust targets for RootCanal 'rust', # Build only the rust components + copy artifacts to output dir 'test', # Run the unit tests 'tools', # Build the host tools (i.e. packetgen) @@ -433,6 +434,11 @@ class HostBuild(): """ self._rust_build() + def _target_rootcanal(self): + """ Build rust artifacts for RootCanal in an already prepared environment. + """ + self.run_command('rust', ['cargo', 'build'], cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env) + def _target_main(self): """ Build the main GN artifacts in an already prepared environment. """ @@ -447,6 +453,7 @@ class HostBuild(): rust_test_cmd = rust_test_cmd + [self.args.test_name] self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt'), env=self.env) + self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env) # Host tests second based on host test list for t in HOST_TESTS: @@ -542,6 +549,8 @@ class HostBuild(): self._target_prepare() elif self.target == 'tools': self._target_tools() + elif self.target == 'rootcanal': + self._target_rootcanal() elif self.target == 'rust': self._target_rust() elif self.target == 'docs': diff --git a/system/gd/rust/packets/build.rs b/system/gd/rust/packets/build.rs index 0e58cbf71c..be5d804b78 100644 --- a/system/gd/rust/packets/build.rs +++ b/system/gd/rust/packets/build.rs @@ -18,7 +18,21 @@ use std::path::{Path, PathBuf}; use std::process::Command; fn main() { - generate_packets(); + let packets_prebuilt = match env::var("HCI_PACKETS_PREBUILT") { + Ok(dir) => PathBuf::from(dir), + Err(_) => PathBuf::from("hci_packets.rs"), + }; + if Path::new(packets_prebuilt.as_os_str()).exists() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let outputted = out_dir.join("../../hci/hci_packets.rs"); + std::fs::copy( + packets_prebuilt.as_os_str().to_str().unwrap(), + out_dir.join(outputted.file_name().unwrap()).as_os_str().to_str().unwrap(), + ) + .unwrap(); + } else { + generate_packets(); + } } fn generate_packets() { @@ -40,7 +54,10 @@ fn generate_packets() { }; if !Path::new(packetgen.as_os_str()).exists() { - panic!("Unable to locate bluetooth packet generator:{:?}", packetgen.as_os_str().to_str().unwrap()); + panic!( + "Unable to locate bluetooth packet generator:{:?}", + packetgen.as_os_str().to_str().unwrap() + ); } for i in 0..input_files.len() { diff --git a/tools/rootcanal/Cargo.toml b/tools/rootcanal/Cargo.toml new file mode 100644 index 0000000000..d734d1402b --- /dev/null +++ b/tools/rootcanal/Cargo.toml @@ -0,0 +1,20 @@ +# +# 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. + +[workspace] + +members = [ + "lmp", +] diff --git a/tools/rootcanal/lmp/Cargo.toml b/tools/rootcanal/lmp/Cargo.toml new file mode 100644 index 0000000000..22f398685e --- /dev/null +++ b/tools/rootcanal/lmp/Cargo.toml @@ -0,0 +1,36 @@ +# +# Copyright 2021 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 = "lmp" +version = "0.1.0" +edition = "2018" +build="build.rs" + +[dependencies] +bytes = "1.0.1" +num-bigint = "0.4.3" +num-derive = "0.3.3" +num-integer = "0.1.45" +num-traits = "0.2.14" +paste = "1.0.4" +pin-utils = "0.1.0" +rand = "0.8.3" +thiserror = "1.0.23" +bt_packets = { path = "../../../system/gd/rust/packets/" } + +[lib] +path="src/lib.rs" +crate-type = ["staticlib"] diff --git a/tools/rootcanal/lmp/build.rs b/tools/rootcanal/lmp/build.rs new file mode 100644 index 0000000000..131103037b --- /dev/null +++ b/tools/rootcanal/lmp/build.rs @@ -0,0 +1,68 @@ +// +// 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. + +use std::env; +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn main() { + let packets_prebuilt = match env::var("LMP_PACKETS_PREBUILT") { + Ok(dir) => PathBuf::from(dir), + Err(_) => PathBuf::from("lmp_packets.rs"), + }; + if Path::new(packets_prebuilt.as_os_str()).exists() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let outputted = out_dir.join("lmp_packets.rs"); + std::fs::copy( + packets_prebuilt.as_os_str().to_str().unwrap(), + out_dir.join(outputted.file_name().unwrap()).as_os_str().to_str().unwrap(), + ) + .unwrap(); + } else { + generate_packets(); + } +} + +fn generate_packets() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + + // Find the packetgen tool. Expecting it at CARGO_HOME/bin + let packetgen = match env::var("CARGO_HOME") { + Ok(dir) => PathBuf::from(dir).join("bin").join("bluetooth_packetgen"), + Err(_) => PathBuf::from("bluetooth_packetgen"), + }; + + if !Path::new(packetgen.as_os_str()).exists() { + panic!( + "Unable to locate bluetooth packet generator:{:?}", + packetgen.as_os_str().to_str().unwrap() + ); + } + + let output = Command::new(packetgen.as_os_str().to_str().unwrap()) + .arg("--out=".to_owned() + out_dir.as_os_str().to_str().unwrap()) + .arg("--include=.") + .arg("--rust") + .arg("lmp_packets.pdl") + .output() + .unwrap(); + + println!( + "Status: {}, stdout: {}, stderr: {}", + output.status, + String::from_utf8_lossy(output.stdout.as_slice()), + String::from_utf8_lossy(output.stderr.as_slice()) + ); +} |