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
use serde::ser;
use serde_json::{self, value::RawValue};
use core::{PackageId, Target};
pub trait Message: ser::Serialize {
fn reason(&self) -> &str;
}
pub fn emit<T: Message>(t: &T) {
let json = serde_json::to_string(t).unwrap();
assert!(json.starts_with("{\""));
let reason = json!(t.reason());
println!("{{\"reason\":{},{}", reason, &json[1..]);
}
#[derive(Serialize)]
pub struct FromCompiler<'a> {
pub package_id: &'a PackageId,
pub target: &'a Target,
pub message: Box<RawValue>,
}
impl<'a> Message for FromCompiler<'a> {
fn reason(&self) -> &str {
"compiler-message"
}
}
#[derive(Serialize)]
pub struct Artifact<'a> {
pub package_id: &'a PackageId,
pub target: &'a Target,
pub profile: ArtifactProfile,
pub features: Vec<String>,
pub filenames: Vec<String>,
pub fresh: bool,
}
impl<'a> Message for Artifact<'a> {
fn reason(&self) -> &str {
"compiler-artifact"
}
}
#[derive(Serialize)]
pub struct ArtifactProfile {
pub opt_level: &'static str,
pub debuginfo: Option<u32>,
pub debug_assertions: bool,
pub overflow_checks: bool,
pub test: bool,
}
#[derive(Serialize)]
pub struct BuildScript<'a> {
pub package_id: &'a PackageId,
pub linked_libs: &'a [String],
pub linked_paths: &'a [String],
pub cfgs: &'a [String],
pub env: &'a [(String, String)],
}
impl<'a> Message for BuildScript<'a> {
fn reason(&self) -> &str {
"build-script-executed"
}
}