hyperledger-solang / solang

Solidity Compiler for Solana and Polkadot
https://solang.readthedocs.io/
Apache License 2.0
1.27k stars 215 forks source link

Feature gate LLVM dependency #597

Closed shekhirin closed 2 years ago

shekhirin commented 2 years ago

Problem

Currently there's no way to use parser without compiling the inkwell dependency which in turn requires the LLVM to be installed.

I encountered that issue while working on Solidity formatter in Foundry (https://github.com/gakonst/foundry/pull/201) where we use only parser::parse function to construct the AST. Without the hard LLVM dependency it would be much easier for users to install our CLI since they won't need to have LLVM installed on their machine.

Solution

I tried to add an llvm feature to Cargo.toml and use #[cfg(feature = "llvm")] in src/lib.rs but that didn't work straight away since parser is writing lots of diagnostic messages while parsing and these messages are written from the package that’s currently depends on LLVM. So simple [features] in Cargo.toml won’t solve the issue for now.

The proposed solution is to separate the diagnostics-related types & functions into the separate module which can be used without LLVM dependency.

seanyoung commented 2 years ago

This is totally a good idea. The solang vscode plugin also does not need llvm, and if did not need llvm, it could be built as a node wasm module.

The llvm dependencies should be in src/emit/. If they're not, they should be abstracted/moved.

An Solidity formatter is a great.I'd love to see that happen.