-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add all resolc dependencies to resolc_packed.js file #176
base: main
Are you sure you want to change the base?
Changes from all commits
8a18f08
82f83c9
66975af
66534f4
a4e29b3
e2ccdaa
e9d3ec2
3035542
ff6bb55
69d81c9
b1d16ee
8f87d01
137ff4a
f49dcbe
ef22770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ jobs: | |
path: | | ||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.js | ||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.wasm | ||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc_packed.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the suffix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not make sense. I am not sure if I will merge it—perhaps I should find a better solution.
|
||
retention-days: 1 | ||
|
||
test-revive-wasm: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { minify } = require("terser"); | ||
|
||
const SOLJSON_URI = | ||
"https://binaries.soliditylang.org/wasm/soljson-v0.8.28+commit.7893614a.js"; | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we planning to this dynamically inside remix in the future? I think this should be done client side. In remix , the user can select the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How it works in Remix: Remix lists the compiler files and loads the selected Steps to bundle it on the Remix side: This change will affect many files in Remix. I wanted to implement it, but first, I need to run Remix's unit and E2E tests. A side effect of this change is that any future Remix updates will take more time to integrate. I think I could remove soljson dep from revive and add it during compiler list generation on backend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two options here:
The second option would also allow us to spend much less resources in optimizing the compiler for the in-browser environments. Honestly I think the second option would allow us to move forward fast and focus on more important issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to decide where to host the compilers if GitHub Pages does not support enabling CSP headers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will put them in the Remix repo. No one else will use them, so it's safe to keep them there. |
||
const RESOLC_WASM_URI = "http://127.0.0.1:8080/resolc.wasm"; | ||
const RESOLC_WASM_TARGET_DIR = path.join( | ||
__dirname, | ||
"../target/wasm32-unknown-emscripten/release", | ||
); | ||
const RESOLC_JS = path.join(RESOLC_WASM_TARGET_DIR, "resolc.js"); | ||
const RESOLC_JS_PACKED = path.join(RESOLC_WASM_TARGET_DIR, "resolc_packed.js"); | ||
|
||
const resolcJs = fs.readFileSync(RESOLC_JS, "utf-8"); | ||
|
||
const packedJsContent = ` | ||
if (typeof importScripts === "function") { | ||
importScripts("${SOLJSON_URI}"); | ||
|
||
var moduleArgs = { | ||
wasmBinary: (function () { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "${RESOLC_WASM_URI}", false); | ||
xhr.responseType = "arraybuffer"; | ||
xhr.send(null); | ||
return new Uint8Array(xhr.response); | ||
})(), | ||
soljson: Module | ||
}; | ||
} else { | ||
console.log("Not a WebWorker, skipping Soljson and WASM loading."); | ||
} | ||
|
||
${resolcJs} | ||
|
||
createRevive = createRevive.bind(null, moduleArgs); | ||
`; | ||
|
||
minify(packedJsContent) | ||
.then((minifiedJs) => { | ||
if (minifiedJs.error) { | ||
console.error("Error during minification:", minifiedJs.error); | ||
process.exit(1); | ||
} | ||
|
||
fs.writeFileSync(RESOLC_JS_PACKED, minifiedJs.code, "utf-8"); | ||
console.log(`Combined script written to ${RESOLC_JS_PACKED}`); | ||
}) | ||
.catch((err) => { | ||
console.error("Minification failed:", err); | ||
process.exit(1); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,57 @@ | ||
var Module = { | ||
stdinData: null, | ||
stdinDataPosition: 0, | ||
stdoutData: [], | ||
stderrData: [], | ||
Module.stdinData = null; | ||
Module.stdinDataPosition = 0; | ||
Module.stdoutData = []; | ||
Module.stderrData = []; | ||
|
||
// Function to read and return all collected stdout data as a string | ||
readFromStdout: function() { | ||
if (!this.stdoutData.length) return ""; | ||
const decoder = new TextDecoder('utf-8'); | ||
const data = decoder.decode(new Uint8Array(this.stdoutData)); | ||
this.stdoutData = []; | ||
return data; | ||
}, | ||
// Method to read all collected stdout data | ||
Module.readFromStdout = function () { | ||
if (!Module.stdoutData.length) return ""; | ||
const decoder = new TextDecoder("utf-8"); | ||
const data = decoder.decode(new Uint8Array(Module.stdoutData)); | ||
Module.stdoutData = []; | ||
return data; | ||
}; | ||
|
||
// Function to read and return all collected stderr data as a string | ||
readFromStderr: function() { | ||
if (!this.stderrData.length) return ""; | ||
const decoder = new TextDecoder('utf-8'); | ||
const data = decoder.decode(new Uint8Array(this.stderrData)); | ||
this.stderrData = []; | ||
return data; | ||
}, | ||
// Method to read all collected stderr data | ||
Module.readFromStderr = function () { | ||
if (!Module.stderrData.length) return ""; | ||
const decoder = new TextDecoder("utf-8"); | ||
const data = decoder.decode(new Uint8Array(Module.stderrData)); | ||
Module.stderrData = []; | ||
return data; | ||
}; | ||
|
||
// Function to set input data for stdin | ||
writeToStdin: function(data) { | ||
const encoder = new TextEncoder(); | ||
this.stdinData = encoder.encode(data); | ||
this.stdinDataPosition = 0; | ||
}, | ||
// Method to write data to stdin | ||
Module.writeToStdin = function (data) { | ||
const encoder = new TextEncoder(); | ||
Module.stdinData = encoder.encode(data); | ||
Module.stdinDataPosition = 0; | ||
}; | ||
|
||
// `preRun` is called before the program starts running | ||
preRun: function() { | ||
// Define a custom stdin function | ||
function customStdin() { | ||
if (!Module.stdinData || Module.stdinDataPosition >= Module.stdinData.length) { | ||
return null; // End of input (EOF) | ||
} | ||
return Module.stdinData[Module.stdinDataPosition++]; | ||
} | ||
// Override the `preRun` method to customize file system initialization | ||
Module.preRun = Module.preRun || []; | ||
Module.preRun.push(function () { | ||
// Custom stdin function | ||
function customStdin() { | ||
if ( | ||
!Module.stdinData || | ||
Module.stdinDataPosition >= Module.stdinData.length | ||
) { | ||
return null; // End of input (EOF) | ||
} | ||
return Module.stdinData[Module.stdinDataPosition++]; | ||
} | ||
|
||
// Define a custom stdout function | ||
function customStdout(char) { | ||
Module.stdoutData.push(char); | ||
} | ||
// Custom stdout function | ||
function customStdout(char) { | ||
Module.stdoutData.push(char); | ||
} | ||
|
||
// Define a custom stderr function | ||
function customStderr(char) { | ||
Module.stderrData.push(char); | ||
} | ||
// Custom stderr function | ||
function customStderr(char) { | ||
Module.stderrData.push(char); | ||
} | ||
|
||
FS.init(customStdin, customStdout, customStderr); | ||
}, | ||
}; | ||
// Initialize the FS (File System) with custom handlers | ||
FS.init(customStdin, customStdout, customStderr); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
mergeInto(LibraryManager.library, { | ||
soljson_compile: function(inputPtr, inputLen) { | ||
const inputJson = UTF8ToString(inputPtr, inputLen); | ||
const output = Module.soljson.cwrap('solidity_compile', 'string', ['string'])(inputJson); | ||
return stringToNewUTF8(output); | ||
}, | ||
soljson_version: function() { | ||
const version = Module.soljson.cwrap("solidity_version", "string", [])(); | ||
return stringToNewUTF8(version); | ||
}, | ||
resolc_compile: function(inputPtr, inputLen) { | ||
const inputJson = UTF8ToString(inputPtr, inputLen); | ||
var revive = createRevive(); | ||
revive.writeToStdin(inputJson); | ||
soljson_compile: function (inputPtr, inputLen) { | ||
const inputJson = UTF8ToString(inputPtr, inputLen); | ||
const output = Module.soljson.cwrap("solidity_compile", "string", [ | ||
"string", | ||
])(inputJson); | ||
return stringToNewUTF8(output); | ||
}, | ||
soljson_version: function () { | ||
const version = Module.soljson.cwrap("solidity_version", "string", [])(); | ||
return stringToNewUTF8(version); | ||
}, | ||
resolc_compile: function (inputPtr, inputLen) { | ||
const inputJson = UTF8ToString(inputPtr, inputLen); | ||
var revive = createRevive(); | ||
revive.writeToStdin(inputJson); | ||
|
||
// Call main on the new instance | ||
const result = revive.callMain(['--recursive-process']); | ||
// Call main on the new instance | ||
const result = revive.callMain(["--recursive-process"]); | ||
|
||
if (result) { | ||
const stderrString = revive.readFromStderr(); | ||
const error = JSON.stringify({ type: 'error', message: stderrString || "Unknown error" }); | ||
return stringToNewUTF8(error); | ||
} else { | ||
const stdoutString = revive.readFromStdout(); | ||
const json = JSON.stringify({ type: 'success', data: stdoutString }); | ||
return stringToNewUTF8(json); | ||
} | ||
}, | ||
if (result) { | ||
const stderrString = revive.readFromStderr(); | ||
const error = JSON.stringify({ | ||
type: "error", | ||
message: stderrString || "Unknown error", | ||
}); | ||
return stringToNewUTF8(error); | ||
} else { | ||
const stdoutString = revive.readFromStdout(); | ||
const json = JSON.stringify({ type: "success", data: stdoutString }); | ||
return stringToNewUTF8(json); | ||
} | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to release it? Does it have any worth over
resolc_packed.js
? How would you use it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolc.js makes sense for use with Node.js, where it is not dynamically downloaded, for example in
js-revive