-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Initial NODERAWFS implementation #6008
Conversation
Node.js supports integer flags but it depends on native system constants, which are different from values on struct_info.compiled.json
Nice! This is simpler than I thought it would need to be. More testing (of all the file operations that are practical to test) and documentation would be good here. |
Also we should test it in |
Should this disable |
It seems the truncate test does not work with root permission. |
tests/unistd/dup.c
Outdated
f = open("/", O_RDONLY); | ||
f2 = open("/", O_RDONLY); | ||
f = open(".", O_RDONLY); | ||
f2 = open(".", O_RDONLY); |
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.
Could we leave a form that checks against /
in non-NODERAWFS form? I think we'd want to retain that, it's an important invariant of MEMFS that /
root is predictable.
tests/fs/test_nodefs_cloexec.c
Outdated
); | ||
assert(open("/working/test.txt", O_RDONLY | O_CLOEXEC) != -1); | ||
assert(open("test.txt", O_RDONLY | O_CLOEXEC) != -1); |
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.
The removal of /working/
could be seen as changing the test, although searching through the tests/ subdirectory, it does look like there's still a couple of places where we explicitly test the /working/test.txt
form. I think we'd like to ensure that this is tested, since this does change absolute to relative, which sometimes has different behavior. Perhaps a
#ifdef NODERAWFS
#define ROOT ""
#else
#define ROOT "/"
#endif
...
assert(open(ROOT "working/test.txt", O_RDONLY | O_CLOEXEC) != -1);
or similar, to keeping testing behavior of absolute paths, while retaining the relative test for NODERAWFS?
(I'm not sure how important specifically the absolute root path property was when the original test was being crafted, but I think it's good to keep it as close to original as possible, perhaps only adding new cases)
tests/test_core.py
Outdated
@@ -4582,20 +4599,43 @@ def process(filename): | |||
} | |||
''', 'at Object.write', js_engines=[NODE_JS], post_build=post) # engines has different error stack format | |||
|
|||
def test_noderawfs(self): |
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.
tests like these two that don't depend on the compiler mode should be in other
(otherwise we run the same test in each mode)
src/settings.js
Outdated
@@ -382,6 +382,10 @@ var NO_FILESYSTEM = 0; // If set, does not build in any filesystem support. Usef | |||
var FORCE_FILESYSTEM = 0; // Makes full filesystem support be included, even if statically it looks like it is not | |||
// used. For example, if your C code uses no files, but you include some JS that does, | |||
// you might need this. | |||
var NODERAWFS = 0; // This dynamically disables virtual filesystem when the build result runs on Node.js |
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.
perhaps this should just make the build node.js-only, that seems simpler? is there a benefit to letting it run on non-node with different behavior?
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.
NODERAWFS only replaces low-level APIs, otherwise it depends on original FS methods including FS.read/writeFile
. FS.ensureErrnoError
, FS.nextfd
, etc. I think there is no value to make it node.js-only when we still depend on original FS.
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.
I think it might avoid some possible confusion, though. To be clear, I'm suggesting that when NODERAWFS is enabled, the build will throw at runtime if it is loaded in anything else than node.js.
Otherwise, the possible confusion that worries me is that the build is run in node and in another shell, and they produce very different results. That's currently something that should not happen, which shell you are in should not matter.
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.
which shell you are in should not matter
Yeah... it can be confusing in other shell environments. We may make it throw first and see what's going on.
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.
Updated but probably we cannot run a failure test on CI as 1. we only have Node.js 2. AFAIK the browser test does not support failure test.
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.
Thanks, and yeah, makes sense about testing.
This PR looks good to me now, just one last thing, please update the comment here in settings.js to say it will throw if not in Node.js.
src/settings.js
Outdated
@@ -385,7 +385,7 @@ var FORCE_FILESYSTEM = 0; // Makes full filesystem support be included, even if | |||
var NODERAWFS = 0; // This dynamically disables virtual filesystem when the build result runs on Node.js | |||
// and directly depends on behaviors of Node.js File System API. | |||
// The initial working directory will be same as process.cwd() instead of VFS root directory. | |||
// The VFS becomes only available for non-Node.js environment. | |||
// The build result will throw when it runs on non-Node.js environment. |
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.
This one? @kripken
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.
Yeah, but sorry, I should have been more clear. It's the first statement I think is confusing,
"This dynamically disables virtual filesystem when the build result runs on Node.js"
How about text like "This mode is intended for use with Node.js (and will throw if the build is run in another engine)" at the start, removing "when the build runs on Node.js" (since that is the only intended use).
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.
Great, just pushed a commit for that 😃
Great, thanks! |
I think I see why we missed the test failures here. The last commits are |
|
Hmm, I bisected I also bisected the other failures (partial list here) to this commit. The error on them is |
Ops, very sorry about this breakage - that was one of those "this is just way too trivial to need a review" so I pushed it in direct. The reason for that change is that the test was failing on Windows where it was writing |
This is currently breaking out waterfall Mac bots: Doesn't look like the CI has mac bots. Could you test them on mac? |
Sadly I don't think travis has mac bots... Looking at the last error in the second link, it says it's node 8.9.3 so it's probably not a version issue. Likely it really is an OS difference, and NODERAWFS is sensitive to such things. We'd need to debug it on mac I guess. If no one thinks they can get to that soon, we could disable the NODERAWFS tests on mac for now, and maybe update the docs to warn. |
I disabled the tests. Not sure which doc to update though. |
Side note, Travis actually does have mac bots: see e.g. https://github.com/WebAssembly/wabt/blob/master/.travis.yml |
Looking at the logs, it seems append mode doesn't work on macOS. I don't have any macOS access but how about filing issues on Node.js too? |
I think the best we have is the settings.js description. I'll update that. |
Fixes #5266.
This removes the need for emscripten-compiled CLI tools to manually mount NODEFS and map all file paths.
-s NODERAWFS=1
overwrites onFS
object and works as an in-place replacement when on Node.js, otherwise the existing virtual filesystem is provided.