From 173ace72cbd060d19a95522a3d19925f8953397d Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Thu, 31 Oct 2024 13:00:35 +0100 Subject: [PATCH] solidity: rename the revive metadata (#106) Rename the revive metadata fields and includes the commit hash and LLVM version in the revive version (similar to what solc does). Signed-off-by: xermicus --- crates/solidity/src/build/mod.rs | 12 +++----- crates/solidity/src/lib.rs | 15 ++++------ crates/solidity/src/missing_libraries.rs | 4 +-- .../solidity/src/project/contract/metadata.rs | 14 ++++----- crates/solidity/src/resolc/main.rs | 6 ++-- crates/solidity/src/solc/combined_json/mod.rs | 2 +- .../src/solc/standard_json/output/mod.rs | 2 +- crates/solidity/src/test_utils.rs | 17 +++-------- crates/solidity/src/version.rs | 30 +++++++++++++++++++ 9 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 crates/solidity/src/version.rs diff --git a/crates/solidity/src/build/mod.rs b/crates/solidity/src/build/mod.rs index e7317542..5dd5d7e6 100644 --- a/crates/solidity/src/build/mod.rs +++ b/crates/solidity/src/build/mod.rs @@ -8,6 +8,7 @@ use std::path::Path; use crate::solc::combined_json::CombinedJson; use crate::solc::standard_json::output::Output as StandardJsonOutput; use crate::solc::version::Version as SolcVersion; +use crate::ResolcVersion; use self::contract::Contract; @@ -40,11 +41,7 @@ impl Build { } /// Writes all contracts assembly and bytecode to the combined JSON. - pub fn write_to_combined_json( - self, - combined_json: &mut CombinedJson, - resolc_version: &semver::Version, - ) -> anyhow::Result<()> { + pub fn write_to_combined_json(self, combined_json: &mut CombinedJson) -> anyhow::Result<()> { for (path, contract) in self.contracts.into_iter() { let combined_json_contract = combined_json .contracts @@ -61,7 +58,7 @@ impl Build { contract.write_to_combined_json(combined_json_contract)?; } - combined_json.zk_version = Some(resolc_version.to_string()); + combined_json.revive_version = Some(ResolcVersion::default().long); Ok(()) } @@ -71,7 +68,6 @@ impl Build { mut self, standard_json: &mut StandardJsonOutput, solc_version: &SolcVersion, - resolc_version: &semver::Version, ) -> anyhow::Result<()> { let contracts = match standard_json.contracts.as_mut() { Some(contracts) => contracts, @@ -90,7 +86,7 @@ impl Build { standard_json.version = Some(solc_version.default.to_string()); standard_json.long_version = Some(solc_version.long.to_owned()); - standard_json.zk_version = Some(resolc_version.to_string()); + standard_json.revive_version = Some(ResolcVersion::default().long); Ok(()) } diff --git a/crates/solidity/src/lib.rs b/crates/solidity/src/lib.rs index e093816a..b5c38ab2 100644 --- a/crates/solidity/src/lib.rs +++ b/crates/solidity/src/lib.rs @@ -7,6 +7,7 @@ pub(crate) mod missing_libraries; pub(crate) mod process; pub(crate) mod project; pub(crate) mod solc; +pub(crate) mod version; pub(crate) mod warning; pub(crate) mod yul; @@ -38,6 +39,7 @@ pub use self::solc::standard_json::output::contract::Contract as SolcStandardJso pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput; pub use self::solc::version::Version as SolcVersion; pub use self::solc::Compiler as SolcCompiler; +pub use self::version::Version as ResolcVersion; pub use self::warning::Warning; pub mod test_utils; @@ -197,7 +199,6 @@ pub fn standard_json( ) -> anyhow::Result<()> { let solc_version = solc.version()?; let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla); - let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid"); let solc_input = SolcStandardJsonInput::try_from_stdin(solc_pipeline)?; let source_code_files = solc_input @@ -244,14 +245,10 @@ pub fn standard_json( if detect_missing_libraries { let missing_libraries = project.get_missing_libraries(); - missing_libraries.write_to_standard_json( - &mut solc_output, - &solc_version, - &resolc_version, - )?; + missing_libraries.write_to_standard_json(&mut solc_output, &solc_version)?; } else { let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?; - build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?; + build.write_to_standard_json(&mut solc_output, &solc_version)?; } serde_json::to_writer(std::io::stdout(), &solc_output)?; std::process::exit(0); @@ -278,8 +275,6 @@ pub fn combined_json( output_directory: Option, overwrite: bool, ) -> anyhow::Result<()> { - let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid"); - let build = standard_output( input_files, libraries, @@ -298,7 +293,7 @@ pub fn combined_json( )?; let mut combined_json = solc.combined_json(input_files, format.as_str())?; - build.write_to_combined_json(&mut combined_json, &resolc_version)?; + build.write_to_combined_json(&mut combined_json)?; match output_directory { Some(output_directory) => { diff --git a/crates/solidity/src/missing_libraries.rs b/crates/solidity/src/missing_libraries.rs index d3edccc2..f14927fe 100644 --- a/crates/solidity/src/missing_libraries.rs +++ b/crates/solidity/src/missing_libraries.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; use crate::solc::standard_json::output::Output as StandardJsonOutput; use crate::solc::version::Version as SolcVersion; +use crate::ResolcVersion; /// The missing Solidity libraries. pub struct MissingLibraries { @@ -23,7 +24,6 @@ impl MissingLibraries { mut self, standard_json: &mut StandardJsonOutput, solc_version: &SolcVersion, - resolc_version: &semver::Version, ) -> anyhow::Result<()> { let contracts = match standard_json.contracts.as_mut() { Some(contracts) => contracts, @@ -43,7 +43,7 @@ impl MissingLibraries { standard_json.version = Some(solc_version.default.to_string()); standard_json.long_version = Some(solc_version.long.to_owned()); - standard_json.zk_version = Some(resolc_version.to_string()); + standard_json.revive_version = Some(ResolcVersion::default().long); Ok(()) } diff --git a/crates/solidity/src/project/contract/metadata.rs b/crates/solidity/src/project/contract/metadata.rs index 931b27c3..8b81b562 100644 --- a/crates/solidity/src/project/contract/metadata.rs +++ b/crates/solidity/src/project/contract/metadata.rs @@ -10,10 +10,10 @@ pub struct Metadata { pub solc_metadata: serde_json::Value, /// The `solc` version. pub solc_version: semver::Version, - /// The zkVM `solc` edition. - pub solc_zkvm_edition: Option, + /// The pallet revive edition. + pub revive_pallet_version: Option, /// The PolkaVM compiler version. - pub zk_version: semver::Version, + pub revive_version: semver::Version, /// The PolkaVM compiler optimizer settings. pub optimizer_settings: revive_llvm_context::OptimizerSettings, } @@ -23,15 +23,15 @@ impl Metadata { pub fn new( solc_metadata: serde_json::Value, solc_version: semver::Version, - solc_zkvm_edition: Option, - zk_version: semver::Version, + revive_pallet_version: Option, + revive_version: semver::Version, optimizer_settings: revive_llvm_context::OptimizerSettings, ) -> Self { Self { solc_metadata, solc_version, - solc_zkvm_edition, - zk_version, + revive_pallet_version, + revive_version, optimizer_settings, } } diff --git a/crates/solidity/src/resolc/main.rs b/crates/solidity/src/resolc/main.rs index b004ca19..881895b2 100644 --- a/crates/solidity/src/resolc/main.rs +++ b/crates/solidity/src/resolc/main.rs @@ -31,11 +31,9 @@ fn main_inner() -> anyhow::Result<()> { if arguments.version { println!( - "{} version {}+commit.{} (LLVM build {:?})", + "{} version {}", env!("CARGO_PKG_DESCRIPTION"), - env!("CARGO_PKG_VERSION"), - env!("GIT_COMMIT_HASH"), - inkwell::support::get_llvm_version(), + revive_solidity::ResolcVersion::default().long ); return Ok(()); } diff --git a/crates/solidity/src/solc/combined_json/mod.rs b/crates/solidity/src/solc/combined_json/mod.rs index 696f6fe9..0dd9c152 100644 --- a/crates/solidity/src/solc/combined_json/mod.rs +++ b/crates/solidity/src/solc/combined_json/mod.rs @@ -28,7 +28,7 @@ pub struct CombinedJson { pub version: String, /// The `resolc` compiler version. #[serde(skip_serializing_if = "Option::is_none")] - pub zk_version: Option, + pub revive_version: Option, } impl CombinedJson { diff --git a/crates/solidity/src/solc/standard_json/output/mod.rs b/crates/solidity/src/solc/standard_json/output/mod.rs index f78ab226..0d642851 100644 --- a/crates/solidity/src/solc/standard_json/output/mod.rs +++ b/crates/solidity/src/solc/standard_json/output/mod.rs @@ -45,7 +45,7 @@ pub struct Output { pub long_version: Option, /// The `resolc` compiler version. #[serde(skip_serializing_if = "Option::is_none")] - pub zk_version: Option, + pub revive_version: Option, } impl Output { diff --git a/crates/solidity/src/test_utils.rs b/crates/solidity/src/test_utils.rs index f3f436c2..ef80629b 100644 --- a/crates/solidity/src/test_utils.rs +++ b/crates/solidity/src/test_utils.rs @@ -3,7 +3,6 @@ use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::HashMap; use std::path::PathBuf; -use std::str::FromStr; use std::sync::Mutex; use once_cell::sync::Lazy; @@ -106,11 +105,7 @@ pub fn build_solidity_with_options( let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?; let build: crate::Build = project.compile(optimizer_settings, false, None)?; - build.write_to_standard_json( - &mut output, - &solc_version, - &semver::Version::from_str(env!("CARGO_PKG_VERSION"))?, - )?; + build.write_to_standard_json(&mut output, &solc_version)?; Ok(output) } @@ -202,11 +197,7 @@ pub fn build_solidity_and_detect_missing_libraries( let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?; let missing_libraries = project.get_missing_libraries(); - missing_libraries.write_to_standard_json( - &mut output, - &solc.version()?, - &semver::Version::from_str(env!("CARGO_PKG_VERSION"))?, - )?; + missing_libraries.write_to_standard_json(&mut output, &solc.version()?)?; Ok(output) } @@ -232,14 +223,14 @@ pub fn check_solidity_warning( warning_substring: &str, libraries: BTreeMap>, pipeline: SolcPipeline, - skip_for_zkvm_edition: bool, + skip_for_revive_edition: bool, suppressed_warnings: Option>, ) -> anyhow::Result { check_dependencies(); let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let solc_version = solc.version()?; - if skip_for_zkvm_edition && solc_version.l2_revision.is_some() { + if skip_for_revive_edition && solc_version.l2_revision.is_some() { return Ok(true); } diff --git a/crates/solidity/src/version.rs b/crates/solidity/src/version.rs new file mode 100644 index 00000000..8b3b3e3a --- /dev/null +++ b/crates/solidity/src/version.rs @@ -0,0 +1,30 @@ +//! The resolc compiler version. + +use serde::Deserialize; +use serde::Serialize; + +/// The resolc compiler version. +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Version { + /// The long version string. + pub long: String, + /// The short `semver`. + pub default: semver::Version, + /// The LLVM version string. + pub llvm: semver::Version, +} + +impl Default for Version { + fn default() -> Self { + let default = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid"); + let commit = env!("GIT_COMMIT_HASH"); + let (llvm_major, llvm_minor, llvm_patch) = inkwell::support::get_llvm_version(); + let llvm = semver::Version::new(llvm_major as u64, llvm_minor as u64, llvm_patch as u64); + + Self { + long: format!("{default}+commit.{commit}.llvm-{llvm}"), + default, + llvm, + } + } +}