Struct foundry_compilers::Project
source · pub struct Project<C: Compiler = MultiCompiler, T: ArtifactOutput = ConfigurableArtifacts> {Show 14 fields
pub compiler: C,
pub locked_versions: HashMap<C::Language, Version>,
pub paths: ProjectPathsConfig<C::Language>,
pub settings: C::Settings,
pub cached: bool,
pub build_info: bool,
pub no_artifacts: bool,
pub artifacts: T,
pub ignored_error_codes: Vec<u64>,
pub ignored_file_paths: Vec<PathBuf>,
pub compiler_severity_filter: Severity,
pub offline: bool,
pub slash_paths: bool,
pub sparse_output: Option<Box<dyn FileFilter>>,
/* private fields */
}Expand description
Represents a project workspace and handles solc compiling of all contracts in that workspace.
Fields§
§compiler: C§locked_versions: HashMap<C::Language, Version>Compiler versions locked for specific languages.
paths: ProjectPathsConfig<C::Language>The layout of the project
settings: C::SettingsThe compiler settings
cached: boolWhether caching is enabled
build_info: boolWhether to output build information with each solc call.
no_artifacts: boolWhether writing artifacts to disk is enabled
artifacts: THandles all artifacts related tasks, reading and writing from the artifact dir.
ignored_error_codes: Vec<u64>Errors/Warnings which match these error codes are not going to be logged
ignored_file_paths: Vec<PathBuf>Errors/Warnings which match these file paths are not going to be logged
compiler_severity_filter: SeverityThe minimum severity level that is treated as a compiler error
offline: boolOffline mode, if set, network access (download solc) is disallowed
slash_paths: boolWindows only config value to ensure the all paths use / instead of \\, same as solc
This is a noop on other platforms
sparse_output: Option<Box<dyn FileFilter>>Optional sparse output filter used to optimize compilation.
Implementations§
source§impl Project
impl Project
sourcepub fn builder() -> ProjectBuilder
pub fn builder() -> ProjectBuilder
Convenience function to call ProjectBuilder::default().
§Examples
Configure with ConfigurableArtifacts artifacts output and MultiCompiler compiler:
use foundry_compilers::Project;
let config = Project::builder().build(Default::default())?;To configure any a project with any ArtifactOutput use either:
use foundry_compilers::Project;
let config = Project::builder().build(Default::default())?;or use the builder directly:
use foundry_compilers::{multi::MultiCompiler, ConfigurableArtifacts, ProjectBuilder};
let config = ProjectBuilder::<MultiCompiler>::default().build(Default::default())?;source§impl<T: ArtifactOutput, C: Compiler> Project<C, T>
impl<T: ArtifactOutput, C: Compiler> Project<C, T>
sourcepub fn artifacts_handler(&self) -> &T
pub fn artifacts_handler(&self) -> &T
Returns the handler that takes care of processing all artifacts
source§impl<C: Compiler, T: ArtifactOutput> Project<C, T>
impl<C: Compiler, T: ArtifactOutput> Project<C, T>
sourcepub fn standard_json_input(
&self,
target: &Path,
) -> Result<StandardJsonCompilerInput>
pub fn standard_json_input( &self, target: &Path, ) -> Result<StandardJsonCompilerInput>
Returns standard-json-input to compile the target contract
source§impl<T: ArtifactOutput, C: Compiler> Project<C, T>
impl<T: ArtifactOutput, C: Compiler> Project<C, T>
sourcepub fn artifacts_path(&self) -> &PathBuf
pub fn artifacts_path(&self) -> &PathBuf
Returns the path to the artifacts directory
sourcepub fn sources_path(&self) -> &PathBuf
pub fn sources_path(&self) -> &PathBuf
Returns the path to the sources directory
sourcepub fn cache_path(&self) -> &PathBuf
pub fn cache_path(&self) -> &PathBuf
Returns the path to the cache file
sourcepub fn build_info_path(&self) -> &PathBuf
pub fn build_info_path(&self) -> &PathBuf
Returns the path to the build-info directory nested in the artifacts dir
sourcepub fn read_cache_file(&self) -> Result<CompilerCache<C::Settings>>
pub fn read_cache_file(&self) -> Result<CompilerCache<C::Settings>>
Convenience function to read the cache file. See also CompilerCache::read_joined()
sourcepub fn set_solc_jobs(&mut self, jobs: usize)
pub fn set_solc_jobs(&mut self, jobs: usize)
sourcepub fn sources(&self) -> Result<Sources>
pub fn sources(&self) -> Result<Sources>
Returns all sources found under the project’s configured sources path
sourcepub fn rerun_if_sources_changed(&self)
pub fn rerun_if_sources_changed(&self)
Emit the cargo rerun-if-changed instruction.
This tells Cargo to re-run the build script if a file inside the project’s sources directory has changed.
Use this if you compile a project in a build.rs file.
§Examples
use foundry_compilers::{Project, ProjectPathsConfig};
// Configure the project with all its paths, solc, cache etc.
// where the root dir is the current Rust project.
let paths = ProjectPathsConfig::hardhat(env!("CARGO_MANIFEST_DIR").as_ref())?;
let project = Project::builder().paths(paths).build(Default::default())?;
let output = project.compile()?;
// Tell Cargo to rerun this build script that if a source file changes.
project.rerun_if_sources_changed();pub fn compile(&self) -> Result<ProjectCompileOutput<C, T>>
sourcepub fn compile_file(
&self,
file: impl Into<PathBuf>,
) -> Result<ProjectCompileOutput<C, T>>
pub fn compile_file( &self, file: impl Into<PathBuf>, ) -> Result<ProjectCompileOutput<C, T>>
Convenience function to compile a single solidity file with the project’s settings.
§Examples
use foundry_compilers::Project;
let project = Project::builder().build(Default::default())?;
let output = project.compile_file("example/Greeter.sol")?;sourcepub fn compile_files<P, I>(
&self,
files: I,
) -> Result<ProjectCompileOutput<C, T>>
pub fn compile_files<P, I>( &self, files: I, ) -> Result<ProjectCompileOutput<C, T>>
Convenience function to compile a series of solidity files with the project’s settings.
Same as Self::compile() but with the given files as input.
§Examples
use foundry_compilers::Project;
let project = Project::builder().build(Default::default())?;
let output = project.compile_files(["examples/Foo.sol", "examples/Bar.sol"])?;sourcepub fn cleanup(&self) -> Result<(), SolcIoError>
pub fn cleanup(&self) -> Result<(), SolcIoError>
Removes the project’s artifacts and cache file
If the cache file was the only file in the folder, this also removes the empty folder.
§Examples
use foundry_compilers::Project;
let project = Project::builder().build(Default::default())?;
let _ = project.compile()?;
assert!(project.artifacts_path().exists());
assert!(project.cache_path().exists());
project.cleanup();
assert!(!project.artifacts_path().exists());
assert!(!project.cache_path().exists());Trait Implementations§
source§impl<T: ArtifactOutput, C: Compiler> ArtifactOutput for Project<C, T>
impl<T: ArtifactOutput, C: Compiler> ArtifactOutput for Project<C, T>
source§type Artifact = <T as ArtifactOutput>::Artifact
type Artifact = <T as ArtifactOutput>::Artifact
Contractsource§fn on_output<CP>(
&self,
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
layout: &ProjectPathsConfig<CP>,
ctx: OutputContext<'_>,
) -> Result<Artifacts<Self::Artifact>>
fn on_output<CP>( &self, contracts: &VersionedContracts, sources: &VersionedSourceFiles, layout: &ProjectPathsConfig<CP>, ctx: OutputContext<'_>, ) -> Result<Artifacts<Self::Artifact>>
crate::CompilerOutput. Read moresource§fn handle_artifacts(
&self,
contracts: &VersionedContracts,
artifacts: &Artifacts<Self::Artifact>,
) -> Result<()>
fn handle_artifacts( &self, contracts: &VersionedContracts, artifacts: &Artifacts<Self::Artifact>, ) -> Result<()>
source§fn output_file_name(name: &str) -> PathBuf
fn output_file_name(name: &str) -> PathBuf
Greeter.jsonsource§fn output_file_name_versioned(name: &str, version: &Version) -> PathBuf
fn output_file_name_versioned(name: &str, version: &Version) -> PathBuf
Greeter.0.8.11.jsonsource§fn output_file(contract_file: &Path, name: &str) -> PathBuf
fn output_file(contract_file: &Path, name: &str) -> PathBuf
source§fn output_file_versioned(
contract_file: &Path,
name: &str,
version: &Version,
) -> PathBuf
fn output_file_versioned( contract_file: &Path, name: &str, version: &Version, ) -> PathBuf
source§fn output_exists(contract_file: &Path, name: &str, root: &Path) -> bool
fn output_exists(contract_file: &Path, name: &str, root: &Path) -> bool
source§fn read_cached_artifact(path: &Path) -> Result<Self::Artifact>
fn read_cached_artifact(path: &Path) -> Result<Self::Artifact>
source§fn read_cached_artifacts<P, I>(
files: I,
) -> Result<BTreeMap<PathBuf, Self::Artifact>>
fn read_cached_artifacts<P, I>( files: I, ) -> Result<BTreeMap<PathBuf, Self::Artifact>>
source§fn contract_to_artifact(
&self,
file: &Path,
name: &str,
contract: Contract,
source_file: Option<&SourceFile>,
) -> Self::Artifact
fn contract_to_artifact( &self, file: &Path, name: &str, contract: Contract, source_file: Option<&SourceFile>, ) -> Self::Artifact
source§fn output_to_artifacts<CP>(
&self,
contracts: &VersionedContracts,
sources: &VersionedSourceFiles,
ctx: OutputContext<'_>,
layout: &ProjectPathsConfig<CP>,
) -> Artifacts<Self::Artifact>
fn output_to_artifacts<CP>( &self, contracts: &VersionedContracts, sources: &VersionedSourceFiles, ctx: OutputContext<'_>, layout: &ProjectPathsConfig<CP>, ) -> Artifacts<Self::Artifact>
source§fn standalone_source_file_to_artifact(
&self,
path: &Path,
file: &VersionedSourceFile,
) -> Option<Self::Artifact>
fn standalone_source_file_to_artifact( &self, path: &Path, file: &VersionedSourceFile, ) -> Option<Self::Artifact>
SourceFile that doesn’t contain any contract definitions (interfaces,
contracts, libraries) to an artifact. Read moresource§fn is_dirty(&self, artifact_file: &ArtifactFile<Self::Artifact>) -> Result<bool>
fn is_dirty(&self, artifact_file: &ArtifactFile<Self::Artifact>) -> Result<bool>
source§fn handle_cached_artifacts(
&self,
artifacts: &Artifacts<Self::Artifact>,
) -> Result<()>
fn handle_cached_artifacts( &self, artifacts: &Artifacts<Self::Artifact>, ) -> Result<()>
Auto Trait Implementations§
impl<C, T> Freeze for Project<C, T>
impl<C = MultiCompiler, T = ConfigurableArtifacts> !RefUnwindSafe for Project<C, T>
impl<C, T> Send for Project<C, T>where
T: Send,
impl<C, T> Sync for Project<C, T>where
T: Sync,
impl<C, T> Unpin for Project<C, T>
impl<C = MultiCompiler, T = ConfigurableArtifacts> !UnwindSafe for Project<C, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightBlack.
§Example
println!("{}", value.bright_black());source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightGreen.
§Example
println!("{}", value.bright_green());source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightYellow.
§Example
println!("{}", value.bright_yellow());source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.bright_magenta());source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self with the
fg()
set to
Color::BrightWhite.
§Example
println!("{}", value.bright_white());source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlack.
§Example
println!("{}", value.on_bright_black());source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightGreen.
§Example
println!("{}", value.on_bright_green());source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightYellow.
§Example
println!("{}", value.on_bright_yellow());source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightBlue.
§Example
println!("{}", value.on_bright_blue());source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightMagenta.
§Example
println!("{}", value.on_bright_magenta());source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightCyan.
§Example
println!("{}", value.on_bright_cyan());source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self with the
bg()
set to
Color::BrightWhite.
§Example
println!("{}", value.on_bright_white());source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::Underline.
§Example
println!("{}", value.underline());source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self with the
attr()
set to
Attribute::RapidBlink.
§Example
println!("{}", value.rapid_blink());source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);