From b6bde8006e08a0b0cb4461ae5fb6757c3c53424f Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Thu, 28 Oct 2021 13:50:25 +0100 Subject: [PATCH] expose raw bindings as a separate package --- .gitmodules | 2 +- Cargo.toml | 13 ++++++++----- mavsdk-bindings/Cargo.toml | 13 +++++++++++++ build.rs => mavsdk-bindings/build.rs | 0 proto => mavsdk-bindings/proto | 0 mavsdk-bindings/src/lib.rs | 12 ++++++++++++ src/info.rs | 2 +- src/mocap.rs | 2 +- src/telemetry.rs | 2 +- 9 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 mavsdk-bindings/Cargo.toml rename build.rs => mavsdk-bindings/build.rs (100%) rename proto => mavsdk-bindings/proto (100%) create mode 100644 mavsdk-bindings/src/lib.rs diff --git a/.gitmodules b/.gitmodules index dcd56f8..c5db566 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "MAVSDK-Proto"] - path = proto + path = mavsdk-bindings/proto url = https://github.com/mavlink/MAVSDK-Proto.git diff --git a/Cargo.toml b/Cargo.toml index b640b69..2430b2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,15 +4,18 @@ version = "0.1.0" authors = ["Ildar Sadykov "] edition = "2021" +[workspace] +members = [ + ".", + "mavsdk-bindings", +] + [dependencies] tonic = "0.6.0" -prost = "0.9.0" - thiserror = "1.0.30" futures-util = { version = "0.3.17", default-features = false } +mavsdk-bindings = { path = "./mavsdk-bindings" } +prost = "0.9.0" [dev-dependencies] tokio = { version = "1.12.0", features = ["rt-multi-thread", "macros", "time"] } - -[build-dependencies] -tonic-build = "0.6.0" diff --git a/mavsdk-bindings/Cargo.toml b/mavsdk-bindings/Cargo.toml new file mode 100644 index 0000000..6b1112b --- /dev/null +++ b/mavsdk-bindings/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "mavsdk-bindings" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tonic = "0.6.0" +prost = "0.9.0" + +[build-dependencies] +tonic-build = "0.6.0" diff --git a/build.rs b/mavsdk-bindings/build.rs similarity index 100% rename from build.rs rename to mavsdk-bindings/build.rs diff --git a/proto b/mavsdk-bindings/proto similarity index 100% rename from proto rename to mavsdk-bindings/proto diff --git a/mavsdk-bindings/src/lib.rs b/mavsdk-bindings/src/lib.rs new file mode 100644 index 0000000..959c00a --- /dev/null +++ b/mavsdk-bindings/src/lib.rs @@ -0,0 +1,12 @@ +macro_rules! include_plugin { + ($plugin: ident, $path: tt ) => { + #[allow(clippy::all, clippy::pedantic)] + pub mod $plugin { + tonic::include_proto!($path); + } + }; +} + +include_plugin!(info, "mavsdk.rpc.info"); +include_plugin!(mocap, "mavsdk.rpc.mocap"); +include_plugin!(telemetry, "mavsdk.rpc.telemetry"); diff --git a/src/info.rs b/src/info.rs index 6644b2c..d0d3d48 100644 --- a/src/info.rs +++ b/src/info.rs @@ -1,7 +1,7 @@ use crate::{FromRpcResponse, RequestError, RequestResult, TonicResult}; mod pb { - tonic::include_proto!("mavsdk.rpc.info"); + pub use mavsdk_bindings::info::*; } #[derive(PartialEq, Clone, Default, Debug)] diff --git a/src/mocap.rs b/src/mocap.rs index 2658ee3..143355f 100644 --- a/src/mocap.rs +++ b/src/mocap.rs @@ -1,7 +1,7 @@ use crate::{FromRpcResponse, RequestError, RequestResult, TonicResult}; mod pb { - tonic::include_proto!("mavsdk.rpc.mocap"); + pub use mavsdk_bindings::mocap::*; } /// Global position/attitude estimate from a vision source. diff --git a/src/telemetry.rs b/src/telemetry.rs index 3de1461..4e2c809 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -2,7 +2,7 @@ use crate::{RequestError, RequestResult}; use futures_util::stream::{Stream, StreamExt}; mod pb { - tonic::include_proto!("mavsdk.rpc.telemetry"); + pub use mavsdk_bindings::telemetry::*; } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]