-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[WasmFS] Make the Node backend optional for web builds #26608
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
Changes from all commits
26eaedc
d30f7de
eea0053
4143136
4b86c1c
a2ab145
112bd63
d0c6c63
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,8 +4,8 @@ | |||||
| * SPDX-License-Identifier: MIT | ||||||
| */ | ||||||
|
|
||||||
| addToLibrary({ | ||||||
| $wasmfsNodeIsWindows: !!process.platform.match(/^win/), | ||||||
| var wasmFSNodeLibrary = { | ||||||
| $wasmfsNodeIsWindows: "!!process.platform.match(/^win/)", | ||||||
|
Collaborator
Author
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. This is a small drive-by fix. Previously, this would emit (when building on Linux): var wasmfsNodeIsWindows = false;in the JS output, which breaks when deploying these binaries on Windows. As possible follow-up, we could also do:
Suggested change
This would allow a #include <emscripten/emscripten.h>
#include <emscripten/wasmfs.h>
EM_JS(bool, is_node, (), { return ENVIRONMENT_IS_NODE; });
backend_t wasmfs_create_root_dir() {
return is_node() ? wasmfs_create_node_backend("")
: wasmfs_create_memory_backend();
}
Collaborator
Author
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. ... PR #26624 addresses this. |
||||||
|
|
||||||
| $wasmfsNodeConvertNodeCode__deps: ['$ERRNO_CODES'], | ||||||
| $wasmfsNodeConvertNodeCode: (e) => { | ||||||
|
|
@@ -29,8 +29,8 @@ addToLibrary({ | |||||
| $wasmfsNodeFixStat__deps: ['$wasmfsNodeIsWindows'], | ||||||
| $wasmfsNodeFixStat: (stat) => { | ||||||
| if (wasmfsNodeIsWindows) { | ||||||
| // Node.js on Windows never represents permission bit 'x', so | ||||||
| // propagate read bits to execute bits | ||||||
| // Windows does not report the 'x' permission bit, so propagate read | ||||||
| // bits to execute bits. | ||||||
| stat.mode |= (stat.mode & {{{ cDefs.S_IRUGO }}}) >> 2; | ||||||
| } | ||||||
| return stat; | ||||||
|
|
@@ -222,5 +222,30 @@ addToLibrary({ | |||||
| // implicitly return 0 | ||||||
| }); | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| #if !ENVIRONMENT_MAY_BE_NODE | ||||||
| function makeStub(x, library) { | ||||||
| if (isJsOnlySymbol(x) || isDecorator(x)) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| var t = library[x]; | ||||||
| if (typeof t == 'string') return; | ||||||
| t = t.toString(); | ||||||
|
|
||||||
| delete library[x + '__i53abi']; | ||||||
| delete library[x + '__deps']; | ||||||
| library[x] = modifyJSFunction(t, (args, body) => { | ||||||
| return `(${args}) => {\n` + | ||||||
| (ASSERTIONS ? "abort('attempt to call Node.js backend function without ENVIRONMENT_MAY_BE_NODE');\n" : '') + | ||||||
| '}'; | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| for (const name of Object.keys(wasmFSNodeLibrary)) { | ||||||
| makeStub(name, wasmFSNodeLibrary); | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| }); | ||||||
| addToLibrary(wasmFSNodeLibrary); | ||||||
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.
What about simply not allowing this file to be included at all it
!ENVIRONMENT_MAY_BE_NODE?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.
That would lead to linker failures. For example, if I remove all these stubs and run
./test/runner other.test_wasmfs_nodefs_stubs, I see:Details
I also thought about moving these stubs to native code and using weak linkage (like how
wasmfs_create_root_dir()is handled), but this seemed easier.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.
Fair enough. I guess we should abort/assert in debug builds there though.