From 4f93b187deabb1fa3fa24eecef8b13fc2a4498ff Mon Sep 17 00:00:00 2001 From: wszdexdrf Date: Sun, 18 Jun 2023 09:56:46 +0530 Subject: [PATCH] feat: add rust build script for trezor-client --- rust/trezor-client/Cargo.toml | 3 +++ rust/trezor-client/build.rs | 26 ++++++++++++++++++++++ rust/trezor-client/src/protos/mod.rs | 33 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 rust/trezor-client/build.rs create mode 100644 rust/trezor-client/src/protos/mod.rs diff --git a/rust/trezor-client/Cargo.toml b/rust/trezor-client/Cargo.toml index 7d39f3f5e8..2851505283 100644 --- a/rust/trezor-client/Cargo.toml +++ b/rust/trezor-client/Cargo.toml @@ -34,6 +34,9 @@ unicode-normalization = { version = "0.1.22", optional = true } # ethereum primitive-types = { version = "0.12", default-features = false, optional = true } +[build-dependencies] +protobuf-codegen = "3.2.0" + [dev-dependencies] tracing-subscriber = "0.3" serial_test = "2.0.0" diff --git a/rust/trezor-client/build.rs b/rust/trezor-client/build.rs new file mode 100644 index 0000000000..ebebe92563 --- /dev/null +++ b/rust/trezor-client/build.rs @@ -0,0 +1,26 @@ +use std::{fs, path::PathBuf}; + +fn main() { + let proto_path = "../../common/protob"; + let protos: Vec = fs::read_dir(proto_path) + .unwrap() + .filter_map(|entry| { + let entry = entry.unwrap(); + let path = entry.path(); + if path.is_file() && path.extension().map_or(false, |ext| ext == "proto") { + Some(path) + } else { + None + } + }) + .collect(); + let out_path = std::env::var("OUT_DIR").unwrap(); + let out_dir = PathBuf::from(out_path).join("protos"); + fs::create_dir_all(&out_dir).expect("Failed to create output directory"); + protobuf_codegen::Codegen::new() + .protoc() + .includes(&[proto_path]) + .inputs(protos) + .out_dir(out_dir) + .run_from_script(); +} diff --git a/rust/trezor-client/src/protos/mod.rs b/rust/trezor-client/src/protos/mod.rs new file mode 100644 index 0000000000..0f500b1904 --- /dev/null +++ b/rust/trezor-client/src/protos/mod.rs @@ -0,0 +1,33 @@ +include!(concat!(env!("OUT_DIR"), "/protos/mod.rs")); + +#[allow(ambiguous_glob_reexports)] +pub use messages::*; +pub use messages_bootloader::*; +pub use messages_common::*; +pub use messages_crypto::*; +pub use messages_debug::*; +pub use messages_management::*; + +macro_rules! features { + ($($feature:literal => $item:ident)+) => {$( + #[cfg(feature = $feature)] + #[allow(ambiguous_glob_reexports)] + pub use $item::*; + )+}; +} + +features! { + "bitcoin" => messages_bitcoin + "ethereum" => messages_ethereum + "ethereum" => messages_ethereum_eip712 + "ethereum" => messages_ethereum_definitions + "binance" => messages_binance + "cardano" => messages_cardano + "eos" => messages_eos + "monero" => messages_monero + "nem" => messages_nem + "ripple" => messages_ripple + "stellar" => messages_stellar + "tezos" => messages_tezos + "webauthn" => messages_webauthn +}