the compiler interface

Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-03-20 23:26:39 +01:00
parent d6c2535853
commit 6a0d705371
11 changed files with 251 additions and 1 deletions
Generated
+108
View File
@@ -1103,6 +1103,25 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
@@ -2476,6 +2495,15 @@ dependencies = [
"unarray",
]
[[package]]
name = "psm"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f58e5423e24c18cc840e1c98370b3993c6649cd1678b4d24318bcf0a083cbe88"
dependencies = [
"cc",
]
[[package]]
name = "quick-error"
version = "1.2.3"
@@ -2543,6 +2571,26 @@ dependencies = [
"rand_core",
]
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "redox_syscall"
version = "0.5.10"
@@ -2581,6 +2629,27 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "revive-common"
version = "0.1.0-dev.12"
source = "git+https://github.com/paritytech/revive?rev=497dae2494dabe12d1af32d6d687122903cb2ada#497dae2494dabe12d1af32d6d687122903cb2ada"
dependencies = [
"anyhow",
"serde",
"serde_json",
"serde_stacker",
]
[[package]]
name = "revive-dt-compiler"
version = "0.1.0"
dependencies = [
"anyhow",
"revive-common",
"revive-solc-json-interface",
"semver 1.0.26",
]
[[package]]
name = "revive-dt-core"
version = "0.1.0"
@@ -2619,6 +2688,19 @@ dependencies = [
"tokio",
]
[[package]]
name = "revive-solc-json-interface"
version = "0.1.0-dev.12"
source = "git+https://github.com/paritytech/revive?rev=497dae2494dabe12d1af32d6d687122903cb2ada#497dae2494dabe12d1af32d6d687122903cb2ada"
dependencies = [
"anyhow",
"rayon",
"revive-common",
"semver 1.0.26",
"serde",
"serde_json",
]
[[package]]
name = "rfc6979"
version = "0.4.0"
@@ -2779,6 +2861,9 @@ name = "semver"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
dependencies = [
"serde",
]
[[package]]
name = "semver-parser"
@@ -2821,6 +2906,16 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_stacker"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69c8defe6c780725cce4ec6ad3bd91e321baf6fa4e255df1f31e345d507ef01a"
dependencies = [
"serde",
"stacker",
]
[[package]]
name = "serde_with"
version = "3.12.0"
@@ -2952,6 +3047,19 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "stacker"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "601f9201feb9b09c00266478bf459952b9ef9a6b94edb2f21eba14ab681a60a9"
dependencies = [
"cc",
"cfg-if",
"libc",
"psm",
"windows-sys 0.52.0",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
+3 -1
View File
@@ -13,6 +13,7 @@ repository = "https://github.com/paritytech/revive-differential-testing.git"
rust-version = "1.85.0"
[workspace.dependencies]
revive-dt-compiler = { version = "0.1.0", path = "crates/compiler" }
revive-dt-core = { version = "0.1.0", path = "crates/core" }
revive-dt-format = { version = "0.1.0", path = "crates/format" }
revive-dt-node-interaction = { version = "0.1.0", path = "crates/node-interaction" }
@@ -30,7 +31,8 @@ serde_json = { version = "1.0", default-features = false, features = ["arbitrary
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
# revive compiler
revive-llvm-context = { git = "https://github.com/paritytech/revive", rev = "2bbc5d713d1bf8b38c43f6ce9382812561ca3ce1" }
revive-solc-json-interface = { git = "https://github.com/paritytech/revive", rev = "497dae2494dabe12d1af32d6d687122903cb2ada" }
revive-common = { git = "https://github.com/paritytech/revive", rev = "497dae2494dabe12d1af32d6d687122903cb2ada" }
# polkadot-sdk and friends
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "revive-dt-compiler"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true
repository.workspace = true
rust-version.workspace = true
[dependencies]
anyhow = { workspace = true }
revive-solc-json-interface = { workspace = true }
revive-common = { workspace = true }
semver = { workspace = true }
+113
View File
@@ -0,0 +1,113 @@
//! This crate provides compiler helpers for all supported Solidity targets:
//! - Ethereum solc compiler
//! - Polkadot revive compiler
use std::{fs::read_to_string, path::Path};
use revive_common::EVMVersion;
use revive_solc_json_interface::{
SolcStandardJsonInput, SolcStandardJsonInputLanguage, SolcStandardJsonInputSettings,
SolcStandardJsonInputSettingsOptimizer, SolcStandardJsonInputSettingsSelection,
SolcStandardJsonOutput,
};
use semver::Version;
pub mod revive_js;
pub mod revive_resolc;
pub mod solc;
/// A common interface for all supported Solidity compilers.
pub trait SolidityCompiler {
/// Extra options specific to the compiler.
type Options: Sized;
fn build(
&self,
input: &SolcStandardJsonInput,
extra_options: &Option<Self::Options>,
) -> anyhow::Result<SolcStandardJsonOutput>;
fn new(solc_version: &Version) -> Self;
}
/// A generic builder style interface for configuring all compiler options.
pub struct Compiler<T: SolidityCompiler> {
input: SolcStandardJsonInput,
extra_options: Option<T::Options>,
solc_version: Version,
allow_paths: Vec<String>,
base_path: Option<String>,
}
impl<T> Compiler<T>
where
T: SolidityCompiler,
{
pub fn new(solc_version: Version) -> Self {
Self {
input: SolcStandardJsonInput {
language: SolcStandardJsonInputLanguage::Solidity,
sources: Default::default(),
settings: SolcStandardJsonInputSettings::new(
None,
Default::default(),
None,
SolcStandardJsonInputSettingsSelection::new_required(),
SolcStandardJsonInputSettingsOptimizer::new(
false,
None,
&Version::new(0, 0, 0),
false,
),
None,
),
},
extra_options: None,
solc_version,
allow_paths: Default::default(),
base_path: None,
}
}
pub fn solc_optimizer(mut self, enabled: bool) -> Self {
self.input.settings.optimizer.enabled = enabled;
self
}
pub fn with_source(mut self, path: &Path) -> anyhow::Result<Self> {
self.input
.sources
.insert(path.display().to_string(), read_to_string(path)?.into());
Ok(self)
}
pub fn evm_version(mut self, evm_version: EVMVersion) -> Self {
self.input.settings.evm_version = Some(evm_version);
self
}
pub fn solc_version(mut self, solc_version: Version) -> Self {
self.solc_version = solc_version;
self
}
pub fn extra_options(mut self, extra_options: T::Options) -> Self {
self.extra_options = Some(extra_options);
self
}
pub fn allow_path(mut self, path: String) -> Self {
self.allow_paths.push(path);
self
}
pub fn base_path(mut self, base_path: String) -> Self {
self.base_path = Some(base_path);
self
}
pub fn try_build(&self) -> anyhow::Result<SolcStandardJsonOutput> {
let compiler = T::new(&self.solc_version);
compiler.build(&self.input, &self.extra_options)
}
}
+2
View File
@@ -0,0 +1,2 @@
//! Implements the [SolidityCompiler] trait with revive Wasm for
//! compiling contracts to PVM bytecode (via Wasm).
+2
View File
@@ -0,0 +1,2 @@
//! Implements the [SolidityCompiler] trait with resolc for
//! compiling contracts to PVM bytecode.
+2
View File
@@ -0,0 +1,2 @@
//! Implements the [SolidityCompiler] trait with solc for
//! compiling contracts to EVM bytecode.
+1
View File
@@ -0,0 +1 @@
//! The compiler driver builds the test case contracts for selected compilers.
+1
View File
@@ -0,0 +1 @@
//! The input driver executes the test cases differentially against selected nodes.
+4
View File
@@ -0,0 +1,4 @@
//! The test driver handles the compilation and execution of the test cases.
pub mod compiler;
pub mod input;
+1
View File
@@ -4,3 +4,4 @@
//! provides a helper utilty to execute tests.
pub mod arguments;
pub mod driver;