Skip to content

Hardhat-compatible artifacts (directory structure) #1573

Open
@naps62

Description

@naps62

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: subvisual/citizend#149

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions