foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(forge): add solc subcommand and utilities

Open jpgonzalezra opened this issue 9 months ago • 2 comments

Motivation

The "issue 7654" it is proposed to add a new command, forge detect-solc (in this PR "forge solc vr" or "forge solc version-resolving"), which returns the detected version of the Solidity compiler based on the project configuration. This command aims to help users identify compatible versions of the Solidity compiler for different folders in large projects by providing insights into the version resolution algorithm used.

Solution

Added a solc command with the subcommand version-resolving, which retrieves the resolved versions of the Solidity compiler (solc) within the project using the SolcVersionManager from the foundry_compilers library.

  • Ex. with solmate project
$ forge solc vr 

Screenshot 2024-05-11 at 18 40 24

jpgonzalezra avatar May 11 '24 22:05 jpgonzalezra

Support for the --skip flag that forge build has would be really nice to allow filtering out directories from the results. When I test this, the output is dominated by e.g. lib/ and test/ files that obscure the src/ files of interest (not a blocker for this PR, can be done in a follow up)

mds1 avatar May 13 '24 13:05 mds1

Thanks for the comments, I can add support for the --skip flag in this PR or another one. And maybe we can add --silent to only print the version, something link:

one version:

  • 0.8.15

More than one:

  • 0.8.15
  • 0.8.25

What do you think guys?

jpgonzalezra avatar May 13 '24 13:05 jpgonzalezra

Hi @jpgonzalezra thanks for the PR! Would be great to get this ready to be merged

I support adding the --skip flag to this PR. Perhaps rather than --silent it makes sense to add different levels of verbosity for the logs that are emitted where the lowest level yields:

  • 0.8.15
  • 0.8.25

And higher levels of verbosity as proposed by you:

- 0.8.15
  - <path>
  - <path>
  - <path>

- 0.8.25
  - <path>
  - <path>
  - <path>

zerosnacks avatar Jul 15 '24 12:07 zerosnacks

@zerosnacks Awesome, I'll fix the conflicts so we can merge. If we want to add anything else, I'll do it in a separate PR. What do you think?

jpgonzalezra avatar Jul 15 '24 13:07 jpgonzalezra

@zerosnacks Awesome, I'll fix the conflicts so we can merge. If we want to add anything else, I'll do it in a separate PR. What do you think?

Great, we can do this as follow ups - not a blocker for me for this PR

zerosnacks avatar Jul 15 '24 13:07 zerosnacks

@zerosnacks I need to make some changes to the PR because there have been significant updates in the compilers repository. See this commit: https://github.com/foundry-rs/compilers/commit/c78e2eacf7db7e571ffacb1f7bb41533decf4581. I believe I need to use the "detect_version" function. I'll work on that. 💪

jpgonzalezra avatar Jul 15 '24 15:07 jpgonzalezra

Thanks @jpgonzalezra! Let me know if you run into any problems

zerosnacks avatar Jul 31 '24 11:07 zerosnacks

@jpgonzalezra friendly bump here. Do you still have the bandwidth to complete this?

yash-atreya avatar Sep 12 '24 07:09 yash-atreya

Would it make sense to generalize this to forge compiler --list?

zerosnacks avatar Sep 12 '24 12:09 zerosnacks

Pending next release of https://github.com/foundry-rs/compilers as it required minor changes upstream to test multi-compiler mode, specifically Vyper.

Command name updated to forge compiler resolve

Updated PR with compiler updates, added JSON compatibility, added verbose / non-verbose mode and added skip flag.

Apart from this blocker, ready for review

zerosnacks avatar Oct 14 '24 13:10 zerosnacks

cc @grandizzy would you mind doing a final review before merging?

zerosnacks avatar Oct 16 '24 11:10 zerosnacks

Like the max supported version by compiler?

DaniPopes avatar Oct 16 '24 12:10 DaniPopes

wonder if it would be useful to add evm version too at some point

like the max supported version by compiler?

Added a follow-up ticket here: https://github.com/foundry-rs/foundry/issues/9125

zerosnacks avatar Oct 16 '24 12:10 zerosnacks