-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
37 lines (32 loc) · 1.08 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
use std::{io::Write, path::Path};
extern crate tonic_build;
fn prepend_package_name_and_build(
path: impl AsRef<Path>,
package_name: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let mut source_file = std::fs::File::open(path)?;
let mut temp_file = tempfile::NamedTempFile::new()?;
std::io::copy(&mut source_file, &mut temp_file)?;
writeln!(temp_file)?;
writeln!(temp_file, "package {package_name};")?;
let target_path = temp_file.into_temp_path();
tonic_build::configure()
.disable_package_emission()
.compile_protos(
&[&target_path],
&[target_path.parent().expect("must succeed")],
)?;
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
prepend_package_name_and_build(
"hatchet/api-contracts/dispatcher/dispatcher.proto",
"dispatcher",
)?;
prepend_package_name_and_build("hatchet/api-contracts/events/events.proto", "events")?;
prepend_package_name_and_build(
"hatchet/api-contracts/workflows/workflows.proto",
"workflows",
)?;
Ok(())
}