about summary refs log tree commit diff
path: root/ops/yandex-cloud-rs/build.rs
blob: e9a96ef9df91912c2678d1f6a473d95046dc8db7 (plain) (blame)
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
41
42
43
use std::path::PathBuf;
use walkdir::{DirEntry, WalkDir};

fn proto_files(proto_dir: &str) -> Vec<PathBuf> {
    let mut out = vec![];

    fn is_proto(entry: &DirEntry) -> bool {
        entry.file_type().is_file()
            && entry
                .path()
                .extension()
                .map(|e| e.to_string_lossy() == "proto")
                .unwrap_or(false)
    }

    for entry in WalkDir::new(format!("{}/yandex", proto_dir)).into_iter() {
        let entry = entry.expect("failed to list proto files");

        if is_proto(&entry) {
            out.push(entry.into_path())
        }
    }

    out
}

fn main() {
    if let Some(proto_dir) = option_env!("YANDEX_CLOUD_PROTOS") {
        tonic_build::configure()
            .build_client(true)
            .build_server(false)
            .out_dir("src/")
            .include_file("includes.rs")
            .compile(
                &proto_files(proto_dir),
                &[
                    format!("{}", proto_dir),
                    format!("{}/third_party/googleapis", proto_dir),
                ],
            )
            .expect("failed to generate gRPC clients for Yandex Cloud")
    }
}