forked from openobserve/openobserve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
137 lines (128 loc) · 5.45 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2023 Zinc Labs Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::{io::Result, process::Command};
use chrono::{DateTime, SecondsFormat, Utc};
fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=proto");
tonic_build::configure()
.type_attribute("FileList", "#[derive(Eq)]")
.type_attribute("FileList", "#[derive(serde::Serialize)]")
.type_attribute("FileKey", "#[derive(Eq)]")
.type_attribute("FileKey", "#[derive(serde::Serialize)]")
.type_attribute("FileDescriptor", "#[derive(Eq)]")
.type_attribute("FileDescriptor", "#[derive(serde::Serialize)]")
.type_attribute("FileMeta", "#[derive(Eq)]")
.type_attribute("FileMeta", "#[derive(serde::Serialize)]")
.type_attribute("Job", "#[derive(Eq)]")
.type_attribute("Job", "#[derive(serde::Serialize)]")
.type_attribute("Partition", "#[derive(Eq)]")
.type_attribute("SearchQuery", "#[derive(Eq)]")
.type_attribute("SearchRequest", "#[derive(Eq)]")
.type_attribute("SearchResponse", "#[derive(Eq)]")
.type_attribute("SearchResponse", "#[derive(serde::Serialize)]")
.type_attribute("SearchAggRequest", "#[derive(Eq)]")
.type_attribute("SearchAggRequest", "#[derive(serde::Serialize)]")
.type_attribute("SearchAggResponse", "#[derive(Eq)]")
.type_attribute("SearchAggResponse", "#[derive(serde::Serialize)]")
.type_attribute("Series", "#[derive(serde::Serialize)]")
.type_attribute("Label", "#[derive(serde::Serialize)]")
.type_attribute("Sample", "#[derive(serde::Serialize)]")
.type_attribute("MetricsQueryStmt", "#[derive(serde::Serialize)]")
.type_attribute("MetricsQueryRequest", "#[derive(serde::Serialize)]")
.type_attribute("MetricsQueryResponse", "#[derive(serde::Serialize)]")
.type_attribute("ScanStats", "#[derive(Eq)]")
.type_attribute("ScanStats", "#[derive(serde::Serialize)]")
.compile(
&[
"proto/cluster/common.proto",
"proto/cluster/event.proto",
"proto/cluster/filelist.proto",
"proto/cluster/metrics.proto",
"proto/cluster/search.proto",
"proto/cluster/usage.proto",
],
&["proto"],
)
.unwrap();
let mut config = prost_build::Config::new();
config
.type_attribute(
"MetricMetadata",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute(
"MetricType",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute("Sample", "#[derive(serde::Deserialize,serde::Serialize)]")
.type_attribute("Exemplar", "#[derive(serde::Deserialize,serde::Serialize)]")
.type_attribute(
"Histogram",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute(
"BucketSpan",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute(
"TimeSeries",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute("Label", "#[derive(serde::Deserialize,serde::Serialize)]")
.type_attribute("Labels", "#[derive(serde::Deserialize,serde::Serialize)]")
.type_attribute(
"LabelMatcher",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute(
"ReadHints",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute("Chunk", "#[derive(serde::Deserialize,serde::Serialize)]")
.type_attribute(
"ChunkedSeries",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute(
"zero_count",
"#[derive(serde::Deserialize,serde::Serialize)]",
)
.type_attribute("count", "#[derive(serde::Deserialize,serde::Serialize)]");
config.compile_protos(
&[
"proto/prometheus/remote.proto",
"proto/prometheus/types.proto",
],
&["proto"],
)?;
// build information
let output = Command::new("git")
.args(["describe", "--tags", "--abbrev=0"])
.output()
.unwrap();
let git_tag = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_VERSION={git_tag}");
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_commit = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_COMMIT_HASH={git_commit}");
let now: DateTime<Utc> = Utc::now();
let build_date = now.to_rfc3339_opts(SecondsFormat::Secs, true);
println!("cargo:rustc-env=GIT_BUILD_DATE={build_date}");
Ok(())
}