-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.rs
33 lines (29 loc) · 1.01 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[cfg(genproto)]
extern crate prost_build;
#[cfg(genproto)]
use std::{env, fs, fs::File, path::Path};
/// To generate updated proto objects:
/// 1. Place `vss.proto` file in `src/proto/`
/// 2. run `RUSTFLAGS="--cfg genproto" cargo build`
fn main() {
#[cfg(genproto)]
generate_protos();
}
#[cfg(genproto)]
fn generate_protos() {
download_file(
"https://raw.githubusercontent.com/lightningdevkit/vss-server/7f492fcac0c561b212f49ca40f7d16075822440f/app/src/main/proto/vss.proto",
"src/proto/vss.proto",
).unwrap();
prost_build::compile_protos(&["src/proto/vss.proto"], &["src/"]).unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("vss.rs");
fs::copy(from_path, "src/types.rs").unwrap();
}
#[cfg(genproto)]
fn download_file(url: &str, save_to: &str) -> Result<(), Box<dyn std::error::Error>> {
let mut response = reqwest::blocking::get(url)?;
fs::create_dir_all(Path::new(save_to).parent().unwrap())?;
let mut out_file = File::create(save_to)?;
response.copy_to(&mut out_file)?;
Ok(())
}