Repository navigation
[wasi] Implement MksTemps/MkdTemp so GetTempFileName and CreateTempSubdirectory work - #134958
Merged
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Sep 30, 2026
Path.GetTempFileName/Directory.CreateTempSubdirectory fail because MksTemps/MkdTemp are stubbed (dotnet#134943, fix in dotnet#134958), and File.Copy fails because fchmod returns ENOSYS (dotnet#134944, fix in dotnet#134959). Quarantine at class level where the test constructor fails and at method level otherwise, so the lanes can go green before the fixes merge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Oct 1, 2026
Path.GetTempFileName/Directory.CreateTempSubdirectory fail because MksTemps/MkdTemp are stubbed (dotnet#134943, fix in dotnet#134958), and File.Copy fails because fchmod returns ENOSYS (dotnet#134944, fix in dotnet#134959). Quarantine at class level where the test constructor fails and at method level otherwise, so the lanes can go green before the fixes merge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Oct 1, 2026
Path.GetTempFileName/Directory.CreateTempSubdirectory fail because MksTemps/MkdTemp are stubbed (dotnet#134943, fix in dotnet#134958), and File.Copy fails because fchmod returns ENOSYS (dotnet#134944, fix in dotnet#134959). Quarantine at class level where the test constructor fails and at method level otherwise, so the lanes can go green before the fixes merge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Oct 2, 2026
Path.GetTempFileName/Directory.CreateTempSubdirectory fail because MksTemps/MkdTemp are stubbed (dotnet#134943, fix in dotnet#134958), and File.Copy fails because fchmod returns ENOSYS (dotnet#134944, fix in dotnet#134959). Quarantine at class level where the test constructor fails and at method level otherwise, so the lanes can go green before the fixes merge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
marked this pull request as ready for review
October 2, 2026 01:46
lewing
added a commit
that referenced
this pull request
Oct 2, 2026
) The CoreCLR WASI host (`wasihost`) initializes the runtime with only `TRUSTED_PLATFORM_ASSEMBLIES`, `APP_PATHS` and the host runtime contract. It never reads the app's runtime configuration, so none of the `configProperties` from `<app>.runtimeconfig.json` reach `AppContext`: feature switches, `RuntimeHostConfigurationOption` items and so on. For example, `System.Text.Encoding.EnableUnsafeUTF7Encoding` never arrives, so UTF-7 tests throw `NotSupportedException : Support for UTF-7 is disabled`. When trimming, `System.Data.DataSet.XmlSerializationIsSupported` is seen as missing by test `PlatformDetection`. ## Change - `src/native/corehost/wasihost/wasihost.cpp`: read `runtimeconfig.bin` from next to the entry assembly and append its properties to the init properties passed to `coreclr_initialize`. Properties the host sets itself take precedence. `get_runtime_property` already serves from the same vectors, so the contract callback returns the same values. A missing file is ignored, and a malformed one fails startup with a message. - `src/mono/wasi/build/WasiApp.CoreCLR.targets`: copy `runtimeconfig.bin` into `managed/`, next to the entry assembly, the framework, `icudt.dat` and the host. `WasiAppBuilder` places it at the bundle root, which `run-wasmtime.sh` (`cd managed && wasmtime --dir . ...`) does not preopen. `runtimeconfig.bin` is the file `RuntimeConfigParserTask` already produces for WASI apps, and Mono's WASI driver consumes the same file. Its format is an ECMA-335 compressed count followed by key/value serialized strings, so the host needs no JSON parser. The browser CoreCLR host follows the same model: `configProperties` first, with host-set properties overriding them. ## Validation Local, macOS arm64 host, wasi-sdk 33, wasmtime 45. - `./build.sh -os wasi -arch wasm -rf CoreCLR -s clr+libs+host -c Release` on clean upstream `main` → succeeded, 0 warnings, 0 errors. - `./build.sh -os wasi -arch wasm -rf CoreCLR -s host.native -c Release` with the change → succeeded; `wasihost.cpp` compiles with no warnings. **System.Text.Encoding.Tests** (untrimmed, `./dotnet.sh build src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/System.Text.Encoding.Tests.csproj -f net11.0 /t:Test /p:TargetOS=wasi /p:TargetArchitecture=wasm /p:RuntimeFlavor=CoreCLR /p:Configuration=Release`) On `main`, the full suite hangs in `TranscodingStreamTests.ReadAsync_LoopsWhenPartialDataReceived`, a blocking wait on single-threaded WASI that is handled in #134813. So I compared the UTF-7-related classes directly with wasmtime on the bundle (`-class` for EncodingMiscTests, EncodingGetEncodingTest, NegativeEncodingTests and the seven `UTF7Encoding*` classes): | | Tests run | Passed | Failed | |---|---|---|---| | Without fix | 1692 | 1654 | **38** (all `Support for UTF-7 is disabled`) | | With fix | 1720 | 1720 | **0** | Full suite with the fix, with the hanging test skipped locally only (not part of this PR): 14614 run, 14605 passed, 4 failed, 5 skipped, 0 UTF-7 failures. The 4 failures are unrelated: `FromUtf16Tests`/`ToUtf16Tests.SomeNonAsciiInput` need System.Security.Cryptography (#99126), and `TranscodingStreamTests.ReadApm`/`WriteApm` throw `PlatformNotSupportedException` from `TaskToAsyncResult.Begin`. **System.Data.Common.Tests** (untrimmed, same command with the System.Data.Common.Tests project) - With fix: 11734 run, 11658 passed, 67 failed, 9 skipped. The same bundle run with `managed/runtimeconfig.bin` removed, which reproduces the pre-fix behavior, gives the identical 67 failures. So there are no regressions. 54 of the failures are `IOException : Success : '/tmp/'` (#134958), and the rest are DbProviderFactories and serialization-guard failures unrelated to runtimeconfig. - The DataSet switch only lands in runtimeconfig when trimming, and trimmed CoreCLR-WASI test builds don't work on `main` yet (ILLink can't resolve System.Private.CoreLib; #134813 sets that up). To confirm the switch now reaches both the product and `PlatformDetection`, I added `System.Data.DataSet.XmlSerializationIsSupported=false` to the bundle's `runtimeconfig.bin` and ran `-class System.Data.Tests.DataSetTest -class System.Data.Tests.DataTableTest5`. The original config gave 63 run, 48 passed, 14 failed (`/tmp`), 1 skipped. With the switch it gave 63 run, 44 passed, 0 failed, 19 skipped: the guarded tests skip and nothing fails from a product/test mismatch. This is split out from the WASI R2R test-standup work in #134813, where the missing properties account for the 38 UTF-7 failures and about 360 System.Data.Common failures in trimmed runs. Resolves #134954 > [!NOTE] > This PR was authored with assistance from GitHub Copilot. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Oct 3, 2026
Path.GetTempFileName/Directory.CreateTempSubdirectory fail because MksTemps/MkdTemp are stubbed (dotnet#134943, fix in dotnet#134958), and File.Copy fails because fchmod returns ENOSYS (dotnet#134944, fix in dotnet#134959). Quarantine at class level where the test constructor fails and at method level otherwise, so the lanes can go green before the fixes merge. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Member
|
Re-enable tests disabled against #134943 |
wasi-libc provides neither mkstemp(s) nor mkdtemp, so on WASI these entry points were stubbed out and returned failure without setting errno. This made Path.GetTempFileName throw "IOException : Success : '/tmp/'" and broke Directory.CreateTempSubdirectory. Emulate them the way libc does: validate the template, fill the trailing XXXXXX from getentropy mapped to [A-Za-z0-9], and create the entry with open(O_CREAT|O_EXCL) / mkdir, retrying on EEXIST a bounded number of times. errno is set on every failure path. Non-WASI code paths are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove all 89 WASI quarantines against issue 134943 after the MksTemps/MkdTemp fix. Preserve unrelated attributes and test code. Keep only the independently failing user-secrets reload test quarantined against issue 135225; the rest of ConfigurationTests now runs on WASI. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
force-pushed
the
lewing-wasi-mkstemps-fix
branch
from
October 5, 2026 15:45
3515dd0 to
0e71660
Compare
This was referenced Oct 5, 2026
Member
Author
|
filed #135268 for the error |
Member
Author
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
pavelsavara
approved these changes
Oct 6, 2026
Member
Author
|
/ba-g unrelated failures are filed |
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.
wasi-libc provides neither
mkstemps/mkstempnormkdtemp. So on WASI,SystemNative_MksTempsasserted and returned-1without settingerrno, andSystemNative_MkdTempreturnedNULLthe same way. As a result,Path.GetTempFileNamethrewIOException : Success : '/tmp/', andDirectory.CreateTempSubdirectorywas also broken. The temp directory itself works fine; the only missing piece was creating a unique name in it.Change
src/native/libs/System.Native/pal_io.c, WASI only. This mirrors how libc implements these functions:GetTempNameRandomCharsvalidates the template. It requires sixXcharacters immediately before the suffix and otherwise fails witherrno = EINVAL.FillTempNameRandomCharsfills theXXXXXXfromgetentropy(backed bywasi:random), mapped to[A-Za-z0-9].SystemNative_MksTempsloops up to 100 times callingopen(path, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600). It returns the fd on success, retries onEEXIST, and returns-1witherrnopreserved on any other error. If every attempt collides, it fails witherrno = EEXIST.SystemNative_MkdTempruns the same loop withmkdir(path, 0700). It returns the template on success andNULLwitherrnoset on failure.Non-WASI native code paths are unchanged. The WASI preprocessor branch also uses
defined(TARGET_WASI). Because this lives in the shared System.Native, the fix applies to both CoreCLR and Mono on WASI.After #134813 merged, this branch was rebased onto upstream main
fa693c42fb6. It removes all 89 WASIActiveIssueattributes against #134943 across 24 test files, preserving other attributes, comments, and test code.Removing the class-wide configuration quarantine exposed a separate missing-user-profile failure. Only
ConfigurationTests.TouchingFileWillReloadForUserSecretsremains quarantined on WASI, now against #135225. No harness defaults or unrelated product code change in this PR.Validation after rebase and quarantine removal
Local macOS arm64 host, wasi-sdk 34, wasmtime via XHarness, CoreCLR WASI interpreter (not ReadyToRun). The worktree-local tool-cache override avoids modifying a concurrently used checkout.
The product command below passed with 0 warnings and 0 errors. Initially the existing CMake caches retained SDK-33 compiler paths despite selecting the SDK-34 toolchain and failed to link WASI networking symbols. Clearing only this worktree's generated WASI CoreCLR/native object directories resolved the mismatch; no source workaround was used.
All commands above exited 0. Counts were checked in the runner logs and xUnit XML:
System.ComponentModel.Composition.Testswas exercised in the interpreter lane, even though it is excluded from the trimmed WASI R2R lane (#135045).Two initial-run findings:
HOMEfailure now tracked in [wasi] Library tests have no HOME/user profile (user secrets path) #135225. A diagnostic re-run of the unquarantined bundle with guestHOME=/tmpreported 33 run, 30 passed, 0 failed, 3 skipped. The final normal-environment run after the method-only quarantine reported the 32-test result above; 27 tests inConfigurationTestsstill passed.MemoryStream_CapacityBoundaryCheckslarge-allocation test. That test already carriesSkipOnCI; forwarding the existing CI guest settingDOTNET_CI=truereproduces the interpreter CI lane and gives the passing result above. No new MemoryStream quarantine was added, and all eight re-enabled StreamReader/StreamWriter temporary-file cases passed.Original before/after reproduction
Before the test-standup merge, on the SDK-33 baseline:
The product build passed with zero warnings/errors. Stashing the native fix, rebuilding
libs.native, and running Memory.Data reproduced 87 run, 80 passed, 1 failed, 6 skipped (BinaryDataTests.CanCreateBinaryDataFromFileStream:IOException : Success : '/tmp/'). Restoring the fix, rebuildinglibs.native, and repeating the same test command passed: 87 run, 81 passed, 0 failed, 6 skipped.The per-app wasihost links
libSystem.Native.afrom the runtime pack, so the rebuilt library is what the tests use.System.Runtime.Extensions.Tests(PathTests.GetTempFileName) andSystem.IO.FileSystem.Tests(Directory_CreateTempSubdirectory) do not target WASI (-windows;-unix;-browseronly), so they were not run. Mono WASI and the ReadyToRun lane were not run.Resolves #134943
Note
This PR was authored with assistance from GitHub Copilot.