first commit

This commit is contained in:
Lucas Schumacher 2024-02-03 16:57:47 -05:00
commit ec42a139a4
4 changed files with 60 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/protobufs

14
Cargo.toml Normal file
View File

@ -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"

41
build.rs Normal file
View File

@ -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);
}
}

3
src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod meshtastic {
include!(concat!(env!("OUT_DIR"), "/meshtastic.rs"));
}