diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index faec1c2..78acb23 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -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, pub optimization: Option, pub solc_version: Option, @@ -76,6 +75,12 @@ pub struct Compiler { additional_options: T::Options, } +impl Default for Compiler { + fn default() -> Self { + Self::new() + } +} + impl Compiler 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>) -> Self { self.input.solc_version = value.into(); self @@ -186,15 +185,6 @@ where } } -impl Default for Compiler -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, diff --git a/crates/compiler/src/revive_resolc.rs b/crates/compiler/src/revive_resolc.rs index 2095ef7..ff54542 100644 --- a/crates/compiler/src/revive_resolc.rs +++ b/crates/compiler/src/revive_resolc.rs @@ -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(), diff --git a/crates/compiler/src/solc.rs b/crates/compiler/src/solc.rs index 47df20a..0546677 100644 --- a/crates/compiler/src/solc.rs +++ b/crates/compiler/src/solc.rs @@ -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(), } diff --git a/crates/compiler/src/utils.rs b/crates/compiler/src/utils.rs index b001847..219e941 100644 --- a/crates/compiler/src/utils.rs +++ b/crates/compiler/src/utils.rs @@ -52,24 +52,42 @@ pub async fn solc_version(solc_path: &Path) -> anyhow::Result { #[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) + ) } }