-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
40 lines (37 loc) · 1.05 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
34
35
36
37
38
39
40
use std::path::Path;
use walkdir::{DirEntry, WalkDir};
fn is_proto(entry: Option<DirEntry>) -> Option<DirEntry> {
match entry {
Some(e) => match e.path().to_str() {
Some(name) => match name.ends_with(".proto") {
true => Some(e),
false => None,
},
None => None,
},
None => None,
}
}
// fn display(vec: &Vec<&Path>) -> () {
// for element in vec {
// println!("{}", element.display());
// }
// }
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut vec: Vec<DirEntry> = Vec::new();
for entry in WalkDir::new("src")
.into_iter()
.filter_map(|e| (is_proto(e.ok())))
{
//println!("{}", entry.path().display());
vec.push(entry);
}
//println!("{}", vec.len());
let protos: Vec<&Path> = vec.iter().map(|d| d.path()).collect();
//display(&protos);
tonic_build::configure()
.build_server(false)
.out_dir("src")
.compile(&protos[..], &["src"])?;
return Ok(());
}