Skip to content

Conversation

@klkvr
Copy link
Member

@klkvr klkvr commented Jul 16, 2024

This adds CompilerSettings::Restrictions associated type which allows configuring constraints for compilation settings. Those constraints can be checked against a settings object and merged.

Ideally given a set of constraints we'd be able to automatically resolve configurations given only basic (default) config, though I think we can do this in follow-up. Current implementation requires user to provide us with concrete profiles such that for each defined constraint at least one of the profiles matches it. This should be enough for most of the usecases for now.

Profile to use is resolved in Graph similarly to version resolution.

The way this could look in foundry.toml is:

[profile.default]
# by default no via-ir and evm version is paris for everything
evm_version = "paris"
via_ir = false

# add cancun profile and via_ir profiles
additional_compiler_profiles = [{ evm_version = "cancun" }, {via_ir = true} ]

# enforce compiling some contracts with cancun, and some with via-ir
# if those contracts are imported by some items in the project, constraints will apply as well
compilation_constraints = [{path = "./**/*.cancun.sol", min_evm_version = "cancun" }, {path = "SomeComplexFile.sol", via_ir = true }] 

When writing artifacts, a profile name is added to artifact file name if the same contract was compiled with multiple artifacts.

@klkvr klkvr force-pushed the klkvr/settings-profiles branch from 9d6a8b8 to 2e82dc5 Compare September 10, 2024 16:19
@klkvr klkvr force-pushed the klkvr/settings-profiles branch from 2e82dc5 to 1b80617 Compare September 23, 2024 18:08
@klkvr klkvr force-pushed the klkvr/settings-profiles branch from 1b80617 to 5b42d05 Compare November 6, 2024 00:26
@klkvr klkvr force-pushed the klkvr/settings-profiles branch 2 times, most recently from 0c2f7d8 to 26a2657 Compare November 6, 2024 02:20
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this makes sense,
was able to follow, but could use some additional docs

Comment on lines 8 to 10
pub trait CompilerSettingsRestrictions: Copy + Debug + Sync + Send + Clone + Default {
fn merge(self, other: Self) -> Option<Self>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs docs

@klkvr klkvr marked this pull request as ready for review November 7, 2024 20:53
@klkvr klkvr requested a review from DaniPopes as a code owner November 7, 2024 20:53
@klkvr klkvr changed the title [wip] feat: allow multiple compiler configs feat: allow multiple compiler configs Nov 7, 2024
@klkvr klkvr requested a review from mattsse November 7, 2024 20:59
@klkvr klkvr self-assigned this Nov 11, 2024
@klkvr klkvr merged commit b5c2a49 into main Nov 15, 2024
2 of 15 checks passed
@DaniPopes DaniPopes deleted the klkvr/settings-profiles branch November 15, 2024 19:14
@KevinSmall
Copy link

KevinSmall commented Sep 19, 2025

In case anyone googles for this feature, and lands here, the syntax given in this post is no longer correct, and silently does nothing. The correct syntax is given here: foundry-rs/foundry#8668

This post, wrong syntax:

compilation_constraints = [{path = 

Correct syntax:

compilation_restrictions = [{ paths =

Definitely some docs would be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

4 participants