Skip to content

Commit b84deb1

Browse files
committed
Add Vss thin client protobuf generation & build/CI setup
1 parent 143d762 commit b84deb1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

vss-accessor/tests/generate_protos.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
extern crate prost_build;
2+
3+
use std::fs;
4+
use std::fs::File;
5+
use std::path::Path;
6+
7+
// Use this test-case to generate rust-proto objects from proto file.
8+
// 1. Enable test case by commenting/removing `#[ignore]`
9+
// 2. Run command :
10+
// ```
11+
// cargo build && OUT_DIR=../target/tmp/ cargo test generate_protos -- --exact
12+
// ```
13+
#[test]
14+
#[ignore]
15+
fn generate_protos() {
16+
download_file(
17+
"https://raw.githubusercontent.com/lightningdevkit/vss-server/ff4b5fc6a079ed8719eb8be7ec35ca1d01c1cc55/app/src/main/proto/vss.proto",
18+
"src/proto/vss.proto",
19+
).unwrap();
20+
21+
prost_build::compile_protos(&["src/proto/vss.proto"], &["src/"]).unwrap();
22+
fs::copy(concat!(env!("OUT_DIR"), "/org.vss.rs"), "src/generated-src/org.vss.rs").unwrap();
23+
}
24+
25+
fn download_file(url: &str, save_to: &str) -> Result<(), Box<dyn std::error::Error>> {
26+
let mut response = reqwest::blocking::get(url)?;
27+
fs::create_dir_all(Path::new(save_to).parent().unwrap())?;
28+
let mut out_file = File::create(save_to)?;
29+
response.copy_to(&mut out_file)?;
30+
Ok(())
31+
}

0 commit comments

Comments
 (0)