pub async fn compile(root: &str) -> Result<ProjectCompileOutput<ConfigurableArtifacts>> {
// Create path from string and check if the path exists
let root = PathBuf::from(root);
if !root.exists() {
return Err(eyre!("Project root {root:?} does not exists!"));
}
// Configure `root` as our project root
let paths = ProjectPathsConfig::builder()
.root(&root)
.sources(&root)
.build()?;
// Create a solc ProjectBuilder instance for compilation
let project = Project::builder()
.paths(paths)
.set_auto_detect(true) // auto detect solc version from solidity source code
.no_artifacts()
.build()?;
// Compile project
let output = project.compile()?;
println!("{:?}", output);
// Check for compilation errors
if output.has_compiler_errors() {
Err(eyre!(
"Compiling solidity project failed: {:?}",
output.output().errors
))
} else {
Ok(output.clone())
}
}
let project = common::compile("contracts/").await?;
Error
running 1 test
Error: "solc": No such file or directory (os error 2)
Location:
tests/common/mod.rs:33:18
test add_notice ... FAILED
failures:
failures:
add_notice
Error