use std::borrow;
use std::path;
pub mod diagnostic;
#[cfg(feature = "test_unstable")]
pub mod test;
type CowPath<'a> = borrow::Cow<'a, path::Path>;
type CowStr<'a> = borrow::Cow<'a, str>;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "reason", rename_all = "kebab-case")]
pub enum Message<'a> {
#[serde(borrow)]
CompilerArtifact(Artifact<'a>),
#[serde(borrow)]
CompilerMessage(FromCompiler<'a>),
#[serde(borrow)]
BuildScriptExecuted(BuildScript<'a>),
#[cfg(not(feature = "strict_unstable"))]
#[doc(hidden)]
#[serde(other)]
Unknown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct Artifact<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
pub target: Target<'a>,
#[serde(borrow)]
pub profile: ArtifactProfile<'a>,
#[serde(borrow)]
pub features: Vec<CowStr<'a>>,
#[serde(borrow)]
pub filenames: Vec<CowPath<'a>>,
#[cfg(feature = "cargo_unstable")]
#[serde(borrow)]
pub executable: Option<CowPath<'a>>,
pub fresh: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct Target<'a> {
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(borrow)]
pub kind: Vec<CowStr<'a>>,
#[serde(default)]
#[serde(borrow)]
pub crate_types: Vec<CowStr<'a>>,
#[serde(default)]
#[serde(rename = "required-features")]
#[serde(borrow)]
pub required_features: Vec<CowStr<'a>>,
#[serde(borrow)]
pub src_path: CowPath<'a>,
#[serde(default = "edition_default")]
#[serde(borrow)]
pub edition: CowStr<'a>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
fn edition_default() -> CowStr<'static> {
"2015".into()
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct WorkspaceMember<'a> {
#[serde(borrow)]
raw: CowStr<'a>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct ArtifactProfile<'a> {
#[serde(borrow)]
pub opt_level: CowStr<'a>,
pub debuginfo: Option<u32>,
pub debug_assertions: bool,
pub overflow_checks: bool,
pub test: bool,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct FromCompiler<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
pub target: Target<'a>,
#[serde(borrow)]
pub message: diagnostic::Diagnostic<'a>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
pub struct BuildScript<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
pub linked_libs: Vec<CowStr<'a>>,
#[serde(borrow)]
pub linked_paths: Vec<CowPath<'a>>,
#[serde(borrow)]
pub cfgs: Vec<CowPath<'a>>,
#[serde(borrow)]
pub env: Vec<(CowStr<'a>, CowStr<'a>)>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}
#[cfg(not(feature = "print"))]
pub(crate) fn log_message(msg: &Message) {
match msg {
Message::CompilerArtifact(ref art) => {
trace!("Building {:#?}", art.package_id,);
}
Message::CompilerMessage(ref comp) => {
let content = comp
.message
.rendered
.as_ref()
.map(|s| s.as_ref())
.unwrap_or(comp.message.message.as_ref());
match comp.message.level {
diagnostic::DiagnosticLevel::Ice => error!("{}", content),
diagnostic::DiagnosticLevel::Error => error!("{}", content),
diagnostic::DiagnosticLevel::Warning => warn!("{}", content),
diagnostic::DiagnosticLevel::Note => info!("{}", content),
diagnostic::DiagnosticLevel::Help => info!("{}", content),
#[cfg(not(feature = "strict_unstable"))]
_ => warn!("Unknown message: {:#?}", msg),
}
}
Message::BuildScriptExecuted(ref script) => {
trace!("Ran script from {:#?}", script.package_id);
}
#[cfg(not(feature = "strict_unstable"))]
_ => {
warn!("Unknown message: {:#?}", msg);
}
}
}
#[cfg(feature = "print")]
pub(crate) fn log_message(msg: &Message) {
match msg {
Message::CompilerArtifact(ref art) => {
println!("Building {:#?}", art.package_id,);
}
Message::CompilerMessage(ref comp) => {
let content = comp
.message
.rendered
.as_ref()
.map(|s| s.as_ref())
.unwrap_or(comp.message.message.as_ref());
match comp.message.level {
diagnostic::DiagnosticLevel::Ice => println!("{}", content),
diagnostic::DiagnosticLevel::Error => println!("{}", content),
diagnostic::DiagnosticLevel::Warning => println!("{}", content),
diagnostic::DiagnosticLevel::Note => println!("{}", content),
diagnostic::DiagnosticLevel::Help => println!("{}", content),
#[cfg(not(feature = "strict_unstable"))]
_ => warn!("Unknown message: {:#?}", msg),
}
}
Message::BuildScriptExecuted(ref script) => {
println!("Ran script from {:#?}", script.package_id);
}
#[cfg(not(feature = "strict_unstable"))]
_ => {
println!("Unknown message: {:#?}", msg);
}
}
}