lib.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. use cargo_metadata::CompilerMessage;
  2. use serde::{Deserialize, Serialize};
  3. use std::path::PathBuf;
  4. pub use cargo_metadata;
  5. /// The structured output for the CLI
  6. ///
  7. /// This is designed such that third party tools can reliably consume the output of the CLI when
  8. /// outputting json.
  9. ///
  10. /// Not every log outputted will be parsable, but all structured logs should be.
  11. ///
  12. /// This means the debug format of this log needs to be parsable json, not the default debug format.
  13. ///
  14. /// We guarantee that the last line of the command represents the success of the command, such that
  15. /// tools can simply parse the last line of the output.
  16. ///
  17. /// There might be intermediate lines that are parseable as structured logs (which you can put here)
  18. /// but they are not guaranteed to be, such that we can provide better error messages for the user.
  19. #[allow(clippy::large_enum_variant)]
  20. #[non_exhaustive]
  21. #[derive(Serialize, Deserialize, Clone)]
  22. pub enum StructuredOutput {
  23. BuildFinished { path: PathBuf },
  24. BuildUpdate { stage: BuildStage },
  25. CargoOutput { message: CompilerMessage },
  26. BundleOutput { bundles: Vec<PathBuf> },
  27. HtmlTranslate { html: String },
  28. Success,
  29. Error { message: String },
  30. }
  31. impl std::fmt::Debug for StructuredOutput {
  32. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  33. f.write_str(&serde_json::to_string(self).map_err(|_e| std::fmt::Error)?)
  34. }
  35. }
  36. /// The current stage of the ongoing build
  37. ///
  38. /// This is a perma-unstable interface that is subject to change at any time.
  39. #[non_exhaustive]
  40. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
  41. pub enum BuildStage {
  42. Initializing,
  43. Starting {
  44. crate_count: usize,
  45. is_server: bool,
  46. },
  47. InstallingTooling,
  48. Compiling {
  49. is_server: bool,
  50. current: usize,
  51. total: usize,
  52. krate: String,
  53. },
  54. RunningBindgen,
  55. SplittingBundle,
  56. OptimizingWasm,
  57. PrerenderingRoutes,
  58. CopyingAssets {
  59. current: usize,
  60. total: usize,
  61. path: PathBuf,
  62. },
  63. Bundling,
  64. RunningGradle,
  65. Success,
  66. Failed,
  67. Aborted,
  68. Restarting,
  69. CompressingAssets,
  70. }