Browser: php.mount() support for OPFS/Native FS handles#1470
Merged
Browser: php.mount() support for OPFS/Native FS handles#1470
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context of this PR
It enables mounting OPFS and local directory handles in the browser version of Playground using the same abstraction as we use for mounting local directories in Node.js. This, in turn, enables using OPFS mounts in the boot protocol and relying on the same general code paths and abstractions.
What's the technical change?
Ships a
DirectoryHandleMountclass that can be used to mount OPFS using thephp.mount()method:Implementation details
DirectoryHandleMount is not a "real" mount in that it doesn't actually plug in an Emscripten FS implementation into the PHP Emscripten module. Instead, it copies all the OPFS files into Playground MEMFS (or the other way around). After that initial sync, it journals all the MEMFS filesystem operations and replays them in OPFS. This is good enough for the in-browser directory handle, since the underlying files aren't going to change on their own, but for the Local Filesystem directory handle we also have an explicit "Synchronize files" button to bring any local changes back into Playground.
Once Emscripten supports asynchronous filesystem operations via wasmfs, we'll be about to get rid of the journal and mount an OPFS implementation to directly delegate writes, reads, etc to the underlying filesystem.
Other changes
This PR removes the
Mountableinterface in favor of functional API to simplify the implementation and remove any state management concerns.Before:
After:
Testing Instructions
Open local Playground and change the storage option to "browser", make some visible changes, refresh Playground a few times, confirm the site still loads and the changes are still around. Close the browser, reopen it, confirm it still works.
Them repeat the test with the local directory storage option.
Also, confirm the following Playground CLI command works and sets up a site in a local
new-wordpress-sitedirectory:bun packages/playground/cli/src/cli.ts server --mount-before-install=`pwd`/new-wordpress-site:/wordpress