Skip to content

Support OPFS in WasmFS with standard Asyncify#26496

Merged
brendandahl merged 1 commit intoemscripten-core:mainfrom
brendandahl:em-wasmfs-asyncify
Mar 19, 2026
Merged

Support OPFS in WasmFS with standard Asyncify#26496
brendandahl merged 1 commit intoemscripten-core:mainfrom
brendandahl:em-wasmfs-asyncify

Conversation

@brendandahl
Copy link
Collaborator

Use the new 'auto' keyword to automatically wrap the opfs functions with handleAsync.

Fixes Issue #23133

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I looked at trying to do something like this in #26026, but honestly I got confused by the different layers of async-ness.

I guess we can close #26026 if this lands?

!emscripten_is_main_browser_thread() ||
emscripten_has_asyncify() == 2 &&
"Cannot safely create OPFS backend on main browser thread without JSPI");
emscripten_has_asyncify() > 0 &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just drop the > 0 here


_wasmfs_opfs_init_root_directory__deps: ['$wasmfsOPFSDirectoryHandles', '$wasmfsOPFSProxyFinish'],
_wasmfs_opfs_init_root_directory__async: {{{ !PTHREADS }}},
_wasmfs_opfs_init_root_directory__async: 'auto',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think the issue here might be that prior to this change, the proxying for the pthread-builds was done manually in the C/C++ code.

If you land this change then you've added automatically proxying from backgroun threads, which I'm not sure you want... or at least I would expect you to be able to remove some manual proxying elsewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the proxy stuff only happens if they're also marked with __proxy?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, sorry that is correct. That concern is not valid.

What about the fact that prior to this change the pthread builds did not use aysnc, and not they do? Is that OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skimmed through jsifier, __async only seems to have an affect if ASYNCIFY is set or if pthread is enabled AND __proxy: 'sync'. I also diffed the output of the test file using 'auto' and false and they were the same.

Use the new 'auto' keyword to automatically wrap the opfs functions with
`handleAsync`.

Fixes Issue emscripten-core#23133
@brendandahl brendandahl merged commit c624110 into emscripten-core:main Mar 19, 2026
9 of 20 checks passed
@brendandahl
Copy link
Collaborator Author

Nice! I looked at trying to do something like this in #26026, but honestly I got confused by the different layers of async-ness.

I guess we can close #26026 if this lands?

Yeah, thanks for adding 'auto'!

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.

2 participants