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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use super::{Diagnostic, PackageId, Target};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::io::{self, BufRead, Lines, Read};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ArtifactProfile {
pub opt_level: String,
pub debuginfo: Option<u32>,
pub debug_assertions: bool,
pub overflow_checks: bool,
pub test: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Artifact {
pub package_id: PackageId,
pub target: Target,
pub profile: ArtifactProfile,
pub features: Vec<String>,
pub filenames: Vec<PathBuf>,
pub executable: Option<PathBuf>,
pub fresh: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct CompilerMessage {
pub package_id: PackageId,
pub target: Target,
pub message: Diagnostic,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct BuildScript {
pub package_id: PackageId,
pub linked_libs: Vec<PathBuf>,
pub linked_paths: Vec<PathBuf>,
pub cfgs: Vec<String>,
pub env: Vec<(String, String)>,
#[serde(default)]
pub out_dir: PathBuf,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct BuildFinished {
pub success: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(tag = "reason", rename_all = "kebab-case")]
pub enum Message {
CompilerArtifact(Artifact),
CompilerMessage(CompilerMessage),
BuildScriptExecuted(BuildScript),
BuildFinished(BuildFinished),
#[serde(skip)]
TextLine(String),
#[doc(hidden)]
#[serde(other)]
Unknown,
}
impl Message {
pub fn parse_stream<R: BufRead>(input: R) -> MessageIter<R> {
MessageIter {
lines: input.lines(),
}
}
}
impl fmt::Display for CompilerMessage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.message)
}
}
pub struct MessageIter<R> {
lines: Lines<R>,
}
impl<R: BufRead> Iterator for MessageIter<R> {
type Item = io::Result<Message>;
fn next(&mut self) -> Option<Self::Item> {
let line = self.lines.next()?;
let message = line.map(|it| {
let mut deserializer = serde_json::Deserializer::from_str(&it);
deserializer.disable_recursion_limit();
Message::deserialize(&mut deserializer).unwrap_or(Message::TextLine(it))
});
Some(message)
}
}
type MessageIterator<R> =
serde_json::StreamDeserializer<'static, serde_json::de::IoRead<R>, Message>;
#[deprecated(note = "Use Message::parse_stream instead")]
pub fn parse_messages<R: Read>(input: R) -> MessageIterator<R> {
serde_json::Deserializer::from_reader(input).into_iter::<Message>()
}