Rémi Rémi - 2 months ago 9x
Javascript Question

How can I track the reason why FS is included by emscripten?

I am compiling some C++ code to emscripten. I noticed that emscripten includes a large piece of code to support file-system manipulation. According to emscripten's documentation, this code is included because the compiled C++ invokes I/O functions. Otherwise, it would not be there. This is the relevant part of the documentation:

Emscripten decides whether to include file system support
automatically. Many programs don’t need files, and file system support
is not negligible in size, so Emscripten avoids including it when it
doesn’t see a reason to. That means that if your C/C++ code does not
access files, then the FS object and other file system APIs will not
be included in the output. And, on the other hand, if your C/C++ code
does use files, then file system support will be automatically
included. So normally things will “just work” and you don’t need to
think about this at all.

The code I am compiling should not be doing I/O, and I would like to optimize the size of the compiled javascript. I tried hard to remove all I/O code, but there must be something left somewhere that requires FS support.

Is there a simple way I could track what requires FS support in my code?


You can try the NO_FILESYSTEM compiler option, as explained at https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html#miscellaneous-code-size-tips

You can use the NO_FILESYSTEM option to disable bundling of filesystem support code (the compiler should optimize it out if not used, but may not always succeed). This can be useful if you are building a pure computational library, for example. See settings.js for more details.

Which you use on the command line as

emcc -s NO_FILESYSTEM=1 [... other stuff]