-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.rs
More file actions
35 lines (31 loc) · 1.03 KB
/
build.rs
File metadata and controls
35 lines (31 loc) · 1.03 KB
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
34
35
#[cfg(genproto)]
extern crate prost_build;
#[cfg(genproto)]
use std::io::Write;
#[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/022ee5e92debb60516438af0a369966495bfe595/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 response = bitreq::get(url).send()?;
fs::create_dir_all(Path::new(save_to).parent().unwrap())?;
let mut out_file = File::create(save_to)?;
out_file.write_all(&response.into_bytes())?;
Ok(())
}