-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.rs
37 lines (27 loc) · 1.13 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
#[cfg(feature = "protobuf")]
use std::path::PathBuf;
#[cfg(feature = "protobuf")]
fn build_protos() -> Result<(), Box<dyn std::error::Error>> {
let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let proto_dir = cargo_dir.join("protos");
let mut builder = tonic_build::configure()
.type_attribute(".", "#[derive(serde::Deserialize, serde::Serialize)]");
for field in vec!["start", "end", "timestamp"] {
builder = builder.field_attribute(field, "#[serde(default, deserialize_with = \"crate::serde_helpers::deserialize_maybe_timestamp\", serialize_with = \"crate::serde_helpers::serialize_maybe_timestamp\", skip_serializing_if = \"Option::is_none\")]");
}
//compile suricata proto
let suricata_proto_path = proto_dir.join("suricata_eve.proto");
println!(
"cargo:rerun-if-changed={}",
suricata_proto_path
.to_str()
.expect("Failed to convert to string")
);
builder.compile(&[suricata_proto_path], &[proto_dir])?;
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "protobuf")]
build_protos()?;
Ok(())
}