pub struct Solc {
pub solc: PathBuf,
pub version: Version,
pub base_path: Option<PathBuf>,
pub allow_paths: BTreeSet<PathBuf>,
pub include_paths: BTreeSet<PathBuf>,
}
Expand description
Abstraction over solc
command line utility
Supports sync and async functions.
By default the solc path is configured as follows, with descending priority:
SOLC_PATH
environment variable- svm’s
global_version
(set viasvm use <version>
), stored at<svm_home>/.global_version
solc
otherwise
Fields§
§solc: PathBuf
Path to the solc
executable
version: Version
Compiler version.
base_path: Option<PathBuf>
Value for –base-path arg.
allow_paths: BTreeSet<PathBuf>
Value for –allow-paths arg.
include_paths: BTreeSet<PathBuf>
Value for –include-paths arg.
Implementations§
Source§impl Solc
impl Solc
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
A new instance which points to solc
. Invokes solc --version
to determine the version.
Returns error if solc
is not found in the system or if the version cannot be retrieved.
Sourcepub fn new_with_version(path: impl Into<PathBuf>, version: Version) -> Self
pub fn new_with_version(path: impl Into<PathBuf>, version: Version) -> Self
A new instance which points to solc
with the given version
Sourcepub fn svm_home() -> Option<PathBuf>
pub fn svm_home() -> Option<PathBuf>
Returns the directory in which svm stores all versions
This will be:
~/.svm
on unix, if it exists- $XDG_DATA_HOME (~/.local/share/svm) if the svm folder does not exist.
Sourcepub fn svm_global_version() -> Option<Version>
pub fn svm_global_version() -> Option<Version>
Returns the semver::Version
svm’s .global_version
is currently set to.
global_version
is configured with (svm use <version>
)
This will read the version string (eg: “0.8.9”) that the ~/.svm/.global_version
file
contains
Sourcepub fn installed_versions() -> Vec<Version>
pub fn installed_versions() -> Vec<Version>
Returns the list of all solc instances installed at SVM_HOME
Sourcepub fn released_versions() -> Vec<Version>
Available on crate feature svm-solc
only.
pub fn released_versions() -> Vec<Version>
svm-solc
only.Returns the list of all versions that are available to download
Sourcepub async fn install(version: &Version) -> Result<Self, SvmError>
Available on crate feature svm-solc
only.
pub async fn install(version: &Version) -> Result<Self, SvmError>
svm-solc
only.Sourcepub fn blocking_install(version: &Version) -> Result<Self, SvmError>
Available on crate feature svm-solc
only.
pub fn blocking_install(version: &Version) -> Result<Self, SvmError>
svm-solc
only.Blocking version of Self::install
Sourcepub fn verify_checksum(&self) -> Result<()>
Available on crate feature svm-solc
only.
pub fn verify_checksum(&self) -> Result<()>
svm-solc
only.Verify that the checksum for this version of solc is correct. We check against the SHA256 checksum from the build information published by binaries.soliditylang.org
Sourcepub fn compile_source(&self, path: impl AsRef<Path>) -> Result<CompilerOutput>
pub fn compile_source(&self, path: impl AsRef<Path>) -> Result<CompilerOutput>
Convenience function for compiling all sources under the given path
Sourcepub fn compile_exact(&self, input: &SolcInput) -> Result<CompilerOutput>
pub fn compile_exact(&self, input: &SolcInput) -> Result<CompilerOutput>
Same as Self::compile()
, but only returns those files which are included in the
CompilerInput
.
In other words, this removes those files from the CompilerOutput
that are not included
in the provided CompilerInput
.
§Examples
Sourcepub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
pub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
Compiles with --standard-json
and deserializes the output as CompilerOutput
.
§Examples
use foundry_compilers::{CompilerInput, Solc};
let solc = Solc::default();
let input = CompilerInput::new("./contracts")?;
let output = solc.compile(&input)?;
Sourcepub fn compile_as<T: Serialize, D: DeserializeOwned>(
&self,
input: &T,
) -> Result<D>
pub fn compile_as<T: Serialize, D: DeserializeOwned>( &self, input: &T, ) -> Result<D>
Compiles with --standard-json
and deserializes the output as the given D
.
Sourcepub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
pub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
Compiles with --standard-json
and returns the raw stdout
output.
Sourcepub fn version_short(&self) -> Version
pub fn version_short(&self) -> Version
Invokes solc --version
and parses the output as a SemVer Version
, stripping the
pre-release and build metadata.
Sourcepub fn version(solc: impl Into<PathBuf>) -> Result<Version>
pub fn version(solc: impl Into<PathBuf>) -> Result<Version>
Invokes solc --version
and parses the output as a SemVer Version
.
Sourcepub fn configure_cmd(&self) -> Command
pub fn configure_cmd(&self) -> Command
Configures Command object depeending on settings and solc version used. Some features are only supported by newer versions of solc, so we have to disable them for older ones.
Source§impl Solc
impl Solc
Sourcepub async fn async_compile_source(
&self,
path: impl AsRef<Path>,
) -> Result<CompilerOutput>
Available on crate feature async
only.
pub async fn async_compile_source( &self, path: impl AsRef<Path>, ) -> Result<CompilerOutput>
async
only.Convenience function for compiling all sources under the given path
Sourcepub async fn async_compile<T: Serialize>(
&self,
input: &T,
) -> Result<CompilerOutput>
Available on crate feature async
only.
pub async fn async_compile<T: Serialize>( &self, input: &T, ) -> Result<CompilerOutput>
async
only.Run solc --stand-json
and return the solc
’s output as
CompilerOutput
Sourcepub async fn async_compile_as<T: Serialize, D: DeserializeOwned>(
&self,
input: &T,
) -> Result<D>
Available on crate feature async
only.
pub async fn async_compile_as<T: Serialize, D: DeserializeOwned>( &self, input: &T, ) -> Result<D>
async
only.Run solc --stand-json
and return the solc
’s output as the given json
output
pub async fn async_compile_output<T: Serialize>( &self, input: &T, ) -> Result<Vec<u8>>
async
only.pub async fn async_version(solc: impl AsRef<Path>) -> Result<Version>
async
only.Sourcepub async fn compile_many<I>(jobs: I, n: usize) -> CompiledMany
Available on crate feature async
only.
pub async fn compile_many<I>(jobs: I, n: usize) -> CompiledMany
async
only.Compiles all CompilerInput
s with their associated Solc
.
This will buffer up to n
solc
processes and then return the CompilerOutput
s in the
order in which they complete. No more than n
futures will be buffered at any point in
time, and less than n
may also be buffered depending on the state of each future.
§Examples
Compile 2 CompilerInput
s at once
use foundry_compilers::{CompilerInput, Solc};
let solc1 = Solc::default();
let solc2 = Solc::default();
let input1 = CompilerInput::new("contracts")?[0].clone();
let input2 = CompilerInput::new("src")?[0].clone();
let outputs = Solc::compile_many([(solc1, input1), (solc2, input2)], 2).await.flattened()?;
Trait Implementations§
Source§impl Compiler for Solc
impl Compiler for Solc
Source§const FILE_EXTENSIONS: &'static [&'static str] = SOLC_EXTENSIONS
const FILE_EXTENSIONS: &'static [&'static str] = SOLC_EXTENSIONS
Source§type Input = SolcInput
type Input = SolcInput
Source§type CompilationError = Error
type CompilationError = Error
Source§type ParsedSource = SolData
type ParsedSource = SolData
Source§fn compile(
&self,
input: Self::Input,
) -> Result<(Self::Input, CompilerOutput<Self::CompilationError>)>
fn compile( &self, input: Self::Input, ) -> Result<(Self::Input, CompilerOutput<Self::CompilationError>)>
Source§fn with_allowed_paths(self, allowed_paths: BTreeSet<PathBuf>) -> Self
fn with_allowed_paths(self, allowed_paths: BTreeSet<PathBuf>) -> Self
Source§fn with_base_path(self, base_path: PathBuf) -> Self
fn with_base_path(self, base_path: PathBuf) -> Self
Source§fn with_include_paths(self, include_paths: BTreeSet<PathBuf>) -> Self
fn with_include_paths(self, include_paths: BTreeSet<PathBuf>) -> Self
Source§impl<'de> Deserialize<'de> for Solc
impl<'de> Deserialize<'de> for Solc
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Solc
impl Ord for Solc
Source§impl PartialOrd for Solc
impl PartialOrd for Solc
impl Eq for Solc
impl StructuralPartialEq for Solc
Auto Trait Implementations§
impl Freeze for Solc
impl RefUnwindSafe for Solc
impl Send for Solc
impl Sync for Solc
impl Unpin for Solc
impl UnwindSafe for Solc
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> 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);