Skip to content

Commit

Permalink
feat: --eof flag and config key (#9002)
Browse files Browse the repository at this point in the history
* feat: --eof flag and config key

* not windows

---------

Co-authored-by: grandizzy <[email protected]>
  • Loading branch information
klkvr and grandizzy authored Oct 3, 2024
1 parent 471e4ac commit ecf37f2
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 11 deletions.
21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ foundry-linking = { path = "crates/linking" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.7.3", default-features = false }
foundry-compilers = { version = "0.11.3", default-features = false }
foundry-compilers = { version = "0.11.4", default-features = false }
foundry-fork-db = "0.4.0"
solang-parser = "=0.3.3"

Expand Down
13 changes: 13 additions & 0 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ pub struct CoreBuildArgs {
#[serde(skip_serializing_if = "Option::is_none")]
pub build_info_path: Option<PathBuf>,

/// Use EOF-enabled solc binary. Enables via-ir and sets EVM version to Prague. Requires Docker
/// to be installed.
///
/// Note that this is a temporary solution until the EOF support is merged into the main solc
/// release.
#[arg(long)]
#[serde(skip)]
pub eof: bool,

/// Skip building files whose names contain the given filter.
///
/// `test` and `script` are aliases for `.t.sol` and `.s.sol`.
Expand Down Expand Up @@ -277,6 +286,10 @@ impl Provider for CoreBuildArgs {
dict.insert("revert_strings".to_string(), revert.to_string().into());
}

if self.eof {
dict.insert("eof".to_string(), true.into());
}

Ok(Map::from([(Config::selected_profile(), dict)]))
}
}
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ toml = { version = "0.8", features = ["preserve_order"] }
toml_edit = "0.22.4"
tracing.workspace = true
walkdir.workspace = true
yansi.workspace = true

[target.'cfg(target_os = "windows")'.dependencies]
path-slash = "0.2.1"
Expand Down
61 changes: 61 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ use std::{
fs,
path::{Path, PathBuf},
str::FromStr,
sync::mpsc::{self, RecvTimeoutError},
time::Duration,
};

mod macros;
Expand Down Expand Up @@ -466,6 +468,9 @@ pub struct Config {
/// Timeout for transactions in seconds.
pub transaction_timeout: u64,

/// Use EOF-enabled solc for compilation.
pub eof: bool,

/// Warnings gathered when loading the Config. See [`WarningsProvider`] for more information
#[serde(rename = "__warnings", default, skip_serializing)]
pub warnings: Vec<Warning>,
Expand Down Expand Up @@ -530,6 +535,9 @@ impl Config {
/// Default salt for create2 library deployments
pub const DEFAULT_CREATE2_LIBRARY_SALT: FixedBytes<32> = FixedBytes::<32>::ZERO;

/// Docker image with eof-enabled solc binary
pub const EOF_SOLC_IMAGE: &'static str = "ghcr.io/paradigmxyz/forge-eof@sha256:46f868ce5264e1190881a3a335d41d7f42d6f26ed20b0c823609c715e38d603f";

/// Returns the current `Config`
///
/// See [`figment`](Self::figment) for more details.
Expand Down Expand Up @@ -786,6 +794,8 @@ impl Config {
config.libs.sort_unstable();
config.libs.dedup();

config.sanitize_eof_settings();

config
}

Expand All @@ -803,6 +813,22 @@ impl Config {
}
}

/// Adjusts settings if EOF compilation is enabled.
///
/// This includes enabling via_ir, eof_version and ensuring that evm_version is not lower than
/// Prague.
pub fn sanitize_eof_settings(&mut self) {
if self.eof {
self.via_ir = true;
if self.eof_version.is_none() {
self.eof_version = Some(EofVersion::V1);
}
if self.evm_version < EvmVersion::Prague {
self.evm_version = EvmVersion::Prague;
}
}
}

/// Returns the directory in which dependencies should be installed
///
/// Returns the first dir from `libs` that is not `node_modules` or `lib` if `libs` is empty
Expand Down Expand Up @@ -904,6 +930,40 @@ impl Config {
///
/// If `solc` is [`SolcReq::Local`] then this will ensure that the path exists.
fn ensure_solc(&self) -> Result<Option<Solc>, SolcError> {
if self.eof {
let (tx, rx) = mpsc::channel();
let root = self.root.0.clone();
std::thread::spawn(move || {
tx.send(
Solc::new_with_args(
"docker",
[
"run",
"--rm",
"-i",
"-v",
&format!("{}:/app/root", root.display()),
Self::EOF_SOLC_IMAGE,
],
)
.map(Some),
)
});
// If it takes more than 1 second, this likely means we are pulling the image.
return match rx.recv_timeout(Duration::from_secs(1)) {
Ok(res) => res,
Err(RecvTimeoutError::Timeout) => {
eprintln!(
"{}",
yansi::Paint::yellow(
"Pulling Docker image for eof-solc, this might take some time..."
)
);
rx.recv().expect("sender dropped")
}
Err(RecvTimeoutError::Disconnected) => panic!("sender dropped"),
}
}
if let Some(ref solc) = self.solc {
let solc = match solc {
SolcReq::Version(version) => {
Expand Down Expand Up @@ -2191,6 +2251,7 @@ impl Default for Config {
eof_version: None,
alphanet: false,
transaction_timeout: 120,
eof: false,
_non_exhaustive: (),
}
}
Expand Down
19 changes: 19 additions & 0 deletions crates/forge/tests/cli/alphanet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Ensure we can run basic counter tests with EOF support.
#[cfg(not(windows))]
forgetest_init!(test_eof_flag, |prj, cmd| {
cmd.forge_fuse().args(["test", "--eof"]).assert_success().stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful with warnings:
Warning (3805): This is a pre-release compiler version, please do not use it in production.
Ran 2 tests for test/Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, [AVG_GAS])
[PASS] test_Increment() ([GAS])
Suite result: ok. 2 passed; 0 failed; 0 skipped; [ELAPSED]
Ran 1 test suite [ELAPSED]: 2 tests passed, 0 failed, 0 skipped (2 total tests)
"#]]);
});
1 change: 1 addition & 0 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ forgetest!(can_extract_config_values, |prj, cmd| {
eof_version: None,
alphanet: false,
transaction_timeout: 120,
eof: false,
_non_exhaustive: (),
};
prj.write_config(input.clone());
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate foundry_test_utils;
pub mod constants;
pub mod utils;

mod alphanet;
mod bind_json;
mod build;
mod cache;
Expand Down

0 comments on commit ecf37f2

Please sign in to comment.