pub struct Project<C: Compiler = MultiCompiler, T: ArtifactOutput<CompilerContract = C::CompilerContract> = ConfigurableArtifacts> {Show 15 fields
pub compiler: C,
pub paths: ProjectPathsConfig<C::Language>,
pub settings: C::Settings,
pub additional_settings: BTreeMap<String, C::Settings>,
pub restrictions: BTreeMap<PathBuf, RestrictionsWithVersion<<C::Settings as CompilerSettings>::Restrictions>>,
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
§paths: ProjectPathsConfig<C::Language>
The layout of the project
settings: C::Settings
The compiler settings
additional_settings: BTreeMap<String, C::Settings>
Additional settings for cases when default compiler settings are not enough to cover all possible restrictions.
restrictions: BTreeMap<PathBuf, RestrictionsWithVersion<<C::Settings as CompilerSettings>::Restrictions>>
Mapping from file path to requirements on settings to compile it.
This file will only be included into compiler inputs with profiles which satisfy the restrictions.
cached: bool
Whether caching is enabled
build_info: bool
Whether to output build information with each solc call.
no_artifacts: bool
Whether writing artifacts to disk is enabled
artifacts: T
Handles 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: Severity
The minimum severity level that is treated as a compiler error
offline: bool
Offline mode, if set, network access (download solc) is disallowed
slash_paths: bool
Windows 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<CompilerContract = C::CompilerContract>, C: Compiler> Project<C, T>
impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, 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
pub fn settings_profiles(&self) -> impl Iterator<Item = (&str, &C::Settings)>
Source§impl<C: Compiler, T: ArtifactOutput<CompilerContract = C::CompilerContract>> Project<C, T>
impl<C: Compiler, T: ArtifactOutput<CompilerContract = C::CompilerContract>> 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<CompilerContract = C::CompilerContract>, C: Compiler> Project<C, T>
impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler> Project<C, T>
Sourcepub fn artifacts_path(&self) -> &Path
pub fn artifacts_path(&self) -> &Path
Returns the path to the artifacts directory
Sourcepub fn sources_path(&self) -> &Path
pub fn sources_path(&self) -> &Path
Returns the path to the sources directory
Sourcepub fn cache_path(&self) -> &Path
pub fn cache_path(&self) -> &Path
Returns the path to the cache file
Sourcepub fn build_info_path(&self) -> &Path
pub fn build_info_path(&self) -> &Path
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());
Sourcepub fn find_contract_path(&self, target_name: &str) -> Result<PathBuf>
pub fn find_contract_path(&self, target_name: &str) -> Result<PathBuf>
Finds the path of the contract with the given name. Throws error if multiple or no contracts with the same name are found.
Sourcepub fn update_output_selection(
&mut self,
f: impl FnOnce(&mut OutputSelection) + Copy,
)
pub fn update_output_selection( &mut self, f: impl FnOnce(&mut OutputSelection) + Copy, )
Invokes CompilerSettings::update_output_selection on the project’s settings and all additional settings profiles.
Trait Implementations§
Source§impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler> ArtifactOutput for Project<C, T>
impl<T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler> ArtifactOutput for Project<C, T>
Source§type Artifact = <T as ArtifactOutput>::Artifact
type Artifact = <T as ArtifactOutput>::Artifact
Contract
type CompilerContract = <C as Compiler>::CompilerContract
Source§fn on_output<CP>(
&self,
contracts: &VersionedContracts<C::CompilerContract>,
sources: &VersionedSourceFiles,
layout: &ProjectPathsConfig<CP>,
ctx: OutputContext<'_>,
primary_profiles: &HashMap<PathBuf, &str>,
) -> Result<Artifacts<Self::Artifact>>
fn on_output<CP>( &self, contracts: &VersionedContracts<C::CompilerContract>, sources: &VersionedSourceFiles, layout: &ProjectPathsConfig<CP>, ctx: OutputContext<'_>, primary_profiles: &HashMap<PathBuf, &str>, ) -> Result<Artifacts<Self::Artifact>>
crate::CompilerOutput
. Read moreSource§fn handle_artifacts(
&self,
contracts: &VersionedContracts<C::CompilerContract>,
artifacts: &Artifacts<Self::Artifact>,
) -> Result<()>
fn handle_artifacts( &self, contracts: &VersionedContracts<C::CompilerContract>, artifacts: &Artifacts<Self::Artifact>, ) -> Result<()>
Source§fn output_file_name(
name: &str,
version: &Version,
profile: &str,
with_version: bool,
with_profile: bool,
) -> PathBuf
fn output_file_name( name: &str, version: &Version, profile: &str, with_version: bool, with_profile: bool, ) -> PathBuf
Greeter.json
Source§fn output_file(
contract_file: &Path,
name: &str,
version: &Version,
profile: &str,
with_version: bool,
with_profile: bool,
) -> PathBuf
fn output_file( contract_file: &Path, name: &str, version: &Version, profile: &str, with_version: bool, with_profile: bool, ) -> PathBuf
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: C::CompilerContract,
source_file: Option<&SourceFile>,
) -> Self::Artifact
fn contract_to_artifact( &self, file: &Path, name: &str, contract: C::CompilerContract, source_file: Option<&SourceFile>, ) -> Self::Artifact
Source§fn output_to_artifacts<CP>(
&self,
contracts: &VersionedContracts<C::CompilerContract>,
sources: &VersionedSourceFiles,
ctx: OutputContext<'_>,
layout: &ProjectPathsConfig<CP>,
primary_profiles: &HashMap<PathBuf, &str>,
) -> Artifacts<Self::Artifact>
fn output_to_artifacts<CP>( &self, contracts: &VersionedContracts<C::CompilerContract>, sources: &VersionedSourceFiles, ctx: OutputContext<'_>, layout: &ProjectPathsConfig<CP>, primary_profiles: &HashMap<PathBuf, &str>, ) -> 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<()>
Source§fn conflict_free_output_file(
already_taken: &HashSet<String>,
conflict: PathBuf,
contract_file: &Path,
artifacts_folder: &Path,
) -> PathBuf
fn conflict_free_output_file( already_taken: &HashSet<String>, conflict: PathBuf, contract_file: &Path, artifacts_folder: &Path, ) -> PathBuf
Source§fn get_artifact_path(
ctx: &OutputContext<'_>,
already_taken: &HashSet<String>,
file: &Path,
name: &str,
artifacts_folder: &Path,
version: &Version,
profile: &str,
with_version: bool,
with_profile: bool,
) -> PathBuf
fn get_artifact_path( ctx: &OutputContext<'_>, already_taken: &HashSet<String>, file: &Path, name: &str, artifacts_folder: &Path, version: &Version, profile: &str, with_version: bool, with_profile: bool, ) -> PathBuf
Source§impl<C: Clone + Compiler, T: Clone + ArtifactOutput<CompilerContract = C::CompilerContract>> Clone for Project<C, T>
impl<C: Clone + Compiler, T: Clone + ArtifactOutput<CompilerContract = C::CompilerContract>> Clone for Project<C, T>
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§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
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>
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>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
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>
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>
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>
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>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
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);