Struct ethers_solc::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_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
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
executable
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>
Available on non-WebAssembly only.
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>
Available on non-WebAssembly only.
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>
Available on non-WebAssembly only.
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
and non-WebAssembly only.
pub fn all_versions() -> Vec<SolcVersion>
svm-solc
and non-WebAssembly only.Returns the list of all versions that are available to download and marking those which are already installed.
sourcepub fn find_svm_installed_version(
version: impl AsRef<str>
) -> Result<Option<Self>>
Available on non-WebAssembly only.
pub fn find_svm_installed_version( version: impl AsRef<str> ) -> Result<Option<Self>>
sourcepub fn find_or_install_svm_version(version: impl AsRef<str>) -> Result<Self>
Available on non-WebAssembly and 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
and non-WebAssembly only.
pub fn detect_version(source: &Source) -> Result<Version>
svm-solc
and non-WebAssembly 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
and non-WebAssembly only.
pub fn ensure_installed(sol_version: &VersionReq) -> Result<Version>
svm-solc
and non-WebAssembly 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, SolcVmError>
Available on crate feature svm-solc
and non-WebAssembly only.
pub async fn install(version: &Version) -> Result<Self, SolcVmError>
svm-solc
and non-WebAssembly only.sourcepub fn blocking_install(version: &Version) -> Result<Self, SolcVmError>
Available on crate feature svm-solc
and non-WebAssembly only.
pub fn blocking_install(version: &Version) -> Result<Self, SolcVmError>
svm-solc
and non-WebAssembly only.Blocking version of Self::install
sourcepub fn verify_checksum(&self) -> Result<()>
Available on crate feature svm-solc
and non-WebAssembly only.
pub fn verify_checksum(&self) -> Result<()>
svm-solc
and non-WebAssembly 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
.
§Example
use ethers_solc::{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>
Run solc --stand-json
and return the solc
’s output as
CompilerOutput
§Example
use ethers_solc::{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>
Run solc --stand-json
and return the solc
’s output as the given json
output
pub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
pub fn version_short(&self) -> Result<Version>
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 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.
§Example
Compile 2 CompilerInput
s at once
use ethers_solc::{CompilerInput, Solc};
let solc1 = Solc::default();
let solc2 = Solc::default();
let input1 = CompilerInput::new("contracts").unwrap()[0].clone();
let input2 = CompilerInput::new("src").unwrap()[0].clone();
let outputs = Solc::compile_many([(solc1, input1), (solc2, input2)], 2).await.flattened().unwrap();
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 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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.