-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from smiasojed/web
Add web worker compatibility
- Loading branch information
Showing
14 changed files
with
114 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,4 @@ artifacts | |
tmp | ||
package-lock.json | ||
/*.html | ||
/js/src/resolc.* | ||
/js/dist/ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../target/wasm32-unknown-emscripten/release/resolc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../target/wasm32-unknown-emscripten/release/resolc.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Web Worker Example</title> | ||
<style> | ||
/* Ensure the pre tag wraps long lines */ | ||
pre { | ||
white-space: pre-wrap; /* Wrap long lines */ | ||
word-wrap: break-word; /* Break long words */ | ||
max-width: 100%; /* Optional: Ensures it doesn't overflow container */ | ||
overflow-wrap: break-word; /* Another method for wrapping */ | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Revive Compilation Output</h1> | ||
<pre id="output"></pre> | ||
<script> | ||
var outputElement = document.getElementById('output'); | ||
var worker = new Worker('./worker.js'); | ||
worker.addEventListener('message', function (e) { | ||
const output = e.data.output | ||
outputElement.textContent = output; | ||
}, false); | ||
|
||
worker.postMessage({ | ||
contractCode: 'contract C { function f() public { } }', | ||
}) | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../target/wasm32-unknown-emscripten/release/resolc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../target/wasm32-unknown-emscripten/release/resolc.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
importScripts('./soljson.js'); | ||
importScripts('./resolc.js'); | ||
|
||
// Handle messages from the main thread | ||
onmessage = async function (e) { | ||
const contractCode = e.data.contractCode | ||
const sourceCode = { | ||
language: 'Solidity', | ||
sources: { | ||
contract: { | ||
content: contractCode, | ||
} | ||
}, | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200, | ||
}, | ||
outputSelection: { | ||
'*': { | ||
'*': ['abi'], | ||
} | ||
} | ||
} | ||
}; | ||
const m = createRevive(); | ||
|
||
m.soljson = Module; | ||
|
||
// Set input data for stdin | ||
m.setStdinData(JSON.stringify(sourceCode)); | ||
|
||
var stdoutString = ""; | ||
m.setStdoutCallback(function(char) { | ||
if (char.charCodeAt(0) === '\n') { | ||
console.log("new line") | ||
exit | ||
} | ||
stdoutString += char; | ||
}); | ||
|
||
var stderrString = ""; | ||
m.setStderrCallback(function(char) { | ||
stderrString += char; | ||
}); | ||
|
||
// Compile the Solidity source code | ||
m.callMain(['--standard-json']); | ||
|
||
postMessage({output: stdoutString || stderrString}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
{ | ||
"name": "revive", | ||
"version": "1.0.0", | ||
"description": "Revive compiler", | ||
"main": "run_revive.js", | ||
"private": true, | ||
"dependencies": { | ||
"solc": "^0.8.28" | ||
}, | ||
"scripts": { | ||
"build": "mkdir -p src && cp ../target/wasm32-unknown-emscripten/release/resolc.js ../target/wasm32-unknown-emscripten/release/resolc.wasm ./src && npx rollup -c", | ||
"test": "npm run build && node run_revive.js" | ||
"fetch:soljson": "wget https://binaries.soliditylang.org/wasm/soljson-v0.8.28+commit.7893614a.js -O ./examples/web/soljson.js", | ||
"example:web": "npm run fetch:soljson && http-server ./examples/web/", | ||
"example:node": "node ./examples/node/run_revive.js" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.26.0", | ||
"@babel/preset-env": "^7.26.0", | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"rollup": "^4.27.3", | ||
"rollup-plugin-copy": "^3.5.0" | ||
"http-server": "^14.1.1" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters