emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.65k stars 3.29k forks source link

How can I add dynamic file path access ability to emscripten's current File api? #17051

Open chenzx opened 2 years ago

chenzx commented 2 years ago

I've noticed emcc's -lworkerfs.js --preload-file can only build a fixed file set, However i need the wasm C++ code fopen can open any local file path (with potential support from server side)

https://emscripten.org/docs/porting/files/Synchronous-Virtual-XHR-Backed-File-System-Usage.html#synchronous-virtual-xhr-backed-file-system-usage says can use FS.createLazyFile api to create a mapping from a virtual wasm fs path to server side url path, but documentation says MUST used with --pre-js option.

Which means, --pre-js inject code is run at the begining of worker thread? Can I call FS.createLazyFile Just-in-Time to worker thread (before wasm C++ fopen run), in that case, I can support dynamic file path access...

chenzx commented 2 years ago

I guess i'll have to implement my own dynamical memfs fread to forward to server-side worker sync fetch, or just wait for the new wasmfs?

Internally refactor my legacy C++ code to change fopen/fread to sync fetch may be possible...