Skip to content

[browser][coreCLR] use WASMFS - #130141

Draft
pavelsavara wants to merge 2 commits into
dotnet:mainfrom
pavelsavara:wasm_fs
Draft

pavelsavara wants to merge 2 commits into
dotnet:mainfrom
pavelsavara:wasm_fs

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Enable Emscripten WASMFS for Browser/CoreCLR.
  • Move virtual filesystem writes and working-directory setup from the legacy
    JavaScript FS API to native open, mkdir, and chdir operations.
  • Configure CoreRun's Node.js filesystem bridge without linking Emscripten's
    conflicting NODERAWFS root hook.
  • Preserve /usr/share for SpecialFolder.CommonApplicationData and propagate
    native working-directory setup failures.
  • Update the directory component-length tests to distinguish Mono's MEMFS
    behavior from CoreCLR's WASMFS behavior.

Testing

  • .\build.cmd -bl -os browser -subset clr+libs+host -c Debug /p:RuntimeFlavor=CoreCLR
    • Passed with 0 warnings and 0 errors.
  • .\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Debug /p:RuntimeFlavor=CoreCLR /t:RunSample src\mono\sample\wasm\console-node
    • Passed and produced the expected Hello World! output.
  • .\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Debug /p:RuntimeFlavor=CoreCLR /t:Test /p:Scenario=WasmTestOnChrome /p:InstallChromeForTests=false /p:XUnitClassName=System.IO.Tests.Directory_CreateDirectory .\src\libraries\System.Runtime\tests\System.IO.FileSystem.Tests\System.IO.FileSystem.Tests.csproj
    • Passed: 94 run, 88 passed, 6 conditionally skipped, 0 failed.
    • All seven overlong-component WASMFS cases passed; the Mono-only inverse
      case was skipped.
  • FilesToIncludeInFileSystemTests was not completed locally because
    VBCSCompiler held hostfxr.dll open while the workload SDK was being
    reinstalled.

Note

This pull request description was generated with GitHub Copilot.

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jul 2, 2026
@pavelsavara pavelsavara self-assigned this Jul 2, 2026
Copilot AI review requested due to automatic review settings July 2, 2026 20:54
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm labels Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR shifts the browser/CoreCLR WASM stack toward using Emscripten WASMFS by moving VFS population and working-directory setup from the JavaScript FS.* APIs into native open/mkdir/chdir-based helpers, and adjusts WASM platform I/O behavior accordingly.

Changes:

  • Update System.Native WASM behavior: trust browser/WASMFS dirent.d_type, treat WASI as unreliable, and avoid O_NOCTTY on WASM where WASMFS rejects unknown flags.
  • Replace JS-side FS.createPath/createDataFile/chdir usage with new native exports (BrowserHost_WriteFileToVfs, BrowserHost_SetWorkingDirectory) and corresponding TS type updates.
  • Enable WASMFS in the native build, add a WASMFS root override for corerun (node/shell path), and export emscripten_stack_get_current where needed.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/native/libs/System.Native/pal_io.c Adjust WASM dirent d_type handling and skip O_NOCTTY on WASM to match WASMFS constraints.
src/native/libs/System.Native.Browser/native/index.ts Remove JS-side working directory creation/chdir from preInit.
src/native/libs/System.Native.Browser/libSystem.Native.Browser.Utils.footer.js Add emscripten_stack_get_current as an explicit dependency.
src/native/libs/Common/JavaScript/types/internal.ts Extend module internal typing with onRuntimeInitialized.
src/native/libs/Common/JavaScript/types/ems-ambient.ts Add ambient typings for new BrowserHost exports; remove typed FS surface.
src/native/libs/Common/JavaScript/host/host.ts Call native working-directory setter during CoreCLR initialization.
src/native/libs/Common/JavaScript/host/assets.ts Route VFS file installation/PDB registration through native file-write export.
src/native/corehost/browserhost/libBrowserHost.footer.js Export new BrowserHost entrypoints for file write + working directory.
src/native/corehost/browserhost/browserhost.cpp Implement native VFS write and working-directory setup using open/mkdir/chdir.
src/coreclr/hosts/corerun/wasm/wasmfs_root_override.cpp Provide WASMFS root backend override (node backend).
src/coreclr/hosts/corerun/wasm/libCorerun.js Add emscripten_stack_get_current dependency for corerun wasm JS library.
src/coreclr/hosts/corerun/wasm/corerun.html Update corerun browser sample invocation (args/core-root).
src/coreclr/hosts/corerun/CMakeLists.txt Wire in WASMFS root override for node/shell corerun builds and remove NODERAWFS link option.
eng/native/configureplatform.cmake Enable WASMFS link options for CoreCLR browser builds.
eng/native.wasm.targets Export _emscripten_stack_get_current from the WASM build.

Comment on lines +19 to +21
const workingDirPtr = _ems_.dotnetBrowserUtilsExports.stringToUTF8Ptr(loaderConfig.virtualWorkingDirectory!) as any;
_ems_._BrowserHost_SetWorkingDirectory(workingDirPtr);
_ems_._free(workingDirPtr);
Comment on lines +195 to +204
extern "C" int BrowserHost_WriteFileToVfs(const char* path, const void* data, int32_t length)
{
BrowserHost_EnsureParentDirs(path);

int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
if (fd < 0)
{
std::fprintf(stderr, "BrowserHost_WriteFileToVfs: open('%s') failed - errno %d\n", path, errno);
return -1;
}
Copilot AI review requested due to automatic review settings July 7, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comment on lines 17 to +22
const loaderConfig = _ems_.dotnetApi.getConfig();

const workingDirPtr = _ems_.dotnetBrowserUtilsExports.stringToUTF8Ptr(loaderConfig.virtualWorkingDirectory!) as any;
_ems_._BrowserHost_SetWorkingDirectory(workingDirPtr);
_ems_._free(workingDirPtr);

Comment on lines +230 to 233
[ConditionalTheory(typeof(Directory_CreateDirectory), nameof(NoMaxComponentLength))]
[MemberData(nameof(PathsWithComponentLongerThanMaxComponent))]
public void DirectoryWithComponentLongerThanMaxComponentAsPath_BrowserDoesNotThrowException(string path)
{
Remove the remaining legacy JavaScript filesystem dependencies and propagate
native working-directory setup failures. Avoid linking Emscripten's NODERAWFS
root hook when CoreRun provides its own root mapping.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants