This commit is contained in:
James Wilson
2025-08-21 12:45:36 +01:00
parent eb754bc9e8
commit bdd2eab194
4 changed files with 46 additions and 31 deletions
+6 -16
View File
@@ -50,7 +50,6 @@ pub trait SolidityCompiler {
/// The generic compilation input configuration.
#[derive(Debug, Clone, Serialize)]
pub struct CompilerInput {
pub wasm: bool,
pub pipeline: Option<ModePipeline>,
pub optimization: Option<ModeOptimizerSetting>,
pub solc_version: Option<VersionReq>,
@@ -76,6 +75,12 @@ pub struct Compiler<T: SolidityCompiler> {
additional_options: T::Options,
}
impl Default for Compiler<solc::Solc> {
fn default() -> Self {
Self::new()
}
}
impl<T> Compiler<T>
where
T: SolidityCompiler,
@@ -83,7 +88,6 @@ where
pub fn new() -> Self {
Self {
input: CompilerInput {
wasm: Default::default(),
pipeline: Default::default(),
optimization: Default::default(),
solc_version: Default::default(),
@@ -98,11 +102,6 @@ where
}
}
pub fn with_wasm(mut self, value: bool) -> Self {
self.input.wasm = value;
self
}
pub fn with_solc_version_req(mut self, value: impl Into<Option<VersionReq>>) -> Self {
self.input.solc_version = value.into();
self
@@ -186,15 +185,6 @@ where
}
}
impl<T> Default for Compiler<T>
where
T: SolidityCompiler,
{
fn default() -> Self {
Self::new()
}
}
/// Defines how the compiler should handle revert strings.
#[derive(
Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
+9 -4
View File
@@ -23,6 +23,8 @@ use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
/// A wrapper around the `resolc` binary, emitting PVM-compatible bytecode.
#[derive(Debug)]
pub struct Resolc {
// Enable wasm compilation.
wasm: bool,
// Where to cache artifacts.
cache_directory: PathBuf,
// We'll use this version when no explicit version
@@ -39,7 +41,6 @@ impl SolidityCompiler for Resolc {
async fn build(
&self,
CompilerInput {
wasm,
pipeline,
optimization,
solc_version,
@@ -62,9 +63,12 @@ impl SolidityCompiler for Resolc {
let solc_version_req = solc_version
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
let solc_path =
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version_req, wasm)
.await?;
let solc_path = revive_dt_solc_binaries::download_solc(
&self.cache_directory,
solc_version_req,
self.wasm,
)
.await?;
let solc_version = utils::solc_version(&solc_path).await?;
if solc_version < SOLC_VERSION_SUPPORTING_VIA_YUL_IR {
@@ -222,6 +226,7 @@ impl SolidityCompiler for Resolc {
fn new(config: &Arguments) -> Self {
Resolc {
wasm: config.wasm,
cache_directory: config.directory().to_path_buf(),
solc_version: config.solc.clone(),
resolc_path: config.resolc.clone(),
+4 -2
View File
@@ -23,6 +23,8 @@ use tokio::{io::AsyncWriteExt, process::Command as AsyncCommand};
#[derive(Debug)]
pub struct Solc {
// Enable wasm compilation.
wasm: bool,
// Where to cache artifacts.
cache_directory: PathBuf,
// We'll use this version when no explicit version requirement
@@ -37,7 +39,6 @@ impl SolidityCompiler for Solc {
async fn build(
&self,
CompilerInput {
wasm,
pipeline,
optimization,
solc_version,
@@ -53,7 +54,7 @@ impl SolidityCompiler for Solc {
let solc_version = solc_version
.unwrap_or_else(|| VersionOrRequirement::version_to_requirement(&self.solc_version));
let solc_path =
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version, wasm)
revive_dt_solc_binaries::download_solc(&self.cache_directory, solc_version, self.wasm)
.await?;
let compiler_supports_via_ir =
utils::solc_version(&solc_path).await? >= SOLC_VERSION_SUPPORTING_VIA_YUL_IR;
@@ -208,6 +209,7 @@ impl SolidityCompiler for Solc {
fn new(config: &Arguments) -> Self {
Self {
wasm: config.wasm,
cache_directory: config.directory().to_path_buf(),
solc_version: config.solc.clone(),
}
+27 -9
View File
@@ -52,24 +52,42 @@ pub async fn solc_version(solc_path: &Path) -> anyhow::Result<semver::Version> {
#[cfg(test)]
mod test {
use super::*;
use revive_dt_common::types::VersionOrRequirement;
#[tokio::test]
async fn compiler_version_can_be_obtained() {
// Arrange
let temp_dir = tempfile::tempdir().expect("can create tempdir");
let solc_path = revive_dt_solc_binaries::download_solc(
temp_dir.path(),
VersionOrRequirement::default(),
false,
)
.await
.expect("can download solc");
let solc_path =
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 7, 6), false)
.await
.expect("can download solc");
// Act
let version = solc_version(&solc_path).await;
// Assert
let _ = version.expect("Failed to get version");
assert_eq!(
version.expect("Failed to get version"),
Version::new(0, 7, 6)
)
}
#[tokio::test]
async fn compiler_version_can_be_obtained1() {
// Arrange
let temp_dir = tempfile::tempdir().expect("can create tempdir");
let solc_path =
revive_dt_solc_binaries::download_solc(temp_dir.path(), Version::new(0, 4, 21), false)
.await
.expect("can download solc");
// Act
let version = solc_version(&solc_path).await;
// Assert
assert_eq!(
version.expect("Failed to get version"),
Version::new(0, 4, 21)
)
}
}