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
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use target_lexicon::Triple;
use super::{metadata::Target, Result};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct UnitGraph {
/// Version of the JSON output structure.
/// If any backwards incompatible changes are made, this value will be increased.
pub version: usize,
/// Array of all build units.
pub units: Vec<Unit>,
/// Array of indices in the "units" array that are the "roots" of the dependency graph.
pub roots: Vec<usize>,
}
#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Unit {
/// An opaque string which indicates the package.
pub pkg_id: String,
/// The Cargo target
pub target: Target,
/// The profile settings for this unit.
/// These values may not match the profile defined in the manifest.
/// Units can use modified profile settings. For example, the "panic"
/// setting can be overridden for tests to force it to "unwind".
pub profile: Profile,
/// Which platform this target is being built for.
/// A value of `None` indicates it is for the host.
#[serde_as(as = "Option<DisplayFromStr>")]
pub platform: Option<Triple>,
/// The "mode" for this unit.
pub mode: Mode,
/// Array of features enabled on this unit.
pub features: Vec<String>,
/// Whether or not this is a standard-library unit,
/// part of the unstable build-std feature
#[serde(default)]
pub is_std: bool,
/// Array of dependencies of this unit.
pub dependencies: Vec<Dependency>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Profile {
/// The profile name these settings are derived from.
pub name: String, // TODO: could be an enum.
/// The optimization level.
pub opt_level: String, // TODO: could be an enum.
/// The LTO setting.
pub lto: String, // TODO: Almost definitely could be an enum
/// The codegen units as an integer.
/// `None` if it should use the compiler's default.
pub codegen_units: Option<u32>,
/// The debug information level as an integer.
/// `None` if it should use the compiler's default (0).
pub debuginfo: Option<u32>,
/// Whether or not debug-assertions are enabled.
pub debug_assertions: bool,
/// Whether or not overflow-checks are enabled.
pub overflow_checks: bool,
/// Whether or not incremental is enabled.
pub rpath: bool,
/// Whether or not incremental is enabled.
pub incremental: bool,
/// The panic strategy.
pub panic: PanicStrategy,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum PanicStrategy {
#[serde(rename = "unwind")]
Unwind,
#[serde(rename = "abort")]
Abort,
}
/// The "mode" of a unit.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Mode {
/// Build using `rustc` as a test.
#[serde(rename = "test")]
Test,
/// Build using `rustc`.
#[serde(rename = "build")]
Build,
/// Build using `rustc` in "check" mode.
#[serde(rename = "check")]
Check,
/// Build using `rustdoc`.
#[serde(rename = "doc")]
Doc,
/// Test using `rustdoc`.
#[serde(rename = "doctest")]
Doctest,
/// Represents the execution of a build script.
#[serde(rename = "run-custom-build")]
RunCustomBuild,
}
/// Array of dependencies of a unit.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Dependency {
/// Index in the "units" array for the dependency.
pub index: usize,
/// The name that this dependency will be referred as.
pub extern_crate_name: String,
/// Whether or not this dependency is "public",
/// part of the unstable public-dependency feature.
/// If `None` the public-dependency feature is not enabled.
pub public: Option<bool>,
/// Whether or not this dependency is injected into the prelude,
/// currently used by the build-std feature.
#[serde(default)]
pub noprelude: bool,
}
impl UnitGraph {
pub fn parse<A: AsRef<[u8]>>(bytes: A) -> Result<Self> {
Ok(serde_json::from_slice(bytes.as_ref())?)
}
}