Pack resolc.wasm and resolc.js to resolc_packed.js

This commit is contained in:
Sebastian Miasojed
2025-01-23 11:59:50 +01:00
parent 888723eb0d
commit 8a18f08aff
16 changed files with 420 additions and 377 deletions
+5 -5
View File
@@ -1,9 +1,9 @@
const soljson = require('solc/soljson');
const createRevive = require('./resolc.js');
const soljson = require("solc/soljson");
const createRevive = require("./resolc.js");
async function compile(standardJsonInput) {
if (!standardJsonInput) {
throw new Error('Input JSON for the Solidity compiler is required.');
throw new Error("Input JSON for the Solidity compiler is required.");
}
// Initialize the compiler
@@ -14,7 +14,7 @@ async function compile(standardJsonInput) {
compiler.writeToStdin(JSON.stringify(standardJsonInput));
// Run the compiler
compiler.callMain(['--standard-json']);
compiler.callMain(["--standard-json"]);
// Collect output
const stdout = compiler.readFromStdout();
@@ -29,4 +29,4 @@ async function compile(standardJsonInput) {
return stdout;
}
module.exports = { compile };
module.exports = { compile };
+20 -20
View File
@@ -1,10 +1,10 @@
const { compile } = require('./revive.js');
const { compile } = require("./revive.js");
const compilerStandardJsonInput = {
language: 'Solidity',
sources: {
'MyContract.sol': {
content: `
language: "Solidity",
sources: {
"MyContract.sol": {
content: `
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract MyContract {
@@ -13,26 +13,26 @@ const compilerStandardJsonInput = {
}
}
`,
},
},
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
"*": {
"*": ["abi"],
},
},
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
'*': {
'*': ['abi'],
},
},
},
};
},
};
async function runCompiler() {
let output = await compile(compilerStandardJsonInput)
let output = await compile(compilerStandardJsonInput);
console.log("Output: " + output);
}
runCompiler().catch(err => {
console.error('Error:', err);
runCompiler().catch((err) => {
console.error("Error:", err);
});
+49 -47
View File
@@ -1,51 +1,53 @@
<!DOCTYPE html>
<!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>
<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');
const standardJsonInput = {
language: 'Solidity',
sources: {
contract: {
content: 'contract MyContract { function f() public { } }',
}
},
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
'*': {
'*': ['abi'],
}
}
}
};
worker.addEventListener('message', function (e) {
outputElement.textContent = e.data.output;
}, false);
worker.postMessage(JSON.stringify(standardJsonInput));
</script>
</body>
<body>
<h1>Revive Compilation Output</h1>
<pre id="output"></pre>
<script>
var outputElement = document.getElementById("output");
var worker = new Worker("./worker.js");
const standardJsonInput = {
language: "Solidity",
sources: {
contract: {
content: "contract MyContract { function f() public { } }",
},
},
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
"*": {
"*": ["abi"],
},
},
},
};
worker.addEventListener(
"message",
function (e) {
outputElement.textContent = e.data.output;
},
false,
);
worker.postMessage(JSON.stringify(standardJsonInput));
</script>
</body>
</html>
-1
View File
@@ -1 +0,0 @@
../../../target/wasm32-unknown-emscripten/release/resolc.wasm
+9 -11
View File
@@ -1,18 +1,16 @@
importScripts('./soljson.js');
importScripts('./resolc.js');
importScripts("./soljson.js");
importScripts("./resolc.js");
// Handle messages from the main thread
onmessage = async function (e) {
const m = createRevive();
const m = createRevive();
m.soljson = Module;
m.soljson = Module;
// Set input data for stdin
m.writeToStdin(e.data);
// Set input data for stdin
m.writeToStdin(e.data);
// Compile the Solidity source code
m.callMain(["--standard-json"]);
// Compile the Solidity source code
m.callMain(['--standard-json']);
postMessage({output: m.readFromStdout() || m.readFromStderr()});
postMessage({ output: m.readFromStdout() || m.readFromStderr() });
};