From ec42a139a41752ffd61d7cee529cfb8ac06457c4 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Sat, 3 Feb 2024 16:57:47 -0500 Subject: [PATCH] first commit --- .gitignore | 2 ++ Cargo.toml | 14 ++++++++++++++ build.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 3 +++ 4 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..537fa83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/protobufs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..8deb780 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "meshtastic-protobuf" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bytes = "1.5.0" +prost = "0.12.3" + +[build-dependencies] +git2 = "0.18.1" +prost-build = "0.12.3" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..6ce73d3 --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +extern crate git2; +extern crate prost_build; + +use git2::Repository; +use prost_build::compile_protos; +use std::path::Path; + +fn update_repo(path: &Path) -> Result<(), git2::Error> { + let repo = Repository::open(path)?; + let mut remote = repo.find_remote("origin")?; + let refspecs: [&str; 0] = []; + remote.fetch(&refspecs, None, None) +} + +fn main() { + let repo = "https://github.com/meshtastic/protobufs.git"; + let path = Path::new("protobufs"); + + if path.exists() { + if let Err(e) = update_repo(path) { + eprintln!("Error could not update meshtastic protobuf repo"); + eprintln!("{e}"); + std::process::exit(1); + } + } else { + if let Err(e) = Repository::clone(repo, path) { + eprintln!("Error could not clone meshtastic protobuf repo"); + eprintln!("{e}"); + std::process::exit(1); + } + } + + let protos = &["protobufs/meshtastic/mesh.proto"]; + let includes = &["protobufs"]; + + if let Err(e) = compile_protos(protos, includes) { + eprintln!("Error could not compile protobufs"); + eprintln!("{e}"); + std::process::exit(1); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d939319 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod meshtastic { + include!(concat!(env!("OUT_DIR"), "/meshtastic.rs")); +}