-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
95 lines (92 loc) · 4.7 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
use prost_build::Config;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = Config::new();
// The best magic to tie Protobuf Structs -> Diesel ORM Rust Structs
// NewWorker (Worker with limited fields)
config
.type_attribute(
"NewWorker",
"#[derive(Queryable, Insertable, AsChangeset, Associations, Serialize, Deserialize)]",
)
.type_attribute("NewWorker", "#[table_name = \"workers\"]")
// Worker
.type_attribute("Worker", "#[derive(Queryable, Identifiable, Associations)]")
.type_attribute("Worker", "#[table_name = \"workers\"]")
// NewTask (Task with limited fields)
.type_attribute("NewTask", "#[derive(Queryable, Insertable, AsChangeset, Associations)]")
.type_attribute("NewTask", "#[table_name = \"tasks\"]")
// PatchTask (Task with limited fields)
.type_attribute("PatchTask", "#[derive(Queryable, AsChangeset, Associations)]")
.type_attribute("PatchTask", "#[table_name = \"tasks\"]")
// Task (Removed as prost_types::Timestamp cannto be changed)
.type_attribute("Task", "#[derive(Queryable, Identifiable, Associations)]")
.type_attribute("Task", "#[table_name = \"tasks\"]")
// NewCorpus (Corpus with limited fields)
.type_attribute(
"NewCorpus",
"#[derive(Queryable, Insertable, AsChangeset, Associations)]",
)
.type_attribute("NewCorpus", "#[table_name = \"corpora\"]")
// Corpus
.type_attribute("Corpus", "#[derive(Queryable, Identifiable, Associations)]")
.type_attribute("Corpus", "#[table_name = \"corpora\"]")
// NewCrash (Crash with limited fields)
.type_attribute(
"NewCrash",
"#[derive(Queryable, Insertable, AsChangeset, Associations)]",
)
.type_attribute("NewCrash", "#[table_name = \"crashes\"]")
// PatchCrash (Crash with limited fields)
.type_attribute(
"PatchCrash",
"#[derive(Queryable, Insertable, AsChangeset, Associations)]",
)
.type_attribute("PatchCrash", "#[table_name = \"crashes\"]")
.type_attribute("PatchCrash", "#[changeset_options(treat_none_as_null=\"true\")]")
// Crash
.type_attribute("Crash", "#[derive(Queryable, Identifiable, Associations)]")
.type_attribute("Crash", "#[table_name = \"crashes\"]")
// WorkerTask (Worker Task)
.type_attribute("WorkerTask", "#[derive(Queryable, Identifiable, Associations)]")
.type_attribute("WorkerTask", "#[table_name = \"worker_tasks\"]")
.type_attribute("WorkerTask", "#[belongs_to(Task)]")
.type_attribute("WorkerTask", "#[belongs_to(Worker)]")
// PatchWorkerTask (Patch Worker Task to update state)
.type_attribute("PatchWorkerTask", "#[derive(Queryable, AsChangeset, Associations)]")
.type_attribute("PatchWorkerTask", "#[table_name = \"worker_tasks\"]")
// WorkerTask (Worker Task)
.type_attribute("WorkerTaskFull", "#[derive(Queryable, Associations)]")
// .type_attribute("WorkerTaskFull", "#[table_name = \"worker_tasks\"]")
// NewFuzzStat (FuzzStat without time field)
.type_attribute(
"NewFuzzStat",
"#[derive(Queryable, Insertable, AsChangeset, Associations)]",
)
.type_attribute("NewFuzzStat", "#[table_name = \"fuzz_stats\"]")
.type_attribute("NewFuzzStat", "#[belongs_to(WorkerTask)]")
// NewSysStat (SysStat without time field)
.type_attribute(
"NewSysStat",
"#[derive(Queryable, Insertable, AsChangeset, Associations)]",
)
.type_attribute("NewSysStat", "#[table_name = \"sys_stats\"]")
.type_attribute("NewSysStat", "#[belongs_to(Worker)]")
// NewTraceEvent
.type_attribute(
"NewTraceEvent",
"#[derive(Queryable, Insertable, Associations)]",
)
.type_attribute("NewTraceEvent", "#[table_name = \"trace_events\"]")
.type_attribute("NewTraceEvent", "#[belongs_to(Worker)]")
// All fields of this name, prost converts them to prost_types::Timestamp, which diesel
// doesn't support natively so we customize deserialization behaviour for one field
//
// https://docs.rs/diesel/1.4.4/diesel/deserialize/trait.Queryable.html
//
.field_attribute("created_at", "#[diesel(deserialize_as = \"std::time::SystemTime\")]")
// Disable this for now
.field_attribute("updated_at", "#[diesel(deserialize_as = \"std::time::SystemTime\")]");
// .compile_well_known_types();
tonic_build::configure().compile_with_config(config, &["proto/xpc.proto"], &["proto"])?;
Ok(())
}