]> git.proxmox.com Git - rustc.git/blob - vendor/cargo_metadata/src/messages.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / vendor / cargo_metadata / src / messages.rs
1 use super::{Diagnostic, PackageId, Target};
2 use serde_json;
3 use std::fmt;
4 use std::io::Read;
5 use std::path::PathBuf;
6
7 /// Profile settings used to determine which compiler flags to use for a
8 /// target.
9 #[derive(Debug, Clone, Serialize, Deserialize)]
10 pub struct ArtifactProfile {
11 /// Optimization level. Possible values are 0-3, s or z.
12 pub opt_level: String,
13 /// The amount of debug info. 0 for none, 1 for limited, 2 for full
14 pub debuginfo: Option<u32>,
15 /// State of the `cfg(debug_assertions)` directive, enabling macros like
16 /// `debug_assert!`
17 pub debug_assertions: bool,
18 /// State of the overflow checks.
19 pub overflow_checks: bool,
20 /// Whether this profile is a test
21 pub test: bool,
22 #[doc(hidden)]
23 #[serde(skip)]
24 __do_not_match_exhaustively: (),
25 }
26
27 /// A compiler-generated file.
28 #[derive(Debug, Clone, Serialize, Deserialize)]
29 pub struct Artifact {
30 /// The package this artifact belongs to
31 pub package_id: PackageId,
32 /// The target this artifact was compiled for
33 pub target: Target,
34 /// The profile this artifact was compiled with
35 pub profile: ArtifactProfile,
36 /// The enabled features for this artifact
37 pub features: Vec<String>,
38 /// The full paths to the generated artifacts
39 /// (e.g. binary file and separate debug info)
40 pub filenames: Vec<PathBuf>,
41 /// Path to the executable file
42 pub executable: Option<PathBuf>,
43 /// If true, then the files were already generated
44 pub fresh: bool,
45 #[doc(hidden)]
46 #[serde(skip)]
47 __do_not_match_exhaustively: (),
48 }
49
50 /// Message left by the compiler
51 // TODO: Better name. This one comes from machine_message.rs
52 #[derive(Debug, Clone, Serialize, Deserialize)]
53 pub struct CompilerMessage {
54 /// The package this message belongs to
55 pub package_id: PackageId,
56 /// The target this message is aimed at
57 pub target: Target,
58 /// The message the compiler sent.
59 pub message: Diagnostic,
60 #[doc(hidden)]
61 #[serde(skip)]
62 __do_not_match_exhaustively: (),
63 }
64
65 /// Output of a build script execution.
66 #[derive(Debug, Clone, Serialize, Deserialize)]
67 pub struct BuildScript {
68 /// The package this build script execution belongs to
69 pub package_id: PackageId,
70 /// The libs to link
71 pub linked_libs: Vec<PathBuf>,
72 /// The paths to search when resolving libs
73 pub linked_paths: Vec<PathBuf>,
74 /// Various `--cfg` flags to pass to the compiler
75 pub cfgs: Vec<PathBuf>,
76 /// The environment variables to add to the compilation
77 pub env: Vec<(String, String)>,
78 /// The `OUT_DIR` environment variable where this script places its output
79 ///
80 /// Added in Rust 1.41.
81 #[serde(default)]
82 pub out_dir: PathBuf,
83 #[doc(hidden)]
84 #[serde(skip)]
85 __do_not_match_exhaustively: (),
86 }
87
88 /// A cargo message
89 #[derive(Debug, Clone, Serialize, Deserialize)]
90 #[serde(tag = "reason", rename_all = "kebab-case")]
91 pub enum Message {
92 /// The compiler generated an artifact
93 CompilerArtifact(Artifact),
94 /// The compiler wants to display a message
95 CompilerMessage(CompilerMessage),
96 /// A build script successfully executed.
97 BuildScriptExecuted(BuildScript),
98 #[doc(hidden)]
99 #[serde(other)]
100 Unknown,
101 }
102
103 impl fmt::Display for CompilerMessage {
104 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105 write!(f, "{}", self.message)
106 }
107 }
108
109 /// An iterator of Message.
110 type MessageIterator<R> =
111 serde_json::StreamDeserializer<'static, serde_json::de::IoRead<R>, Message>;
112
113 /// Creates an iterator of Message from a Read outputting a stream of JSON
114 /// messages. For usage information, look at the top-level documentation.
115 pub fn parse_messages<R: Read>(input: R) -> MessageIterator<R> {
116 serde_json::Deserializer::from_reader(input).into_iter::<Message>()
117 }