Add web worker compatibility

This commit is contained in:
Sebastian Miasojed
2024-11-27 15:17:26 +01:00
parent 81915ddbcb
commit 6a4fd1e991
12 changed files with 222 additions and 49 deletions
+1
View File
@@ -0,0 +1 @@
../../../target/wasm32-unknown-emscripten/release/resolc.js
+1
View File
@@ -0,0 +1 @@
../../../target/wasm32-unknown-emscripten/release/resolc.wasm
+61
View File
@@ -0,0 +1,61 @@
const soljson = require('solc/soljson');
const createRevive = require('./resolc.js');
const compilerStandardJsonInput = {
language: 'Solidity',
sources: {
'MyContract.sol': {
content: `
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract MyContract {
function greet() public pure returns (string memory) {
return "Hello";
}
}
`,
},
},
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
'*': {
'*': ['abi'],
},
},
},
};
async function runCompiler() {
const m = createRevive();
m.soljson = soljson;
// Set input data for stdin
m.setStdinData(JSON.stringify(compilerStandardJsonInput));
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
let x = m.callMain(['--standard-json']);
console.log("Stdout: " + stdoutString);
console.error("Stderr: " + stderrString);
}
runCompiler().catch(err => {
console.error('Error:', err);
});