Repository navigation
Commit 6caab30
[wasi] Pass runtimeconfig properties to the runtime in wasihost (#134964)
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 <[email protected]>1 parent fcaee07 commit 6caab30
2 files changed
Lines changed: 117 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
220 | 226 | | |
221 | 227 | | |
222 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
161 | 266 | | |
162 | 267 | | |
163 | 268 | | |
| |||
248 | 353 | | |
249 | 354 | | |
250 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
251 | 362 | | |
252 | 363 | | |
253 | 364 | | |
| |||
0 commit comments