forked from confidential-containers/guest-components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
61 lines (52 loc) · 1.82 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright The ocicrypt Authors.
// SPDX-License-Identifier: Apache-2.0
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "gen-proto-grpc")]
tonic_build::configure()
.build_server(true)
.out_dir("src/utils/grpc/")
.compile(&["src/utils/proto/keyprovider.proto"], &["src/utils"])?;
#[cfg(feature = "gen-proto-ttrpc")]
{
use std::fs::File;
use std::io::{Read, Write};
fn replace_text_in_file(
file_name: &str,
from: &str,
to: &str,
) -> Result<(), std::io::Error> {
let mut src = File::open(file_name)?;
let mut contents = String::new();
src.read_to_string(&mut contents).unwrap();
drop(src);
let new_contents = contents.replace(from, to);
let mut dst = File::create(file_name)?;
dst.write_all(new_contents.as_bytes())?;
Ok(())
}
ttrpc_codegen::Codegen::new()
.out_dir("src/utils/ttrpc")
.inputs(["src/utils/proto/keyprovider.proto"])
.include("src/utils")
.rust_protobuf()
.customize(ttrpc_codegen::Customize {
async_all: false,
..Default::default()
})
.rust_protobuf_customize(ttrpc_codegen::ProtobufCustomize::default().gen_mod_rs(false))
.run()
.expect("ttrpc gen async code failed.");
// Fix clippy warnings of code generated from ttrpc_codegen
replace_text_in_file(
"src/utils/ttrpc/keyprovider_ttrpc.rs",
"client: client",
"client",
)?;
replace_text_in_file(
"src/utils/ttrpc/keyprovider_ttrpc.rs",
"#![allow(box_pointers)]\n",
"",
)?;
}
Ok(())
}