Skip to content

Commit 62e1322

Browse files
committed
Add Base protobuf generation for types.
1 parent 6d35834 commit 62e1322

File tree

4 files changed

+429
-0
lines changed

4 files changed

+429
-0
lines changed

rust/api/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
prost = { version = "0.11.6", default-features = false, features = ["std", "prost-derive"] }
8+
bytes = "1.4.0"
9+
10+
[target.'cfg(genproto)'.build-dependencies]
11+
prost-build = { version = "0.11.3" }
12+
reqwest = { version = "0.11.13", default-features = false, features = ["rustls-tls", "blocking"] }

rust/api/build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#[cfg(genproto)]
2+
extern crate prost_build;
3+
#[cfg(genproto)]
4+
use std::{env, fs, fs::File, path::Path};
5+
6+
/// To generate updated proto objects, run `RUSTFLAGS="--cfg genproto" cargo build`
7+
fn main() {
8+
#[cfg(genproto)]
9+
generate_protos();
10+
}
11+
12+
#[cfg(genproto)]
13+
fn generate_protos() {
14+
download_file(
15+
"https://raw.githubusercontent.com/lightningdevkit/vss-server/7f492fcac0c561b212f49ca40f7d16075822440f/app/src/main/proto/vss.proto",
16+
"src/proto/vss.proto",
17+
).unwrap();
18+
19+
prost_build::Config::new()
20+
.bytes(&["."])
21+
.compile_protos(&["src/proto/vss.proto"], &["src/"])
22+
.expect("protobuf compilation failed");
23+
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
24+
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("vss.rs");
25+
fs::copy(from_path, "src/types.rs").unwrap();
26+
}
27+
28+
#[cfg(genproto)]
29+
fn download_file(url: &str, save_to: &str) -> Result<(), Box<dyn std::error::Error>> {
30+
let mut response = reqwest::blocking::get(url)?;
31+
fs::create_dir_all(Path::new(save_to).parent().unwrap())?;
32+
let mut out_file = File::create(save_to)?;
33+
response.copy_to(&mut out_file)?;
34+
Ok(())
35+
}

rust/api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod types;

0 commit comments

Comments
 (0)