Skip to content

Commit 3b0eb96

Browse files
authored
WasmFS: Fix FS.cwd() usage without FORCE_FILESYSTEM (#19616)
The linking of FS.cwd is pretty awkward, unfortunately, but without adding too much more complexity this PR makes it work in another case, when FORCE_FILESYSTEM is not set. I am hoping this is the end of the complexity here. See more details in the big comment. The enabled test is an example of a case that failed before. This PR also allows us to remove the ugly INCLUDE_FULL_LIBRARY hack in this code.
1 parent 7660103 commit 3b0eb96

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/library_wasmfs.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FS.createPreloadedFile = FS_createPreloadedFile;
3030
'$FS_getMode',
3131
// For FS.readFile
3232
'$UTF8ArrayToString',
33-
#if FORCE_FILESYSTEM || INCLUDE_FULL_LIBRARY // see comment below on FORCE
33+
#if FORCE_FILESYSTEM
3434
'$FS_modeStringToFlags',
3535
'malloc',
3636
'free',
@@ -114,16 +114,23 @@ FS.createPreloadedFile = FS_createPreloadedFile;
114114
return ret;
115115
},
116116

117-
#if FORCE_FILESYSTEM || INCLUDE_FULL_LIBRARY // FORCE_FILESYSTEM makes us
118-
// include all JS library code. We
119-
// must also do so if
120-
// INCLUDE_FULL_LIBRARY as other
121-
// places will refer to FS.cwd()
122-
// in that mode, and so we need
123-
// to include that.
117+
// FS.cwd is in the awkward position of being used from various JS
118+
// libraries through PATH_FS. FORCE_FILESYSTEM may not have been set while
119+
// using those libraries, which means we cannot put this method in the
120+
// ifdef for that setting just below. Instead, what we can use to tell if we
121+
// need this method is whether the compiled get_cwd() method is present, as
122+
// we include that both when FORCE_FILESYSTEM *and* when PATH_FS is in use
123+
// (see the special PATH_FS deps logic for WasmFS).
124+
//
125+
// While this may seem odd, it also makes sense: we include this JS method
126+
// exactly when the wasm method it wants to call is present.
127+
#if hasExportedSymbol('_wasmfs_get_cwd')
128+
cwd: () => UTF8ToString(__wasmfs_get_cwd()),
129+
#endif
130+
131+
#if FORCE_FILESYSTEM
124132
// Full JS API support
125133

126-
cwd: () => UTF8ToString(__wasmfs_get_cwd()),
127134
mkdir: (path, mode) => withStackSave(() => {
128135
mode = mode !== undefined ? mode : 511 /* 0777 */;
129136
var buffer = stringToUTF8OnStack(path);

test/test_browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,7 @@ def test_worker_api_with_pthread_compilation_fails(self):
25492549
stderr = self.expect_fail([EMCC, 'hello.o', '-o', 'a.js', '-g', '--closure=1', '-pthread', '-sBUILD_AS_WORKER'])
25502550
self.assertContained("pthreads + BUILD_AS_WORKER require separate modes that don't work together, see https://github.com/emscripten-core/emscripten/issues/8854", stderr)
25512551

2552+
@also_with_wasmfs
25522553
def test_emscripten_async_wget2(self):
25532554
self.btest_exit('test_emscripten_async_wget2.cpp')
25542555

0 commit comments

Comments
 (0)