mod masm;
use miden_assembly_syntax::debuginfo::SourceManager;
use miden_project::ProjectDependencyGraph;
pub use self::masm::MasmSourceProvider;
use super::*;
pub struct TargetAssemblyContext<'a> {
pub package: &'a ProjectPackage,
pub manifest_path: &'a std::path::Path,
pub project_root: &'a std::path::Path,
pub resolved_target_root: Box<std::path::Path>,
pub target: &'a Target,
pub profile: &'a Profile,
pub dependency_graph: &'a ProjectDependencyGraph,
pub source_manager: Arc<dyn SourceManager>,
pub warnings_as_errors: bool,
}
impl<'a> TargetAssemblyContext<'a> {
pub fn new(
package: &'a ProjectPackage,
manifest_path: &'a std::path::Path,
target: &'a Target,
profile: &'a Profile,
dependency_graph: &'a ProjectDependencyGraph,
source_manager: Arc<dyn SourceManager>,
) -> Result<Self, Report> {
let project_root = manifest_path.parent().ok_or_else(|| {
Report::msg(format!("manifest '{}' has no parent directory", manifest_path.display()))
})?;
let target_path = target.path.to_path().ok_or_else(|| {
Report::msg(format!(
"invalid target '{}': '{}' is not a valid file path",
target.name.inner(),
target.path
))
})?;
let root_path = project_root.join(&target_path);
let root_path = root_path.canonicalize().map_err(|error| {
Report::msg(format!(
"failed to resolve target source '{}': {error}",
root_path.display()
))
})?;
Ok(TargetAssemblyContext {
package,
manifest_path,
project_root,
resolved_target_root: root_path.into_boxed_path(),
target,
profile,
dependency_graph,
source_manager,
warnings_as_errors: false,
})
}
#[inline]
pub fn with_warnings_as_errors(&mut self, yes: bool) -> &mut Self {
self.warnings_as_errors = yes;
self
}
}
pub trait ProjectSourceProvider {
fn file_type(&self) -> &'static str;
fn provide_sources(
&self,
context: &TargetAssemblyContext<'_>,
) -> Result<ProjectSourceInputs, Report>;
fn provide_source_provenance(
&self,
context: &TargetAssemblyContext<'_>,
) -> Result<ProjectSourceProvenanceInputs, Report>;
}