You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
native filesystem is not accessible without mounting on node.js #5237
I'm trying to compile a command-line utility for cross-platform distribution but the compiled output can't access any files. Here's a simple repro:
$ cat > hello.c
#include <assert.h>
#include <stdio.h>
int main() {
FILE *file = fopen("hello.c", "rb");
if (!file) {
puts("could not open file");
return 1;
}
puts("could open file");
return 0;
}
$ cc hello.c -o hello
$ ./hello
could open file
$ source emsdk/emsdk_env.sh
$ emcc --version
emcc (Emscripten gcc/clang-like replacement) 1.37.12 (commit 9330aeb094dc88d9eb165cbd63c720229dec205f)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ emcc hello.c -o hello.js
$ node hello.js
could not open file
I tried -s FORCE_FILESYSTEM=1 as this page suggests but it didn't do anything. It looks like NODEFS is what I want. How do I enable it? I tried -s NODEFS=1 but that threw an error.
But that's undesirable because I don't want to have to add this the source code of the 3rd-party tool I'm using and because it's unreasonable for everyone to have to either prefix their paths with /hack or to heavily modify the tool to manually substitute /hack before every path-specific syscall.
I agree this could be much improved. There are some technical limitations that prevent mounting the root, see #2040, which we should fix. And I think that's a good idea to add a flag that mounts it for you, so you don't need to change source code for this to work.
Has this been resolved? Throwing a EM_ASM statement in just to get file-access working seems pretty tedious in a way. I mean, it is not hard - but not what I want either. Basically, I want to tell emscripten to allow me to use the standard POSIX api to read files, list directories and the like. The program I am compiling actually supports self-testing by running through a list of unit tests. But I can not pass that to the program, since the path is not available unfortunately...
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.
Activity
evanw commentedon May 23, 2017
Update: I got it to do something by doing what test_nodefs_rw.c does:
But that's undesirable because I don't want to have to add this the source code of the 3rd-party tool I'm using and because it's unreasonable for everyone to have to either prefix their paths with /hack or to heavily modify the tool to manually substitute /hack before every path-specific syscall.
kripken commentedon May 23, 2017
I agree this could be much improved. There are some technical limitations that prevent mounting the root, see #2040, which we should fix. And I think that's a good idea to add a flag that mounts it for you, so you don't need to change source code for this to work.
bzz commentedon Aug 18, 2017
Would be nice to have a flag indeed.
[-]fopen is broken[/-][+]native filesystem is not accessible without mounting on node.js[/+]IngwiePhoenix commentedon Feb 12, 2019
Has this been resolved? Throwing a
EM_ASMstatement in just to get file-access working seems pretty tedious in a way. I mean, it is not hard - but not what I want either. Basically, I want to tell emscripten to allow me to use the standard POSIX api to read files, list directories and the like. The program I am compiling actually supports self-testing by running through a list of unit tests. But I can not pass that to the program, since the path is not available unfortunately...So, is there a flag yet?
kripken commentedon Feb 12, 2019
I think the
NODERAWFSflag helps here, see settings.js.kkirby commentedon Feb 25, 2019
@kripken Is correct. That worked for me.
stale commentedon Feb 26, 2020
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.