dioxus_dx_wire_format/
lib.rs

1use cargo_metadata::{diagnostic::Diagnostic, CompilerMessage};
2use manganis_core::BundledAsset;
3use serde::{Deserialize, Serialize};
4use std::{borrow::Cow, collections::HashSet, path::PathBuf};
5use subsecond_types::JumpTable;
6
7pub use cargo_metadata;
8
9/// The structured output for the CLI
10///
11/// This is designed such that third party tools can reliably consume the output of the CLI when
12/// outputting json.
13///
14/// Not every log outputted will be parsable, but all structured logs should be.
15///
16/// This means the debug format of this log needs to be parsable json, not the default debug format.
17///
18/// We guarantee that the last line of the command represents the success of the command, such that
19/// tools can simply parse the last line of the output.
20///
21/// There might be intermediate lines that are parseable as structured logs (which you can put here)
22/// but they are not guaranteed to be, such that we can provide better error messages for the user.
23#[allow(clippy::large_enum_variant)]
24#[non_exhaustive]
25#[derive(Serialize, Deserialize, Clone, Debug)]
26pub enum StructuredOutput {
27    BuildsFinished {
28        client: StructuredBuildArtifacts,
29        server: Option<StructuredBuildArtifacts>,
30    },
31    PrintCargoArgs {
32        args: Vec<String>,
33        env: Vec<(Cow<'static, str>, String)>,
34    },
35    BuildFinished {
36        artifacts: StructuredBuildArtifacts,
37    },
38    BuildUpdate {
39        stage: BuildStage,
40    },
41    Hotpatch {
42        jump_table: JumpTable,
43        artifacts: StructuredBuildArtifacts,
44    },
45    CargoOutput {
46        message: CompilerMessage,
47    },
48    RustcOutput {
49        message: Diagnostic,
50    },
51    BundleOutput {
52        bundles: Vec<PathBuf>,
53        client: StructuredBuildArtifacts,
54        server: Option<StructuredBuildArtifacts>,
55    },
56    HtmlTranslate {
57        html: String,
58    },
59    Success,
60    Error {
61        message: String,
62    },
63}
64
65impl std::fmt::Display for StructuredOutput {
66    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67        f.write_str(&serde_json::to_string(self).map_err(|_e| std::fmt::Error)?)
68    }
69}
70
71#[derive(Debug, Clone, Default, Serialize, Deserialize)]
72pub struct StructuredBuildArtifacts {
73    pub path: PathBuf,
74    pub exe: PathBuf,
75    pub rustc_args: Vec<String>,
76    pub rustc_envs: Vec<(String, String)>,
77    pub link_args: Vec<String>,
78    pub assets: HashSet<BundledAsset>, // the serialized asset manifest
79}
80
81/// The current stage of the ongoing build
82///
83/// This is a perma-unstable interface that is subject to change at any time.
84#[non_exhaustive]
85#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
86pub enum BuildStage {
87    Initializing,
88    Starting {
89        crate_count: usize,
90        patch: bool,
91    },
92    InstallingTooling,
93    Compiling {
94        current: usize,
95        total: usize,
96        krate: String,
97    },
98    RunningBindgen,
99    SplittingBundle,
100    OptimizingWasm,
101    Linking,
102    Hotpatching,
103    ExtractingAssets,
104    CopyingAssets {
105        current: usize,
106        total: usize,
107        path: PathBuf,
108    },
109    Bundling,
110    RunningGradle,
111    CodeSigning,
112    Success,
113    Failed,
114    Aborted,
115    Restarting,
116    CompressingAssets,
117    Prerendering,
118}