Accessing local files from C++/wasm when in Node / d8 / etc.?

20 views
Skip to first unread message

Steven Johnson

unread,
May 21, 2019, 2:56:44 PM5/21/19
to emscripte...@googlegroups.com
I have a bunch of pre-existing tests and benchmarks written in vanilla C++ that load images (png, jpeg, etc) from the local filesystem as part of their normal operation. I'm now cross-compiling them into wasm using emscripten, and running them in a wasm-enabled shell (d8 or Node); what options do I have that will minimize the amount of editing I need to do to each test?

Based on what I've read so far:
  • I could modify my Makefiles to use --embed_file when building each test. Pro: the tests can work without editing the C++ source. Con: build time is extremely slow; doesn't allow any test outputs or byproducts to be easily written to local filesystem (e.g for debugging)
  • If I require Node instead of d8, I could use FS.mount(NODEFS) to map the local filesystem in a way that the wasm code can see. Pros: actually provides file access and file output. Cons: requires adding awkward boilerplate to every test I want to run in this environment; requires Node rather than d8
Are there other options I'm missing? (Fortunately, running these tests in a browser environment isn't yet a requirement, though it may be eventually.)

(A close-enough-to-ideal solution for me would be if Node allowed some commandline / config setup that did the filesystem mapping automatically; if such a thing exists, I haven't found it, but I am a newcomer to Node so could have easily missed it.)

Alon Zakai

unread,
May 21, 2019, 5:03:07 PM5/21/19
to emscripte...@googlegroups.com
Another option is NODERAWFS. That just lets the code access the filesystem directly through node's APIs.

The main problem there is that node filesystem commands can behave differently on different OSes (because of underlying OS differences, probably, but could also be node oddities I guess). If you avoid corner cases though then this mode can work well.

- Alon


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAM%3DdnvcJHX%3DgYipxm_gQKPcuP60n%3DVb7-fDNYn9xqmsTtORX7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Steven Johnson

unread,
May 21, 2019, 5:25:04 PM5/21/19
to emscripte...@googlegroups.com
Ah, I didn't know that was a thing! That sounds like the thing I most likely want. (Underlying OS differences are less likely to matter for these cases.)

Reply all
Reply to author
Forward
0 new messages