Skip to content

Added via_ir Detection for Foundry Projects in Ape #2572

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shwetd19
Copy link

Description

This PR fixes issue #2564 , where Ape’s FoundryProject class does not detect the via_ir setting from Foundry’s foundry.toml configuration file.

The change updates the _parse_solidity_config method in src/ape_pm/project.py to read the via_ir key and include it in the Solidity compiler configuration as viaIR. This ensures Ape respects Foundry’s via_ir setting during compilation, aligning with Foundry’s behavior.

Changes Made

  • Modified FoundryProject._parse_solidity_config in src/ape_pm/project.py to check for via_ir in the parsed foundry.toml data.
  • Added via_ir to the sol_cfg dictionary as "viaIR": via_ir when present, preserving existing logic for other settings (version, evm_version, remappings).
  • While ensuring safe handling of missing via_ir keys using data.get("via_ir").

Testing

  • Created a test Foundry project with:

    [profile.default]
    via_ir = true

    in foundry.toml.

  • Ran ape compile to verify that the compiler applies the viaIR pipeline (confirmed via compiler output).

  • Tested with via_ir absent to ensure no unintended side effects.

  • [Optional] Added a unit test in tests/test_foundry_project.py to validate via_ir detection.


Thank you for considering this contribution! 🚀

Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

please also edit this test and the foundry_toml fixture to include the new value

@@ -266,6 +266,9 @@ def _parse_solidity_config(
if evm_version := data.get("evm_version"):
sol_cfg["evm_version"] = evm_version

if via_ir := data.get("via_ir"):
sol_cfg["viaIR"] = via_ir
Copy link
Member

@antazoey antazoey Apr 15, 2025

Choose a reason for hiding this comment

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

It is snake case: https://github.com/ApeWorX/ape-solidity/blob/main/ape_solidity/compiler.py#L142

Suggested change
sol_cfg["viaIR"] = via_ir
sol_cfg["via_ir"] = via_ir

note: we are not editing solidity directly but the ape-solidity plugin which handles it

@shwetd19
Copy link
Author

shwetd19 commented Apr 15, 2025

Hey @antazoey I did the change for via_ir and updated it but I'm not able to do the change for foundry_toml , pls help me out there

@antazoey
Copy link
Member

Hey @antazoey I did the change for via_ir and updated it but I'm not able to do the change for foundry_toml , pls help me out there

Right now, the foundry toml fixture looks like this:

(from tests/functional/test_project.py)

@pytest.fixture(scope="module")
def foundry_toml():
    return """
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
solc = "0.8.18"
evm_version = 'cancun'

remappings = [
    'forge-std/=lib/forge-std/src/',
    '@openzeppelin/=lib/openzeppelin-contracts/',
]
""".lstrip()

it is basically just the string version of a foundry TOML file, for configuring foundry. Foundry-based projects will have these (similar to how Ape has an ape-config.yaml).

The project API layer in Ape converts 1 config to another for the sake of successfully using dependencies that happen to be foundry projects, as well as being able to use ape command directly in a foundry project. Much of this integration needs work, so I appreciate you fixing the via_ir.

Anyway, you need to update this fixture to have via_ir = true, so we can test that our integration sucessfully reads and parses the value thanks to your change.

The via_ir field goes in the [profile.default] stanza, so you can plop it right under the evm_version part.

After this is done, head over to the TestFoundryProject::test_extract_config in the same module - add an assertion under the evm_version part like

assert actual_sol["via_ir"] is True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants