recursive processes use the current executable by default (#484)

- Recursive processes spawn the currently running executable by default,
removing the annoyance of mixing different compiler builds during
contract compilation.
- Remove the unused `once_cell` dependency.

Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
xermicus authored and GitHub committed 2026-02-22 18:14:21 +01:00
1 parent 971ab2c615
commit 073276696f
4 files changed
+23 -31

No files matched your search

Generated
-1
View File
@@ -9076,7 +9076,6 @@ dependencies = [
"log",
"mimalloc",
"normpath",
"once_cell",
"path-slash",
"rayon",
"revive-common",
-1
View File
@@ -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 }
+9 -7
View File
@@ -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<PathBuf> = OnceCell::new();
/// The default executable path, lazily initialized from the current binary.
static DEFAULT_EXECUTABLE: LazyLock<PathBuf> =
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<PathBuf> = 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());
+14 -22
View File
@@ -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<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
static EVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
static EVM_RUNTIME_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
Lazy::new(Default::default);
static YUL_IR_CACHE: Lazy<Mutex<HashMap<CachedBlob, String>>> = Lazy::new(Default::default);
static PVM_BLOB_CACHE: LazyLock<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
LazyLock::new(Default::default);
static EVM_BLOB_CACHE: LazyLock<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
LazyLock::new(Default::default);
static EVM_RUNTIME_BLOB_CACHE: LazyLock<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
LazyLock::new(Default::default);
static YUL_IR_CACHE: LazyLock<Mutex<HashMap<CachedBlob, String>>> = 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<T: ToString>(
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<T: ToString + Display>(
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<T: ToString>(sources: &[(T, T)]) -> BTreeMap<String, SolcStandard
}
/// Checks if the required executables are present in `${PATH}`.
/// Also initializes the resolc executable path for subprocess spawning,
/// since `std::env::current_exe()` returns the test runner binary in tests.
fn check_dependencies() {
for executable in [
crate::r#const::DEFAULT_EXECUTABLE_NAME,
@@ -439,6 +427,10 @@ fn check_dependencies() {
"The `{executable}` executable not found in ${{PATH}}"
);
}
let _ = crate::process::native_process::EXECUTABLE.set(
which::which(crate::r#const::DEFAULT_EXECUTABLE_NAME).expect("resolc should be in ${PATH}"),
);
}
/// The internal EVM bytecode compile helper.