Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] preprocessor for speeding up compilation #8891

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,5 @@ alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "511ae9
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
revm = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }

foundry-compilers = { git = "https://github.com/foundry-rs/compilers", rev = "a379db3" }
13 changes: 11 additions & 2 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use foundry_compilers::{
solc::{Solc, SolcCompiler},
Compiler,
},
preprocessor::{TestOptimizerPreprocessor},
project::Preprocessor,
report::{BasicStdoutReporter, NoReporter, Report},
solc::SolcSettings,
Artifact, Project, ProjectBuilder, ProjectCompileOutput, ProjectPathsConfig, SolcConfig,
Expand Down Expand Up @@ -122,7 +124,10 @@ impl ProjectCompiler {
}

/// Compiles the project.
pub fn compile<C: Compiler>(mut self, project: &Project<C>) -> Result<ProjectCompileOutput<C>> {
pub fn compile<C: Compiler>(mut self, project: &Project<C>) -> Result<ProjectCompileOutput<C>>
where
TestOptimizerPreprocessor: Preprocessor<C>,
{
// TODO: Avoid process::exit
if !project.paths.has_input_files() && self.files.is_empty() {
println!("Nothing to compile");
Expand All @@ -140,6 +145,7 @@ impl ProjectCompiler {
};

foundry_compilers::project::ProjectCompiler::with_sources(project, sources)?
.with_preprocessor(TestOptimizerPreprocessor)
.compile()
.map_err(Into::into)
})
Expand Down Expand Up @@ -361,7 +367,10 @@ pub fn compile_target<C: Compiler>(
target_path: &Path,
project: &Project<C>,
quiet: bool,
) -> Result<ProjectCompileOutput<C>> {
) -> Result<ProjectCompileOutput<C>>
where
TestOptimizerPreprocessor: Preprocessor<C>,
{
ProjectCompiler::new().quiet(quiet).files([target_path.into()]).compile(project)
}

Expand Down