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

Support for native compilers #87

Merged
merged 33 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b076b2c
rebase
cd1m0 Sep 21, 2021
6a7ebd4
Rebase on master; Get downloading of compilers to work
cd1m0 Sep 21, 2021
d1b559a
Mostly clean run on the new Wasm compiler classes + async compile fun…
cd1m0 Nov 16, 2021
ca1fbf9
First try at native compilation
cd1m0 Dec 10, 2021
cf26a1d
Initial top-level definitions grammar
cd1m0 Jan 10, 2022
2629b6e
Completed and tested the grammar
cd1m0 Jan 11, 2022
43e1560
input refactor WIP, some tests still failing
cd1m0 Jan 12, 2022
6935566
clean test run
cd1m0 Jan 13, 2022
f364a9a
Review comments
cd1m0 Jan 13, 2022
1773cec
forgot more files
cd1m0 Jan 13, 2022
99b63da
Merge pull request #88 from ConsenSys/native_compilers_standard_input…
blitz-1306 Jan 13, 2022
b420cc3
Add integration test that diffs the result of native and wasm compila…
cd1m0 Jan 13, 2022
58baf4d
Polishing pass
blitz-1306 Jan 14, 2022
ee384e8
Merge branch 'native_compilers' of https://github.com/ConsenSys/solc-…
blitz-1306 Jan 14, 2022
1a8b316
Tweaked test for match code base tweaks
blitz-1306 Jan 14, 2022
6b208bd
Stabilizing tsc processing of FLD grammar and polishing executable
blitz-1306 Jan 14, 2022
1ed2a10
Resolved TODO about supportin LocalNpmResolver, removed file-level im…
blitz-1306 Jan 14, 2022
0101114
Polishing and introducing support of both compiler kinds in the tests
blitz-1306 Jan 20, 2022
7e42443
Merge master and resolve conflicts
blitz-1306 Jan 20, 2022
ac8e102
Add axios as dependency to use as component for downloading
blitz-1306 Jan 20, 2022
51ce7e7
Add test coverage for a few ASTNodeFactory methods
blitz-1306 Jan 20, 2022
8d76a19
Minor polishing of test suites
blitz-1306 Jan 21, 2022
dea958f
Attempt to fix CI compiler crash
blitz-1306 Jan 21, 2022
469dfad
Updated dependencies. Disabled changes for some tests to figure if th…
blitz-1306 Jan 21, 2022
50808cd
Restored default compiler kind only for definitions.spec.ts test
blitz-1306 Jan 21, 2022
1d4eee3
Addressing TODOs and bumping test coverage
blitz-1306 Jan 24, 2022
8f530de
Tweaked default compiler cache dir location to not duplicate compiler…
blitz-1306 Jan 24, 2022
304bdd7
Updated README - mentioned native compiler cache
blitz-1306 Jan 24, 2022
e75ff29
Fixed typo in README
blitz-1306 Jan 24, 2022
9b06bdd
Final self-review fixes
cd1m0 Jan 28, 2022
70df82f
Merge pull request #90 from ConsenSys/origin/native_compilers/dimo_nits
blitz-1306 Jan 28, 2022
1ac9fb2
FLD parser: support for legacy invalid escape sequences and $ charact…
blitz-1306 Jan 31, 2022
38b4d61
Merge branch 'native_compilers' of https://github.com/ConsenSys/solc-…
blitz-1306 Jan 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
},
"ignorePatterns": [
"src/types/typeStrings/typeString_parser_header.ts",
"src/types/typeStrings/typeString_parser.ts"
"src/types/typeStrings/typeString_parser.ts",
"src/compile/inference/file_level_definitions_parser_header.ts",
"src/compile/inference/file_level_definitions_parser.ts"
]
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.nyc_output
node_modules
.compiler_cache
/node_modules
dist
docs
coverage
*.tgz
src/types/typeStrings/typeString_parser.ts
src/compile/inference/file_level_definitions_parser.ts
11 changes: 10 additions & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"extension": [".ts"],
"exclude": ["**/*.d.ts", "**/node_modules/**", "**/test/**", "**/coverage/**", "**/docs/**", "src/types/typeStrings/typeString_parser*.ts"],
"exclude": [
"**/*.d.ts",
"**/node_modules/**",
"**/test/**",
"**/coverage/**",
"**/docs/**",
"**/.compiler_cache/**",
"src/types/typeStrings/typeString_parser*.ts",
"src/compile/inference/file_level_definitions_parser*.ts"
],
"reporter": ["html", "text-summary"],
"all": true,
"check-coverage": true,
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ import { CompileFailedError, CompileResult, compileSol } from "solc-typed-ast";
let result: CompileResult;

try {
result = compileSol("sample.sol", "auto", []);
result = await compileSol("sample.sol", "auto", []);
} catch (e) {
if (e instanceof CompileFailedError) {
console.error("Compile errors encountered:");

for (const failure of e.failures) {
console.error(`SolcJS ${failure.compilerVersion}:`);
console.error(`Solc ${failure.compilerVersion}:`);

for (const error of failure.errors) {
console.error(error);
Expand All @@ -68,7 +68,15 @@ console.log(result);

The second argument with the `"auto"` value specifies a compiler selection strategy. If `"auto"` is specified and source code contains valid `pragma solidity` directive, then compiler version will be automatically picked from it. If compile process will not succedd, the execution will fall back to _"compiler guessing"_: trying to compile source with a few different versions of the new and old Solidity compilers. The other option would be to specify a concrete supported compiler version string, like `"0.7.0"` for example. There is also a support for various compiler selection strategies, including used-defined custom ones (`CompilerVersionSelectionStrategy` interface implementations).

**NOTE:** We want to notify that **the package preinstalls 50+ SolcJS compilers** (since 0.4.13), so be ready that it will occupy fair amount of free space. At some point we may consider to move compilers away from this package. It will mostly depend on users feedback.
**NOTE:** We want to notify that **the package preinstalls 50+ versions of Solc compilers** (since 0.4.13), so be ready that it will occupy fair amount of free space. At some point we may consider to move compilers away from this package. It will mostly depend on users feedback.

### Native compilers

Package supports switching between native binary Solc compilers and its WASM versions. The CLI option `--compiler-kind` and `kind` argument of `compile*()` functions family may be used for that purpose. Native binary compilers are downloaded on demand to the directory `.compiler_cache` at the package installation directory (by default). The compiler cache location may be customized by setting `SOL_AST_COMPILER_CACHE` environment variable to a custom path. For example:

```bash
SOL_AST_COMPILER_CACHE=~/.compiler_cache solc-ast-compile sample.sol --compiler-kind native --tree
```

### Typed universal AST

Expand Down Expand Up @@ -130,6 +138,7 @@ Use `--help` to see all available features.
The project have following directory structure:

```
├── .compiler_cache # Cache of downloaded native compilers.
├── coverage # Test coverage report, produced by "npm test" command.
├── dist # Generated JavaScript sources for package distribution (produced by "npm run build" and published by "npm publish" commands).
├── docs # Project documentation and API reference, produced by "npm run docs:render" or "npm run docs:refresh" commands.
Expand Down
390 changes: 177 additions & 213 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"sol-ast-compile": "dist/bin/compile.js"
},
"scripts": {
"clean": "rm -rf dist/ src/ast/typestrings/typeString_parser.ts",
"clean": "rm -rf dist/ src/ast/typestrings/typeString_parser.ts src/compile/inference/file_level_definitions_parser.ts",
"transpile": "tsc",
"build-type-parser": "tspegjs -o src/types/typeStrings/typeString_parser.ts --custom-header-file src/types/typeStrings/typeString_parser_header.ts --cache src/types/typeStrings/typeString_grammar.pegjs",
"build": "npm run clean && npm run build-type-parser && npm run transpile",
"build-file-level-definitions-parser": "tspegjs -o src/compile/inference/file_level_definitions_parser.ts --custom-header-file src/compile/inference/file_level_definitions_parser_header.ts --cache src/compile/inference/file_level_definitions.pegjs",
"build-parsers": "npm run build-type-parser && npm run build-file-level-definitions-parser",
"build": "npm run clean && npm run build-parsers && npm run transpile",
"lint": "eslint src/ test/ --ext=ts",
"lint:fix": "eslint src/ test/ --ext=ts --fix",
"test": "NODE_OPTIONS='--max-old-space-size=2048' nyc mocha",
Expand All @@ -26,6 +28,7 @@
"prepare": "npm run build"
},
"dependencies": {
"axios": "^0.25.0",
"findup-sync": "^5.0.0",
"fs-extra": "^10.0.0",
"jsel": "^1.1.6",
Expand Down Expand Up @@ -85,6 +88,8 @@
"solc-0.7.6": "npm:solc@0.7.6",
"solc-0.8.0": "npm:solc@0.8.0",
"solc-0.8.1": "npm:solc-0.8.1-fixed@0.8.1",
"solc-0.8.10": "npm:solc@0.8.10",
"solc-0.8.11": "npm:solc@0.8.11",
"solc-0.8.2": "npm:solc@0.8.2",
"solc-0.8.3": "npm:solc@0.8.3",
"solc-0.8.4": "npm:solc@0.8.4",
Expand All @@ -93,32 +98,30 @@
"solc-0.8.7": "npm:solc@0.8.7-fixed",
"solc-0.8.8": "npm:solc@0.8.8",
"solc-0.8.9": "npm:solc@0.8.9",
"solc-0.8.10": "npm:solc@0.8.10",
"solc-0.8.11": "npm:solc@0.8.11",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.6.1"
"web3-eth-abi": "^1.7.0"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/minimist": "^1.2.2",
"@types/mocha": "^9.0.0",
"@types/node": "^12.20.38",
"@types/mocha": "^9.1.0",
"@types/node": "^12.20.42",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"codecov": "^3.8.3",
"eslint": "^8.5.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"expect": "^27.4.2",
"mocha": "^9.1.3",
"expect": "^27.4.6",
"mocha": "^9.1.4",
"nyc": "^15.1.0",
"peggy": "^1.2.0",
"prettier": "2.5.1",
"ts-node": "^10.4.0",
"ts-pegjs": "^1.2.1",
"typedoc": "^0.22.10",
"typescript": "^4.5.4"
"typedoc": "^0.22.11",
"typescript": "^4.5.5"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
"bugs": "https://github.com/ConsenSys/solc-typed-ast/issues",
Expand Down
Loading