File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments