[wip] compiler abstraction
This PR introduces following traits:
-
Compiler- wrapper around compiler executable (solc/vyper) with following associated types-
Input- trait capable of generating aVec<Self>from givenSourcesset -
ParsedSource- parser which extracts semver requirements and imported files from a given source -
CompilationError- errors returned by underlying compiler binary -
Settings- compiler settings
-
-
CompilerVersionManager- factory ofCompilers capable of getting compilers by version
This PR contains 2 implementations of Compiler: Solc which is slightly updated Solc struct, and Vyper which is a draft PoC impl always invoking vyper command without any version management.
Currently it's already possible to compile and use cache for Vyper sources if vyper is avaialble on host machine.
Open questions:
- Do we need
Compiler::Errorassociated type? It requires additional generics onResults returned byProjectCompilerwhich I am not sure we'll ever use. - Right now all
Project::compile*functions accept eitherCompilerorCompilerVersionManager. This makes API a bit more complex as earlier we'd just callproject.compile()and it'd use svm to auto-detect compiler version. Perhaps it makes sense to add more helper fns/types?
Some parts of the code are ignored for now as they are not really used in the actual compiler pipeline. I'll work on making tests pass and adapting all code to changes.
Other general changes to types:
-
allowed_pathsandinclude_pathsare moved fromProjecttoProjectPathsConfig - some of the compiler output types were indexing paths via
String, updated keys for those toPathBuf. -
Solcnow always required to keep aVersionas we need it to configure all flags correctly.
Solc now always required to keep a Version as we need it to configure all flags correctly.
this makes sense, a solc that can't resolve the version will also fail when compiling, so new(path) -> Result<Solc> is more useful imo
@elfedy yep, I was keeping zkSync usecase in mind
We've decided to not make output artifact type generic for now as foundry can already benefit from generic Compiler returning artifacts of the same shape (Contract)
In the future this will be made generic and for zkSync case this can return a single artifact including zksolc and solc compilation output