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

feat(forge compile): print compiled contract names #682

Merged
merged 5 commits into from
Mar 1, 2022

Conversation

tynes
Copy link
Contributor

@tynes tynes commented Feb 6, 2022

Motivation

I want to know which contracts were compiled when running
forge build and the compiler version that was used.

Solution

Print the names of the compiled contracts after
running forge compile. Its useful to know which
contracts were compiled and the compiler version
that was used.

The output looks like this:

$ forge build --hardhat --names --sizes

compiling...
Compiling 1 files with 0.5.17
Compiling 79 files with 0.8.11
Compilation finished successfully
Compilation finished successfully
compiled contracts:
  compiler version: 0.5.17
    - WETH9
  compiler version: 0.8.11
    - AddressDictator
    - ChugSplashDictator
    - IL1CrossDomainMessenger
    - IL1ERC20Bridge
    - IL1StandardBridge
    - L1CrossDomainMessenger
    - L1StandardBridge
    - CanonicalTransactionChain
    - ChainStorageContainer
    - ICanonicalTransactionChain
    - IChainStorageContainer
    - IStateCommitmentChain
    - StateCommitmentChain
    - TeleportrDeposit
    - BondManager
    - IBondManager
    - IL2CrossDomainMessenger
    - IL2ERC20Bridge
    - L2CrossDomainMessenger
    - L2StandardBridge
    - L2StandardTokenFactory
    - OVM_DeployerWhitelist
... <more contracts, removed for brevity>
name             size (bytes)
-----------------------------
Address              141
AddressAliasHelper   141
AddressDictator      2926
BondManager          940
CanonicalTransactionChain 5689
ChainStorageContainer 3220
ChugSplashDictator   1733
Context              0
ContextUpgradeable   0
CrossDomainEnabled   291
ERC165Checker        141
ERC20                2902
FailingReceiver      159
Helper_SimpleProxy   595
IBondManager         0
ICanonicalTransactionChain 0
IChainStorageContainer 0
ICrossDomainMessenger 0
IERC165              0
IERC20               0
IERC20Metadata       0
IL1CrossDomainMessenger 0
IL1ERC20Bridge       0
IL1StandardBridge    0
IL2CrossDomainMessenger 0
IL2ERC20Bridge       0
IL2StandardERC20     0
IStateCommitmentChain 0
Initializable        0
L1ChugSplashProxy    2065
L1CrossDomainMessenger 12799
L1StandardBridge     5179
L2CrossDomainMessenger 2524
L2StandardBridge     3383
L2StandardERC20      4275
L2StandardTokenFactory 5115
Lib_AddressManager   1444
Lib_AddressResolver  0
Lib_Buffer           141
Lib_Bytes32Utils     141
Lib_BytesUtils       141
Lib_CrossDomainUtils 141
Lib_DefaultValues    141
Lib_MerkleTree       141
Lib_MerkleTrie       141
Lib_OVMCodec         141
Lib_PredeployAddresses 141
Lib_RLPReader        141
Lib_RLPWriter        141
Lib_ResolvedDelegateProxy 1262
Lib_SecureMerkleTrie 141
OVM_DeployerWhitelist 1196
OVM_ETH              3404
OVM_GasPriceOracle   2718
OVM_L2ToL1MessagePasser 610
OVM_SequencerFeeVault 843
Ownable              0
OwnableUpgradeable   0
PausableUpgradeable  0
ReentrancyGuardUpgradeable 0
SafeERC20            141
StateCommitmentChain 7274
TeleportrDeposit     2160
TeleportrDisburser   1964
TestERC20            1522
TestLib_AddressAliasHelper 307
TestLib_Buffer       1330
TestLib_Bytes32Utils 483
TestLib_BytesUtils   3904
TestLib_CrossDomainUtils 743
TestLib_MerkleTree   2853
TestLib_MerkleTrie   11208
TestLib_OVMCodec     1016
TestLib_RLPReader    3808
TestLib_RLPWriter    4784
TestLib_SecureMerkleTrie 11363
WETH9                2055
iL1ChugSplashDeployer 0
iOVM_L1BlockNumber   0
iOVM_L2ToL1MessagePasser 0
success.

Not sure how much I like the output of --sizes when using foundry_utils::to_table. I think iterating and printing similarly to --names could look better. Thoughts?

cli/src/cmd/mod.rs Outdated Show resolved Hide resolved
@onbjerg
Copy link
Member

onbjerg commented Feb 6, 2022

Related: #588

@gakonst
Copy link
Member

gakonst commented Feb 6, 2022

Supportive of table view + forge size + forge build --size. Would be enough to close 588

@onbjerg onbjerg added the T-feature Type: feature label Feb 7, 2022
@gakonst gakonst force-pushed the master branch 2 times, most recently from dd690ab to bc613e1 Compare February 9, 2022 11:48
@mattsse
Copy link
Member

mattsse commented Feb 9, 2022

@tynes fyi, you can now subscribe to the socl CompilerOutput ref gakonst/ethers-rs#883
and #707

@tynes tynes force-pushed the feat/compile-info branch from b88a9c1 to 25b41b2 Compare February 11, 2022 05:05
@tynes tynes changed the title feat(forge compile): print metadata feat(forge compile): print compiled contract names Feb 11, 2022
@tynes
Copy link
Contributor Author

tynes commented Feb 11, 2022

Supportive of table view + forge size + forge build --size. Would be enough to close 588

I've updated this PR to only print the names of contracts that were compiled + the compiler version for simplicity, since that seems like the lower hanging feature for now. Do you still want this to be behind a flag?

@tynes tynes force-pushed the feat/compile-info branch from 25b41b2 to 236108b Compare February 11, 2022 05:13
@tynes tynes marked this pull request as ready for review February 11, 2022 05:24
cli/src/cmd/mod.rs Outdated Show resolved Hide resolved
cli/src/cmd/mod.rs Outdated Show resolved Hide resolved
@gakonst
Copy link
Member

gakonst commented Feb 11, 2022

Yep let's always have this behind a flag if possible @tynes?

@tynes
Copy link
Contributor Author

tynes commented Feb 11, 2022

Yep let's always have this behind a flag if possible @tynes?

Will add it behind a flag, thinking -v? Then it will follow the same pattern with the logs and in the future -vv or -vvv could be added if desired

@gakonst
Copy link
Member

gakonst commented Feb 11, 2022

Yeah -v sounds good to me. Will it not conflict with forge test -v? How would I e.g. show traces when forge test -vvvv but not show all the contracts being compiled?

@mattsse
Copy link
Member

mattsse commented Feb 12, 2022

Yeah -v sounds good to me. Will it not conflict with forge test -v? How would I e.g. show traces when forge test -vvvv but not show all the contracts being compiled?

right, this will conflict since test also includes a verbosity flag and uses flattened BuildArgs.

hmm this is a bit tricky, we could change the actual build command to

struct Build {
    #[clap(flatten)]
    opts: BuildArgs,
    verbosity: u8

so that build and test have separate verbosity flags, but then the question is should we print build info in forge test -v?

or we use a different flag?

I'd lean towards also printing build info with forge test -v, we could add another option in forge test though so that we expect -vvvvv for it to also set verbose build, which is perhaps over engineering.

@gakonst
Copy link
Member

gakonst commented Feb 14, 2022

@tynes think we have all the helper functions in, so can move this PR forward?

@tynes
Copy link
Contributor Author

tynes commented Feb 15, 2022

@tynes think we have all the helper functions in, so can move this PR forward?

Definitely, I have some changes locally but have been bikeshedding on the exact flag to use for printing this information. I'm currently leaning towards a new flag that isn't -v so it doesn't conflict with -v for forge test. What do you think?

@gakonst
Copy link
Member

gakonst commented Feb 15, 2022

Ah I see. What about --names for this feature, and --sizes for the contract sizes table?

@tynes
Copy link
Contributor Author

tynes commented Feb 15, 2022

Ah I see. What about --names for this feature, and --sizes for the contract sizes table?

Sounds good to me, will use this for the table:
https://github.com/gakonst/foundry/blob/31e4a9d3a3f33e1865a2d1169a0538bc96eee797/utils/src/lib.rs#L309

@gakonst
Copy link
Member

gakonst commented Feb 18, 2022

@tynes wanna push over your local changes? I'm happy to help to get this PR over the line today

Print the names of the compiled contracts after
running `forge compile`. Its useful to know which
contracts were compiled and the compiler version
that was used.

The output looks like this:

```bash
$ forge build --hardhat

compiling...
compiled contracts:
compiler version: 0.5.17+commit.d19bba13.Linux.gcc
  - WETH9
compiler version: 0.8.11+commit.d7f03943.Linux.gcc
  - AddressDictator
  - ChugSplashDictator
  - IL1CrossDomainMessenger
  - IL1ERC20Bridge
  - IL1StandardBridge
  - L1CrossDomainMessenger
  - L1StandardBridge
  - CanonicalTransactionChain
  - ChainStorageContainer
  - ICanonicalTransactionChain
  - IChainStorageContainer
  - IStateCommitmentChain
  - StateCommitmentChain
success.
```
@tynes tynes force-pushed the feat/compile-info branch from 236108b to 256561d Compare February 23, 2022 18:51
for (_, contracts) in compiled_contracts.into_iter() {
for (name, contract) in contracts {
let bytecode: CompactContractBytecode = contract.into();
let size = if let Some(code) = bytecode.bytecode {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to always be 0 for libraries

}
}
if print_sizes {
let compiled_contracts = output.compiled_contracts_by_compiler_version();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code could be modularized and reused in the future for foundry sizes

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

Successfully merging this pull request may close these issues.

4 participants