Skip to content

Fully remove unused FS.filesystems property from libfs.js. NFC - #27940

Merged
kripken merged 5 commits into
emscripten-core:mainfrom
kripken:no.fs
Oct 12, 2026
Merged

kripken merged 5 commits into
emscripten-core:mainfrom
kripken:no.fs

Conversation

@kripken

@kripken kripken commented Oct 9, 2026

Copy link
Copy Markdown
Member

Replaces #27918 which did not go far enough.

@kripken
kripken requested a review from sbc100 October 9, 2026 17:58
@sbc100

sbc100 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

I think the there are references in test/test_core.py that need removing too

@kripken
kripken enabled auto-merge (squash) October 12, 2026 17:30
@kripken
kripken disabled auto-merge October 12, 2026 17:47
@kripken
kripken merged commit 3b38f0f into emscripten-core:main Oct 12, 2026
41 checks passed
@kripken
kripken deleted the no.fs branch October 12, 2026 17:47
@hoodmane

Copy link
Copy Markdown
Collaborator

So I think it's worth pointing out that using MEMFS directly only works inside the Emscripten module, code as follows no longer works:

import instantiateModule from "./a.out.mjs";

const Module = await instantiateModule();
Module.FS.mount(Module.FS.filesystems.SOMEFS, ...);

Of course one can just put FS.filesystems back in pre.js or in a constructor. But maybe there would be some value in adding a way to ask for filesystems as an EXPORTED_RUNTIME_METHODS to support that use case in a uniform way?

See python/cpython#160264 where I do this workaround downstream.

@sbc100

sbc100 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

We didn't imagine there there were uses of this property, but if there are then perhaps we should bring it back.

BTW, can you not do Module.FS.mount(Module.SOMEFS, ...); ?

@sbc100

sbc100 commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Yes, I think you can just export the FS object to the outside world if you need to:

$ ./emcc test/hello_world.c -sEXPORTED_FUNCTIONS=_main,MEMFS

@kripken

kripken commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Yes, I think exporting MEMFS if needed is the best solution here. But sorry for the breakage @hoodmane , I didn't fully realize this issue before.

I can add something to the changelog to mention the exporting solution if we think that would be helpful for others?

@hoodmane

Copy link
Copy Markdown
Collaborator

Yeah I think it would be helpful to mention the external use case in the changelog.

@hoodmane

Copy link
Copy Markdown
Collaborator

FS.filesystem is documented in Pyodide's documentation here:
https://pyodide.org/en/stable/usage/file-system.html#mounting-a-file-system

So Pyodide will put back FS.filesystem to avoid unnecessarily breaking things. But it's easy for us to put it back.

@sbc100

sbc100 commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Sorry about the breakage. We should do a better job or auditing at least open source world users before removing stuff.

@hoodmane

Copy link
Copy Markdown
Collaborator

Well it hasn't been released yet so if it were a more problematic change that actually needed a revert we still would have time. But maybe 40% of Emscripten releases have a regression for me. I'm trying to keep better track of this with my cron github action that runs cpython tests against tip of tree Emscripten. Which caught this bug and #27941.

@kripken

kripken commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Some of this is unavoidable as we have been turning some auto-exported things off by default, as a long-term project to reduce the code size waste of decisions that were made over a decade ago. That is, to move to better defaults. But, yeah, we should document each such breaking change. I'll add a changelog mention here.

kripken added a commit that referenced this pull request Oct 23, 2026
sbc100 added a commit to sbc100/emscripten that referenced this pull request Nov 18, 2026
After `FS.filesystems` was removed in emscripten-core#27940 and `toplevel: true` was
enabled for Terser in emscripten-core#27987, optional filesystem backends linked in via
`-lidbfs.js`, `-lworkerfs.js`, `-lproxyfs.js`, `-lopfs.js`, etc. had no
remaining references in the generated JS and were eliminated in `-O2`
and `-O3` builds when referenced only from external JS (such as
`Module.preRun` in HTML).

Mark these optional filesystem backend objects with `__export: true` so
that when `$FS` pulls them in, they are exported and preserved across
JS optimizations (including `--closure=1`, `-sMODULARIZE`, and
`-sMODULARIZE=instance`), without adding any code size when `$FS` is not
used or under default settings.

Fixes: emscripten-core#28072
sbc100 added a commit to sbc100/emscripten that referenced this pull request Nov 18, 2026
After `FS.filesystems` was removed in emscripten-core#27940 and `toplevel: true` was
enabled for Terser in emscripten-core#27987, optional filesystem backends linked in via
`-lidbfs.js`, `-lworkerfs.js`, `-lproxyfs.js`, `-lopfs.js`, etc. had no
remaining references in the generated JS and were eliminated in `-O2`
and `-O3` builds when referenced only from external JS (such as
`Module.preRun` in HTML).

Mark these optional filesystem backend objects with `__export: true` so
that when `$FS` pulls them in, they are exported and preserved across
JS optimizations (including `--closure=1`, `-sMODULARIZE`, and
`-sMODULARIZE=instance`), without adding any code size when `$FS` is not
used or under default settings.

Fixes: emscripten-core#28072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants