build.rs 1.36 KB
Newer Older
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
1
2
3
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
OlivierDehaene's avatar
OlivierDehaene committed
4
    println!("cargo:rerun-if-changed=../../proto/**");
5

OlivierDehaene's avatar
OlivierDehaene committed
6
    fs::create_dir_all("src/v2/pb").unwrap_or(());
7
8
9
    let mut config = prost_build::Config::new();
    config.protoc_arg("--experimental_allow_proto3_optional");

Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
10
11
12
    tonic_build::configure()
        .build_client(true)
        .build_server(false)
OlivierDehaene's avatar
OlivierDehaene committed
13
        .out_dir("src/v2/pb")
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
14
        .include_file("mod.rs")
15
        .compile_with_config(config, &["../../proto/generate.proto"], &["../../proto"])
16
17
18
19
20
        .map_err(|e| match e.kind(){
            std::io::ErrorKind::NotFound => {panic!("`protoc` not found, install libprotoc")},
            std::io::ErrorKind::Other => {panic!("`protoc` version unsupported, upgrade protoc: https://github.com/protocolbuffers/protobuf/releases")},
            e => {e}
        }).unwrap_or_else(|e| panic!("protobuf compilation failed: {e}"));
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
21

OlivierDehaene's avatar
OlivierDehaene committed
22
23
24
25
26
27
28
29
30
31
32
33
    fs::create_dir_all("src/v3/pb").unwrap_or(());
    let mut config = prost_build::Config::new();
    config.protoc_arg("--experimental_allow_proto3_optional");

    tonic_build::configure()
        .build_client(true)
        .build_server(false)
        .out_dir("src/v3/pb")
        .include_file("mod.rs")
        .compile_with_config(config, &["../../proto/v3/generate.proto"], &["../../proto"])
        .unwrap_or_else(|e| panic!("protobuf compilation failed: {e}"));

Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
34
35
    Ok(())
}