emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.91k stars 3.32k forks source link

[feature request] Add a user-facing compiler/linker switch to add a node-invoking hashbang #23041

Open vadimkantorov opened 3 days ago

vadimkantorov commented 3 days ago

Some build scripts will try to immediately execute freshly-built binaries, bypassing this can be nasty and sometimes it's easier to have the emscripten-produced binaries have the node-invoking hashbang and have executable bit via chmod +x. At least surfacing this as a compiler option would be useful (and also may be useful to ask emscripten to produce both the node-invokable JS and sidecar *.wasm file).

It also appears that now hashbang is also accepted in JavaScript as comment: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#hashbang_comments, so in theory might be okay to always produce this hashbang and at least it should not prevent these hashbang-prefixed files to be consummable by conventional JavaScript engines

Originally discussed in: