Struct foundry_compilers::Solc
source · pub struct Solc {
pub solc: PathBuf,
pub base_path: Option<PathBuf>,
pub args: Vec<String>,
}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_PATHenvironment variable- svm’s
global_version(set viasvm use <version>), stored at<svm_home>/.global_version solcotherwise
Fields§
§solc: PathBufPath to the solc executable
base_path: Option<PathBuf>The base path to set when invoking solc, see also https://docs.soliditylang.org/en/v0.8.11/path-resolution.html#base-path-and-include-paths
args: Vec<String>Additional arguments passed to the solc exectuable
Implementations§
source§impl Solc
impl Solc
sourcepub fn with_base_path(self, base_path: impl Into<PathBuf>) -> Self
pub fn with_base_path(self, base_path: impl Into<PathBuf>) -> Self
Sets solc’s base path
Ref: https://docs.soliditylang.org/en/v0.8.11/path-resolution.html#base-path-and-include-paths
sourcepub fn arg<T: Into<String>>(self, arg: T) -> Self
pub fn arg<T: Into<String>>(self, arg: T) -> Self
Adds an argument to pass to the solc command.
sourcepub fn svm_home() -> Option<PathBuf>
pub fn svm_home() -> Option<PathBuf>
Returns the directory in which svm stores all versions
This will be:
~/.svmon 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<SolcVersion>
pub fn installed_versions() -> Vec<SolcVersion>
Returns the list of all solc instances installed at SVM_HOME
sourcepub fn all_versions() -> Vec<SolcVersion>
Available on crate feature svm-solc only.
pub fn all_versions() -> Vec<SolcVersion>
svm-solc only.Returns the list of all versions that are available to download and marking those which are already installed.
sourcepub fn find_or_install_svm_version(version: impl AsRef<str>) -> Result<Self>
Available on crate feature svm-solc only.
pub fn find_or_install_svm_version(version: impl AsRef<str>) -> Result<Self>
svm-solc only.sourcepub fn find_matching_installation(
versions: &[Version],
required_version: &VersionReq
) -> Option<Version>
pub fn find_matching_installation( versions: &[Version], required_version: &VersionReq ) -> Option<Version>
Assuming the versions array is sorted, it returns the first element which satisfies
the provided VersionReq
sourcepub fn detect_version(source: &Source) -> Result<Version>
Available on crate feature svm-solc only.
pub fn detect_version(source: &Source) -> Result<Version>
svm-solc only.Given a Solidity source, it detects the latest compiler version which can be used to build it, and returns it.
If the required compiler version is not installed, it also proceeds to install it.
sourcepub fn ensure_installed(sol_version: &VersionReq) -> Result<Version>
Available on crate feature svm-solc only.
pub fn ensure_installed(sol_version: &VersionReq) -> Result<Version>
svm-solc only.Given a Solidity version requirement, it detects the latest compiler version which can be used to build it, and returns it.
If the required compiler version is not installed, it also proceeds to install it.
sourcepub fn source_version_req(source: &Source) -> Result<VersionReq>
pub fn source_version_req(source: &Source) -> Result<VersionReq>
Parses the given source looking for the pragma definition and
returns the corresponding SemVer version requirement.
sourcepub fn version_req(version: &str) -> Result<VersionReq>
pub fn version_req(version: &str) -> Result<VersionReq>
Returns the corresponding SemVer version requirement for the solidity version.
Note: This is a workaround for the fact that VersionReq::parse does not support whitespace
separators and requires comma separated operators. See VersionReq.
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: &CompilerInput) -> Result<CompilerOutput>
pub fn compile_exact(&self, input: &CompilerInput) -> 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
use foundry_compilers::{CompilerInput, Solc};
let solc = Solc::default();
let input = CompilerInput::new("./contracts")?[0].clone();
let output = solc.compile_exact(&input)?;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) -> Result<Version>
pub fn version_short(&self) -> Result<Version>
Invokes solc --version and parses the output as a SemVer Version, stripping the
pre-release and build metadata.
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(&self) -> 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 CompilerInputs with their associated Solc.
This will buffer up to n solc processes and then return the CompilerOutputs 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 CompilerInputs 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<'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 PartialEq for Solc
impl PartialEq for Solc
source§impl PartialOrd for Solc
impl PartialOrd for Solc
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl 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> 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 more