Cheng Shao pushed to branch wip/wasm-dyld-pie at Glasgow Haskell Compiler / GHC Commits: 82c0689a by Cheng Shao at 2025-10-24T19:07:39+02:00 wasm: factor out nodeMain in dyld - - - - - 1 changed file: - utils/jsffi/dyld.mjs Changes: ===================================== utils/jsffi/dyld.mjs ===================================== @@ -318,11 +318,7 @@ class DyLDHost { // Deduped absolute paths of directories where we lookup .so files #rpaths = new Set(); - constructor() { - // Inherited pipe file descriptors from GHC - const out_fd = Number.parseInt(process.argv[4]), - in_fd = Number.parseInt(process.argv[5]); - + constructor({ out_fd, in_fd }) { this.readStream = stream.Readable.toWeb( fs.createReadStream(undefined, { fd: in_fd }) ); @@ -494,7 +490,7 @@ export class DyLDRPC { // Actual implementation of endpoints used by DyLDRPC class DyLDRPCServer { - #dyldHost = new DyLDHost(); + #dyldHost; #server; #wss; @@ -504,9 +500,13 @@ class DyLDRPCServer { dyldPath, libdir, ghciSoPath, + out_fd, + in_fd, args, redirectWasiConsole, }) { + this.#dyldHost = new DyLDHost({ out_fd, in_fd }); + this.#server = http.createServer(async (req, res) => { const origin = originFromServerAddress(await this.listening); @@ -1252,17 +1252,9 @@ export async function main({ rpc, libdir, ghciSoPath, args }) { } } -(async () => { - if (!isNode) { - return; - } - - const libdir = process.argv[2]; - const ghciSoPath = process.argv[3]; - const args = process.argv.slice(6); - +export async function nodeMain({ libdir, ghciSoPath, out_fd, in_fd, args }) { if (!process.env.GHCI_BROWSER) { - const rpc = new DyLDHost(); + const rpc = new DyLDHost({ out_fd, in_fd }); await main({ rpc, libdir, @@ -1284,6 +1276,8 @@ export async function main({ rpc, libdir, ghciSoPath, args }) { dyldPath: import.meta.filename, libdir, ghciSoPath, + out_fd, + in_fd, args, redirectWasiConsole: process.env.GHCI_BROWSER_PUPPETEER_LAUNCH_OPTS || @@ -1374,4 +1368,22 @@ export async function main({ rpc, libdir, ghciSoPath, args }) { console.log( `Open ${origin}/main.html or import ${origin}/main.js to boot ghci` ); -})(); +} + +function isNodeMain() { + if (!globalThis?.process?.versions?.node) { + return false; + } + + return import.meta.filename === process.argv[1]; +} + +if (isNodeMain()) { + const libdir = process.argv[2]; + const ghciSoPath = process.argv[3]; + const out_fd = Number.parseInt(process.argv[4]), + in_fd = Number.parseInt(process.argv[5]); + const args = process.argv.slice(6); + + nodeMain({ libdir, ghciSoPath, out_fd, in_fd, args }); +} View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/82c0689a4aef740fc399a1f88c84bea0... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/82c0689a4aef740fc399a1f88c84bea0... You're receiving this email because of your account on gitlab.haskell.org.