Skip to content

Commit 3784cd8

Browse files
elfedyklkvr
andauthored
refactor: adapt to CompilerContract trait type (#9423)
* refactor: adapt to CompilerContract trait type * chore: cargo fmt * fix: specify MultiCompiler in MultiContractRunner::build * bump * fix --------- Co-authored-by: Arsenii Kulikov <[email protected]>
1 parent 25c978a commit 3784cd8

File tree

12 files changed

+66
-42
lines changed

12 files changed

+66
-42
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ foundry-linking = { path = "crates/linking" }
169169

170170
# solc & compilation utilities
171171
foundry-block-explorers = { version = "0.9.0", default-features = false }
172-
foundry-compilers = { version = "0.12.3", default-features = false }
172+
foundry-compilers = { version = "0.12.5", default-features = false }
173173
foundry-fork-db = "0.8.0"
174174
solang-parser = "=0.3.3"
175175
solar-ast = { version = "=0.1.0", default-features = false }

crates/cast/bin/cmd/storage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use foundry_common::{
2020
shell,
2121
};
2222
use foundry_compilers::{
23-
artifacts::{ConfigurableContractArtifact, StorageLayout},
23+
artifacts::{ConfigurableContractArtifact, Contract, StorageLayout},
2424
compilers::{
2525
solc::{Solc, SolcCompiler},
2626
Compiler,
@@ -284,7 +284,7 @@ fn print_storage(layout: StorageLayout, values: Vec<StorageValue>, pretty: bool)
284284
"{}",
285285
serde_json::to_string_pretty(&serde_json::to_value(StorageReport { layout, values })?)?
286286
)?;
287-
return Ok(())
287+
return Ok(());
288288
}
289289

290290
let mut table = Table::new();
@@ -314,7 +314,7 @@ fn print_storage(layout: StorageLayout, values: Vec<StorageValue>, pretty: bool)
314314
Ok(())
315315
}
316316

317-
fn add_storage_layout_output<C: Compiler>(project: &mut Project<C>) {
317+
fn add_storage_layout_output<C: Compiler<CompilerContract = Contract>>(project: &mut Project<C>) {
318318
project.artifacts.additional_values.storage_layout = true;
319319
project.update_output_selection(|selection| {
320320
selection.0.values_mut().for_each(|contract_selection| {

crates/common/src/compile.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use comfy_table::{presets::ASCII_MARKDOWN, Attribute, Cell, CellAlignment, Color
1010
use eyre::Result;
1111
use foundry_block_explorers::contract::Metadata;
1212
use foundry_compilers::{
13-
artifacts::{remappings::Remapping, BytecodeObject, Source},
13+
artifacts::{remappings::Remapping, BytecodeObject, Contract, Source},
1414
compilers::{
1515
solc::{Solc, SolcCompiler},
1616
Compiler,
@@ -129,7 +129,10 @@ impl ProjectCompiler {
129129
}
130130

131131
/// Compiles the project.
132-
pub fn compile<C: Compiler>(mut self, project: &Project<C>) -> Result<ProjectCompileOutput<C>> {
132+
pub fn compile<C: Compiler<CompilerContract = Contract>>(
133+
mut self,
134+
project: &Project<C>,
135+
) -> Result<ProjectCompileOutput<C>> {
133136
// TODO: Avoid process::exit
134137
if !project.paths.has_input_files() && self.files.is_empty() {
135138
sh_println!("Nothing to compile")?;
@@ -163,7 +166,10 @@ impl ProjectCompiler {
163166
/// ProjectCompiler::new().compile_with(|| Ok(prj.compile()?)).unwrap();
164167
/// ```
165168
#[instrument(target = "forge::compile", skip_all)]
166-
fn compile_with<C: Compiler, F>(self, f: F) -> Result<ProjectCompileOutput<C>>
169+
fn compile_with<C: Compiler<CompilerContract = Contract>, F>(
170+
self,
171+
f: F,
172+
) -> Result<ProjectCompileOutput<C>>
167173
where
168174
F: FnOnce() -> Result<ProjectCompileOutput<C>>,
169175
{
@@ -202,7 +208,10 @@ impl ProjectCompiler {
202208
}
203209

204210
/// If configured, this will print sizes or names
205-
fn handle_output<C: Compiler>(&self, output: &ProjectCompileOutput<C>) {
211+
fn handle_output<C: Compiler<CompilerContract = Contract>>(
212+
&self,
213+
output: &ProjectCompileOutput<C>,
214+
) {
206215
let print_names = self.print_names.unwrap_or(false);
207216
let print_sizes = self.print_sizes.unwrap_or(false);
208217

@@ -465,7 +474,7 @@ pub struct ContractInfo {
465474
/// If `verify` and it's a standalone script, throw error. Only allowed for projects.
466475
///
467476
/// **Note:** this expects the `target_path` to be absolute
468-
pub fn compile_target<C: Compiler>(
477+
pub fn compile_target<C: Compiler<CompilerContract = Contract>>(
469478
target_path: &Path,
470479
project: &Project<C>,
471480
quiet: bool,

crates/config/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use foundry_compilers::{
3535
error::SolcError,
3636
multi::{MultiCompilerParsedSource, MultiCompilerRestrictions},
3737
solc::{CliSettings, SolcSettings},
38-
ConfigurableArtifacts, Graph, Project, ProjectPathsConfig, RestrictionsWithVersion,
39-
VyperLanguage,
38+
ArtifactOutput, ConfigurableArtifacts, Graph, Project, ProjectPathsConfig,
39+
RestrictionsWithVersion, VyperLanguage,
4040
};
4141
use regex::Regex;
4242
use revm_primitives::{map::AddressHashMap, FixedBytes, SpecId};
@@ -1021,7 +1021,10 @@ impl Config {
10211021
}
10221022

10231023
/// Cleans the project.
1024-
pub fn cleanup<C: Compiler>(&self, project: &Project<C>) -> Result<(), SolcError> {
1024+
pub fn cleanup<C: Compiler, T: ArtifactOutput<CompilerContract = C::CompilerContract>>(
1025+
&self,
1026+
project: &Project<C, T>,
1027+
) -> Result<(), SolcError> {
10251028
project.cleanup()?;
10261029

10271030
// Remove last test run failures file.
@@ -1090,7 +1093,7 @@ impl Config {
10901093
rx.recv().expect("sender dropped")
10911094
}
10921095
Err(RecvTimeoutError::Disconnected) => panic!("sender dropped"),
1093-
}
1096+
};
10941097
}
10951098
if let Some(ref solc) = self.solc {
10961099
let solc = match solc {
@@ -1291,11 +1294,11 @@ impl Config {
12911294
) -> Option<Result<Cow<'_, str>, UnresolvedEnvVarError>> {
12921295
let mut endpoints = self.rpc_endpoints.clone().resolved();
12931296
if let Some(endpoint) = endpoints.remove(maybe_alias) {
1294-
return Some(endpoint.map(Cow::Owned))
1297+
return Some(endpoint.map(Cow::Owned));
12951298
}
12961299

12971300
if let Ok(Some(endpoint)) = mesc::get_endpoint_by_query(maybe_alias, Some("foundry")) {
1298-
return Some(Ok(Cow::Owned(endpoint.url)))
1301+
return Some(Ok(Cow::Owned(endpoint.url)));
12991302
}
13001303

13011304
None

crates/evm/traces/src/debug/sources.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use foundry_common::compact_to_contract;
33
use foundry_compilers::{
44
artifacts::{
55
sourcemap::{SourceElement, SourceMap},
6-
Bytecode, ContractBytecodeSome, Libraries, Source,
6+
Bytecode, Contract, ContractBytecodeSome, Libraries, Source,
77
},
88
multi::MultiCompilerLanguage,
99
Artifact, Compiler, ProjectCompileOutput,
@@ -137,7 +137,7 @@ impl ContractSources {
137137
Ok(sources)
138138
}
139139

140-
pub fn insert<C: Compiler>(
140+
pub fn insert<C: Compiler<CompilerContract = Contract>>(
141141
&mut self,
142142
output: &ProjectCompileOutput<C>,
143143
root: &Path,

crates/forge/bin/cmd/clone.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl CloneArgs {
266266
let remappings_txt_content =
267267
config.remappings.iter().map(|r| r.to_string()).collect::<Vec<_>>().join("\n");
268268
if fs::write(&remappings_txt, remappings_txt_content).is_err() {
269-
return false
269+
return false;
270270
}
271271

272272
let profile = config.profile.as_str().as_str();
@@ -612,7 +612,7 @@ impl EtherscanClient for Client {
612612
mod tests {
613613
use super::*;
614614
use alloy_primitives::hex;
615-
use foundry_compilers::Artifact;
615+
use foundry_compilers::CompilerContract;
616616
use foundry_test_utils::rpc::next_mainnet_etherscan_api_key;
617617
use std::collections::BTreeMap;
618618

@@ -631,7 +631,7 @@ mod tests {
631631
contracts.iter().for_each(|(name, contract)| {
632632
if name == contract_name {
633633
let compiled_creation_code =
634-
contract.get_bytecode_object().expect("creation code not found");
634+
contract.bin_ref().expect("creation code not found");
635635
assert!(
636636
hex::encode(compiled_creation_code.as_ref())
637637
.starts_with(stripped_creation_code),

crates/forge/bin/cmd/coverage.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use foundry_compilers::{
1919
artifacts::{
2020
sourcemap::SourceMap, CompactBytecode, CompactDeployedBytecode, SolcLanguage, Source,
2121
},
22+
compilers::multi::MultiCompiler,
2223
Artifact, ArtifactId, Project, ProjectCompileOutput,
2324
};
2425
use foundry_config::{Config, SolcReq};
@@ -245,7 +246,7 @@ impl CoverageArgs {
245246
.sender(evm_opts.sender)
246247
.with_fork(evm_opts.get_fork(&config, env.clone()))
247248
.set_coverage(true)
248-
.build(&root, output, env, evm_opts)?;
249+
.build::<MultiCompiler>(&root, output, env, evm_opts)?;
249250

250251
let known_contracts = runner.known_contracts.clone();
251252

crates/forge/bin/cmd/test/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ use foundry_cli::{
2323
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs, shell, TestFunctionExt};
2424
use foundry_compilers::{
2525
artifacts::output_selection::OutputSelection,
26-
compilers::{multi::MultiCompilerLanguage, Language},
26+
compilers::{
27+
multi::{MultiCompiler, MultiCompilerLanguage},
28+
Language,
29+
},
2730
utils::source_files_iter,
2831
ProjectCompileOutput,
2932
};
@@ -353,7 +356,7 @@ impl TestArgs {
353356
.with_fork(evm_opts.get_fork(&config, env.clone()))
354357
.enable_isolation(evm_opts.isolate)
355358
.alphanet(evm_opts.alphanet)
356-
.build(project_root, &output, env, evm_opts)?;
359+
.build::<MultiCompiler>(project_root, &output, env, evm_opts)?;
357360

358361
let mut maybe_override_mt = |flag, maybe_regex: Option<&Option<Regex>>| {
359362
if let Some(Some(regex)) = maybe_regex {

crates/forge/src/multi_runner.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use alloy_json_abi::{Function, JsonAbi};
88
use alloy_primitives::{Address, Bytes, U256};
99
use eyre::Result;
1010
use foundry_common::{get_contract_name, shell::verbosity, ContractsByArtifact, TestFunctionExt};
11-
use foundry_compilers::{artifacts::Libraries, Artifact, ArtifactId, ProjectCompileOutput};
11+
use foundry_compilers::{
12+
artifacts::{Contract, Libraries},
13+
compilers::Compiler,
14+
Artifact, ArtifactId, ProjectCompileOutput,
15+
};
1216
use foundry_config::{Config, InlineConfig};
1317
use foundry_evm::{
1418
backend::Backend,
@@ -457,7 +461,7 @@ impl MultiContractRunnerBuilder {
457461

458462
/// Given an EVM, proceeds to return a runner which is able to execute all tests
459463
/// against that evm
460-
pub fn build(
464+
pub fn build<C: Compiler<CompilerContract = Contract>>(
461465
self,
462466
root: &Path,
463467
output: &ProjectCompileOutput,

0 commit comments

Comments
 (0)