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, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "reason", rename_all = "kebab-case")]
#[allow(clippy::large_enum_variant)]
pub enum Message<'a> {
BuildFinished(BuildFinished),
#[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, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct BuildFinished {
pub success: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct Artifact<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
pub manifest_path: Option<CowPath<'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>>,
#[serde(borrow)]
#[serde(default)]
pub executable: Option<CowPath<'a>>,
pub fresh: bool,
}
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
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)]
pub doctest: Option<bool>,
#[serde(default)]
pub doc: Option<bool>,
#[serde(default)]
pub test: bool,
#[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>,
}
fn edition_default() -> CowStr<'static> {
"2015".into()
}
#[derive(Debug, Clone, 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, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct ArtifactProfile<'a> {
#[serde(borrow)]
pub opt_level: CowStr<'a>,
pub debuginfo: Option<DebugInfo<'a>>,
pub debug_assertions: bool,
pub overflow_checks: bool,
pub test: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[serde(untagged)]
#[non_exhaustive]
pub enum DebugInfo<'a> {
Level(u32),
#[serde(borrow)]
Name(CowStr<'a>),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct FromCompiler<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
pub manifest_path: Option<CowPath<'a>>,
#[serde(borrow)]
pub target: Target<'a>,
#[serde(borrow)]
pub message: diagnostic::Diagnostic<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "strict_unstable", serde(deny_unknown_fields))]
#[non_exhaustive]
pub struct BuildScript<'a> {
#[serde(borrow)]
pub package_id: WorkspaceMember<'a>,
#[serde(borrow)]
#[serde(default)]
pub out_dir: Option<CowPath<'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>)>,
}
#[cfg(not(feature = "print"))]
pub(crate) fn log_message(msg: &Message<'_>) {
match msg {
Message::BuildFinished(ref finished) => {
log::trace!("Build Finished: {:?}", finished.success);
}
Message::CompilerArtifact(ref art) => {
log::trace!("Building {:#?}", art.package_id,);
}
Message::CompilerMessage(ref comp) => {
let content = comp
.message
.rendered
.as_ref()
.map(|s| s.as_ref())
.unwrap_or_else(|| comp.message.message.as_ref());
match comp.message.level {
diagnostic::DiagnosticLevel::Ice => log::error!("{}", content),
diagnostic::DiagnosticLevel::Error => log::error!("{}", content),
diagnostic::DiagnosticLevel::Warning => log::warn!("{}", content),
diagnostic::DiagnosticLevel::Note => log::info!("{}", content),
diagnostic::DiagnosticLevel::Help => log::info!("{}", content),
#[cfg(not(feature = "strict_unstable"))]
_ => log::warn!("Unknown message: {:#?}", msg),
}
}
Message::BuildScriptExecuted(ref script) => {
log::trace!("Ran script from {:#?}", script.package_id);
}
#[cfg(not(feature = "strict_unstable"))]
_ => {
log::warn!("Unknown message: {:#?}", msg);
}
}
}
#[cfg(feature = "print")]
#[allow(clippy::print_stderr)]
pub(crate) fn log_message(msg: &Message<'_>) {
match msg {
Message::BuildFinished(ref finished) => {
eprintln!("Build Finished: {:?}", finished.success);
}
Message::CompilerArtifact(ref art) => {
eprintln!("Building {:#?}", art.package_id,);
}
Message::CompilerMessage(ref comp) => {
let content = comp
.message
.rendered
.as_ref()
.map(|s| s.as_ref())
.unwrap_or_else(|| comp.message.message.as_ref());
match comp.message.level {
diagnostic::DiagnosticLevel::Ice => eprintln!("{content}"),
diagnostic::DiagnosticLevel::Error => eprintln!("{content}"),
diagnostic::DiagnosticLevel::Warning => eprintln!("{content}"),
diagnostic::DiagnosticLevel::Note => eprintln!("{content}"),
diagnostic::DiagnosticLevel::Help => eprintln!("{content}"),
#[cfg(not(feature = "strict_unstable"))]
_ => eprintln!("Unknown message: {:#?}", msg),
}
}
Message::BuildScriptExecuted(ref script) => {
eprintln!("Ran script from {:#?}", script.package_id);
}
#[cfg(not(feature = "strict_unstable"))]
_ => {
eprintln!("Unknown message: {:#?}", msg);
}
}
}