-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
54 lines (47 loc) · 1.33 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
use std::{
env, fs,
path::{Path, PathBuf},
};
fn main() -> anyhow::Result<()> {
vergen::EmitBuilder::builder().git_sha(true).emit()?;
compile_protos(
["googleapis", "proto"],
[
"google/rpc/status.proto",
"google/rpc/error_details.proto",
"lanquetta/errors.proto",
],
"errors.bin",
);
#[cfg(windows)]
winres::WindowsResource::new()
.set_icon_with_id(
"img/logo.ico",
&(windows::Win32::UI::WindowsAndMessaging::IDI_APPLICATION.0 as u32).to_string(),
)
.compile()?;
println!("cargo:rerun-if-changed=img/logo.ico");
Ok(())
}
fn compile_protos(
includes: impl IntoIterator<Item = impl AsRef<Path>>,
files: impl IntoIterator<Item = impl AsRef<Path>>,
destination: impl AsRef<Path>,
) {
let mut compiler = protox::Compiler::new(includes).unwrap();
compiler
.include_source_info(false)
.include_imports(true)
.open_files(files)
.unwrap();
for file in compiler.files() {
if let Some(path) = file.path() {
println!("cargo:rerun-if-changed={}", path.display());
}
}
fs::write(
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join(destination),
compiler.encode_file_descriptor_set(),
)
.unwrap();
}