foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.34k stars 1.77k forks source link

Hardhat-compatible artifacts (directory structure) #1573

Open naps62 opened 2 years ago

naps62 commented 2 years ago

Component

Forge

Describe the feature you would like

Foundry has a hardhat-compatibility flag (which from my understanding, sets libs and src config values)

It also seems to detect existing hardhat projects. When calling forge init --force in an existing hardhat repo, I noticed it filled out those same configs as --hh would. But it also set out = 'artifacts', which is the directory used by hardhat.

When seeing that, I took it as having the ability to share compilation artifacts with hardhat. Which is a great thing to have, since it means I could do a single compilation, and run both forge test and hardhat test

However, the artifacts generated by foundry are apparently not compatible, due to the directory structure generated. It flattens all contracts into a subdir of artifacts, whereas hardhat mimics the structure of contracts

So for the following project:

root
|-- contracts
|   |-- libs
|   |   `-- MyLib.sol
|   `-- MyToken.sol
`-- node_modules
    `-- @openzeppelin

Hardhat would give me:

root
|-- artifacts
|   |-- contracts
|   |   |-- mylib
|   |   |   `-- MyLib.sol
|   |   `-- MyToken.sol
|   `-- @openzeppelin

but apparently foundry gives me:

root
|-- artifacts
|   |-- Context.sol
|   |-- ERC20.sol
|   |-- ...
|   |-- MyLib.sol
|   `-- MyToken.sol

Besides breaking the original expectation (which would be very cool to have, if possible), it also means that forge init --force actually creates a broken setup, since artifacts will end up duplicated inside the artifacts directory. If hardhat is using typechain to infer typings from those, compilation errors will be thrown due to all the duplicates

Additional context

This is the PR where I tried adding foundry to an existing project: https://github.com/subvisual/discoveryDAO/pull/149

I had to explicitly remove out = 'artifacts' due to the described issues. CI is currently set to run two independent compilations

onbjerg commented 2 years ago

Requires changes in ethers-solc

Since Foundry sort of supports Hardhat-style artifacts (read only, not all cases IIRC) we could have a config setting to choose artifact flavor.

See also https://github.com/foundry-rs/foundry/issues/73

mattsse commented 2 years ago

you might be interested in this https://github.com/foundry-rs/hardhat/pull/16 which bakes forge directly into hardhat and also uses an artifacts handler that's compatible with hardhat

onbjerg commented 2 years ago

@naps62 Let us know if using the Foundry Hardhat plugin solves this for you :)

naps62 commented 2 years ago

@onbjerg sorry for taking so long. I am mostly away from the project where this was an issue, so didn't have time to check until now. I'm still interested in figuring this out though, regardless of the project

So here's where I'm at: I tested that plugin. but maybe I misunderstood it's functionality, or didn't find some configuration I should add. Running hardhat test seems to now runs forge test only. What I actually wanted was to keep both test suites in place, but sharing compilation artifacts, so as not to cause conflicting artifacts, and to keep CI times where they are

hlauinfo commented 1 month ago

Seems like this was on the roadmap and then removed? I really don't want to go back to Hardhat at this point but there's legacy tooling that still utilizes HH artifact files so this would be a great add.