diff --git a/Cargo.lock b/Cargo.lock index 8430972..cbda44d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9076,7 +9076,6 @@ dependencies = [ "log", "mimalloc", "normpath", - "once_cell", "path-slash", "rayon", "revive-common", diff --git a/crates/resolc/Cargo.toml b/crates/resolc/Cargo.toml index 1272790..c65b525 100644 --- a/crates/resolc/Cargo.toml +++ b/crates/resolc/Cargo.toml @@ -23,7 +23,6 @@ clap = { workspace = true } hex = { workspace = true } inkwell = { workspace = true } log = { workspace = true } -once_cell = { workspace = true } path-slash = { workspace = true } rayon = { workspace = true, optional = true } semver = { workspace = true } diff --git a/crates/resolc/src/process/native_process.rs b/crates/resolc/src/process/native_process.rs index d99e064..85a1632 100644 --- a/crates/resolc/src/process/native_process.rs +++ b/crates/resolc/src/process/native_process.rs @@ -3,8 +3,9 @@ use std::io::Write; use std::path::PathBuf; use std::process::Command; +use std::sync::LazyLock; +use std::sync::OnceLock; -use once_cell::sync::OnceCell; use revive_common::deserialize_from_slice; use revive_common::EXIT_CODE_SUCCESS; use revive_solc_json_interface::standard_json::output::error::source_location::SourceLocation; @@ -16,8 +17,12 @@ use super::Input; use super::Output; use super::Process; -/// The overriden executable name used when the compiler is run as a library. -pub static EXECUTABLE: OnceCell = OnceCell::new(); +/// The default executable path, lazily initialized from the current binary. +static DEFAULT_EXECUTABLE: LazyLock = + LazyLock::new(|| std::env::current_exe().expect("Should have an executable")); + +/// Override for the executable path, used when the compiler is run as a library. +pub static EXECUTABLE: OnceLock = OnceLock::new(); pub struct NativeProcess; @@ -61,10 +66,7 @@ impl Process for NativeProcess { I: Serialize, O: DeserializeOwned, { - let executable = EXECUTABLE - .get() - .cloned() - .unwrap_or_else(|| std::env::current_exe().expect("Should have an executable")); + let executable = EXECUTABLE.get().unwrap_or(&DEFAULT_EXECUTABLE); let mut command = Command::new(executable.as_path()); command.stdin(std::process::Stdio::piped()); command.stdout(std::process::Stdio::piped()); diff --git a/crates/resolc/src/test_utils.rs b/crates/resolc/src/test_utils.rs index 61a55fb..d54330a 100644 --- a/crates/resolc/src/test_utils.rs +++ b/crates/resolc/src/test_utils.rs @@ -4,10 +4,8 @@ use std::collections::BTreeMap; use std::collections::BTreeSet; use std::collections::HashMap; use std::fmt::Display; -use std::path::PathBuf; use std::sync::Mutex; -use once_cell::sync::Lazy; use revive_common::MetadataHash; use revive_llvm_context::initialize_llvm; use revive_llvm_context::DebugConfig; @@ -24,16 +22,19 @@ use revive_solc_json_interface::SolcStandardJsonInputSettingsSelection; use revive_solc_json_interface::SolcStandardJsonInputSource; use revive_solc_json_interface::SolcStandardJsonOutput; use revive_solc_json_interface::SolcStandardJsonOutputErrorHandler; +use std::sync::LazyLock; use crate::project::Project; use crate::solc::solc_compiler::SolcCompiler; use crate::solc::Compiler; -static PVM_BLOB_CACHE: Lazy>>> = Lazy::new(Default::default); -static EVM_BLOB_CACHE: Lazy>>> = Lazy::new(Default::default); -static EVM_RUNTIME_BLOB_CACHE: Lazy>>> = - Lazy::new(Default::default); -static YUL_IR_CACHE: Lazy>> = Lazy::new(Default::default); +static PVM_BLOB_CACHE: LazyLock>>> = + LazyLock::new(Default::default); +static EVM_BLOB_CACHE: LazyLock>>> = + LazyLock::new(Default::default); +static EVM_RUNTIME_BLOB_CACHE: LazyLock>>> = + LazyLock::new(Default::default); +static YUL_IR_CACHE: LazyLock>> = LazyLock::new(Default::default); const DEBUG_CONFIG: revive_llvm_context::DebugConfig = DebugConfig::new(None, true); @@ -78,9 +79,6 @@ pub fn build_solidity_with_options( inkwell::support::enable_llvm_pretty_stack_trace(); initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]); - let _ = crate::process::native_process::EXECUTABLE - .set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); - let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let solc_version = solc.version()?; @@ -146,9 +144,6 @@ pub fn build_solidity_with_options_evm( check_dependencies(); inkwell::support::enable_llvm_pretty_stack_trace(); initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]); - let _ = crate::process::native_process::EXECUTABLE - .set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); - let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let mut input = SolcStandardJsonInput::try_from_solidity_sources( None, @@ -204,9 +199,6 @@ pub fn build_solidity_and_detect_missing_libraries( inkwell::support::enable_llvm_pretty_stack_trace(); initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]); - let _ = crate::process::native_process::EXECUTABLE - .set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); - let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let solc_version = solc.version()?; let mut input = SolcStandardJsonInput::try_from_solidity_sources( @@ -249,9 +241,6 @@ pub fn build_yul( inkwell::support::enable_llvm_pretty_stack_trace(); initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]); - let _ = crate::process::native_process::EXECUTABLE - .set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); - let mut build = Project::try_from_yul_sources( sources .iter() @@ -298,9 +287,6 @@ pub fn build_yul_standard_json( inkwell::support::enable_llvm_pretty_stack_trace(); initialize_llvm(PolkaVMTarget::PVM, crate::DEFAULT_EXECUTABLE_NAME, &[]); - let _ = crate::process::native_process::EXECUTABLE - .set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); - let solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let mut output = solc.validate_yul_standard_json(&mut solc_input, &mut vec![])?; if output.has_errors() { @@ -427,6 +413,8 @@ pub fn sources(sources: &[(T, T)]) -> BTreeMap