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
#![doc(html_root_url = "https://docs.rs/build-plan/0.1.1")]
#![warn(missing_debug_implementations)]
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate semver;
use serde::de::{self, Error};
use std::collections::BTreeMap;
use std::path::PathBuf;
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Kind {
Host,
Target,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum LibKind {
Lib,
Rlib,
Dylib,
ProcMacro,
Other(String),
}
impl LibKind {
pub fn from_str(string: &str) -> LibKind {
match string {
"lib" => LibKind::Lib,
"rlib" => LibKind::Rlib,
"dylib" => LibKind::Dylib,
"proc-macro" => LibKind::ProcMacro,
s => LibKind::Other(s.to_string()),
}
}
pub fn crate_type(&self) -> &str {
match *self {
LibKind::Lib => "lib",
LibKind::Rlib => "rlib",
LibKind::Dylib => "dylib",
LibKind::ProcMacro => "proc-macro",
LibKind::Other(ref s) => s,
}
}
pub fn linkable(&self) -> bool {
match *self {
LibKind::Lib | LibKind::Rlib | LibKind::Dylib | LibKind::ProcMacro => true,
LibKind::Other(..) => false,
}
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum TargetKind {
Lib(Vec<LibKind>),
Bin,
Test,
Bench,
ExampleLib(Vec<LibKind>),
ExampleBin,
CustomBuild,
}
impl<'de> de::Deserialize<'de> for TargetKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: de::Deserializer<'de> {
use self::TargetKind::*;
let raw = Vec::<&str>::deserialize(deserializer)?;
Ok(match *raw {
[] => return Err(D::Error::invalid_length(0, &"at least one target kind")),
["bin"] => Bin,
["example"] => ExampleBin,
["test"] => Test,
["custom-build"] => CustomBuild,
["bench"] => Bench,
ref lib_kinds => Lib(lib_kinds.iter().cloned().map(LibKind::from_str).collect()),
})
}
}
#[derive(Debug, Deserialize)]
pub struct Invocation {
pub package_name: String,
pub package_version: semver::Version,
pub target_kind: TargetKind,
pub kind: Kind,
pub deps: Vec<usize>,
pub outputs: Vec<PathBuf>,
pub links: BTreeMap<PathBuf, PathBuf>,
pub program: String,
pub args: Vec<String>,
pub env: BTreeMap<String, String>,
pub cwd: Option<PathBuf>,
}
#[derive(Debug, Deserialize)]
pub struct BuildPlan {
pub invocations: Vec<Invocation>,
pub inputs: Vec<PathBuf>,
}
impl BuildPlan {
pub fn from_cargo_output<S: AsRef<[u8]>>(output: S) -> serde_json::Result<Self> {
serde_json::from_slice(output.as_ref())
}
}