foundry-rs / foundry-rs/foundry
add option to `forge build` to only get the AST without compiling to bytecode
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 16h 38m
- Merged PRs (30d)
- 511
Description
### Component
Forge
### Describe the feature you would like
**UPDATE** see https://github.com/foundry-rs/foundry/issues/7212#issuecomment-2075291224
I would like the forge build command to expose [this](https://github.com/foundry-rs/compilers/blob/790e8e6921070d15cdf7dab89f90cb8f7aba7c19/src/artifacts/mod.rs#L270), so one can pass `--stop-after parsing` solc and only get the AST without compiling to bytecode
As a potential optimization, foundry could look if the solidity files' content is unchanged and reuse the AST on disk for compilation by giving them to solc when `forge build --stop-after parsing && forge build/test` is run.
### Additional context
from https://github.com/ethereum/solidity/blob/develop/docs/using-the-compiler.rst#compiler-input-and-output-json-description:
```
{
// If language is set to "SolidityAST", an AST needs to be supplied under the "ast" key
// and there can be only one source file present.
// The format is the same as used by the `ast` output.
// Note that importing ASTs is experimental and in particular that:
// - importing invalid ASTs can produce undefined results and
// - no proper error reporting is available on invalid ASTs.
// Furthermore, note that the AST import only consumes the fields of the AST as
// produced by the compiler in "stopAfter": "parsing" mode and then re-performs
// analysis, so any analysis-based annotations of the AST are ignored upon import.
"ast": { ... }
},
```
Contributor guide
Research direction
Start at the `forge build` command and read the referenced `src/artifacts/mod.rs` compiler option. Trace how compiler arguments and artifacts are handled, then determine how `--stop-after parsing` should expose the AST without bytecode compilation. Done means the command supports parsing-only output; AST reuse is an optional optimization noted in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, solidity
- Domain
- build-system, cli, compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100