[wasi] Add CoreCLR-WASI corehost (wasihost)#130816
Merged
Merged
Conversation
Stand up a proper, statically-linked corehost for the CoreCLR-WASI library-test leg, mirroring browserhost and the static apphost, so the leg can run on a shipping host archive instead of relinking the coreclr-internal corerun. corerun keeps its role for CoreCLR runtime tests. New src/native/corehost/wasihost/ produces libWasiHost.a (OUTPUT_NAME WasiHost), a self-contained STATIC host archive installed to sharedFramework. It is linked per-app (whole-archive) by WasiApp.CoreCLR.targets together with the runtime-pack static libraries and the app-generated P/Invoke callhelpers. The host is thin (browserhost-style): it builds the CoreCLR init properties from CORE_ROOT, sets host_runtime_contract.pinvoke_override to the app-generated callhelpers_pinvoke_override (coreclr_initialize forwards it to PInvokeOverride::SetPInvokeOverride, the same registration corerun performs), preloads icudt.dat via a weak GlobalizationNative_LoadICUData, and runs coreclr_initialize / coreclr_execute_assembly with a real wasi:cli/run main(). It reuses the corerun pal header for CORE_ROOT/TPA/path handling so assembly discovery stays identical to the corerun-based host. Build enablement: - corehost/CMakeLists.txt: add a CLR_CMAKE_TARGET_WASI branch that builds only wasihost (no hostmisc dependency). - corehost.proj: acquire the wasi-sdk and pass WASI_SDK_PATH to the native build; stage libWasiHost.a into the runtime pack native dir. - eng/liveBuilds.targets: package libWasiHost.a from HostSharedFrameworkDir for wasi CoreCLR (mirrors the browser libBrowserHost.a entry). - Directory.Build.props: add the libWasiHost.a platform manifest entry. Foundation host for the CoreCLR-WASI library-test leg (dotnet#130745). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 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
There was a problem hiding this comment.
Pull request overview
Adds a new CoreCLR-WASI “thin” corehost, wasihost, built as a static archive (libWasiHost.a) and packaged/staged so CoreCLR-WASI library-test apps can link against a shipping host archive (mirroring the browserhost static host model).
Changes:
- Introduces
src/native/corehost/wasihost/(C++ host + CMake/configure glue) producinglibWasiHost.a. - Updates corehost build wiring for WASI to build
wasihost(instead of the full host stack) and stagelibWasiHost.ainto the runtime pack native directory. - Updates packaging/manifest inputs so
libWasiHost.ais shipped for WASI CoreCLR (excluding the runtime-tests Helix flavor, matching browserhost handling).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/native/corehost/wasihost/wasihost.cpp | New WASI CoreCLR host implementation (CORE_ROOT-based properties, runtime contract, ICU preload, execute/shutdown, exit marker). |
| src/native/corehost/wasihost/CMakeLists.txt | Builds and installs WasiHost-Static as libWasiHost.a, reusing corerun PAL header. |
| src/native/corehost/wasihost/configure.cmake | Generates config.h needed by shared corerun PAL header feature checks. |
| src/native/corehost/wasihost/config.h.in | Template for generated config.h used by corerun PAL header. |
| src/native/corehost/corehost.proj | Acquires WASI SDK for corehost build; stages libWasiHost.a into runtime pack native dir. |
| src/native/corehost/CMakeLists.txt | Adds a WASI-specific branch to build only wasihost. |
| src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props | Adds libWasiHost.a to the platform manifest file entries for WASI. |
| eng/liveBuilds.targets | Includes libWasiHost.a in WASI CoreCLR runtime pack inputs (excluding runtime-tests builds). |
The runtime contract must remain valid for the process lifetime (the runtime may call back through it any time after coreclr_initialize), and its address is handed to the runtime via HOST_RUNTIME_CONTRACT. Storing it in automatic storage risked use-after-scope under refactoring; make it static, mirroring browserhost. Addresses PR review feedback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
The initial comments read like a design doc. Cut narration and redundant explanation, keeping only the non-obvious rationale (contract wiring, weak ICU symbol, mangled callhelper decl, static lifetime). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
…-loud copy - wasihost.cpp: build the entry-assembly argument slice as a std::vector<const char*> instead of casting char** to const char**. - corehost.proj: pass WASI_SDK_PATH to the Windows corehost build too (BuildCoreHostOnWindows), not just the Unix path. - corehost.proj: drop the Exists() guard on CopyWasiNativeFiles so a missing libWasiHost.a fails the build (like browser's CopyWasmNativeFiles) rather than silently yielding an incomplete runtime pack. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
pavelsavara
reviewed
Jul 15, 2026
… app dir - Remove the SystemInteropJS_* linker stubs: the wasi libcoreclr_static.a does not reference them (verified with llvm-nm; they exist in corerun only because it is shared with the browser build). Relink + run confirmed unaffected. - Replace the CORE_ROOT-empty fallback (which used get_exe_path, itself synthesized from CORE_ROOT on wasi and thus circular) with a default to the entry assembly's directory, since the wasi bundle co-locates the framework with the app. CORE_ROOT remains an optional override. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
- CopyWasiNativeFiles: depend on both BuildCoreHostOnUnix and BuildCoreHostOnWindows (one is skipped by its HostOS condition) instead of $(CopyWasmNativeFilesDependsOn), which selects the Unix target for wasi and would leave the copy unordered against the host build on a Windows host. - Replace references to the not-yet-present src/mono/wasi/build/WasiApp.CoreCLR.targets path (it lands with the consumer leg) with "the CoreCLR-WASI app builder". Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
lewing
marked this pull request as ready for review
July 16, 2026 17:49
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
icudt.dat is a framework asset staged with the framework (where CORE_ROOT points), so preload it from core_root rather than app_path. These are the same directory in the default bundle, but if CORE_ROOT is set to a different directory than the entry assembly, loading from app_path would miss the data and silently fall back to invariant. Addresses PR review. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
- Use the canonical HOST_PROPERTY_TRUSTED_PLATFORM_ASSEMBLIES /
HOST_PROPERTY_APP_PATHS macros instead of string literals, matching the
rest of corehost.
- Initialize host_runtime_contract with { sizeof, nullptr } and assign the
used callbacks by name (like browserhost) so a future field
add/reorder can't silently mis-wire the function pointers.
Addresses PR review.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0e95d46c-7a1d-4aee-87a7-ef681e7347cc
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
akoeplinger
approved these changes
Jul 16, 2026
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Jul 16, 2026
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Jul 16, 2026
…library-test leg Adapt the CoreCLR-WASI library-test leg to build off the wasihost corehost PR (dotnet#130816). Both PRs produced libWasiHost.a in the runtime pack native dir; dotnet#130816 supplies it from a proper, statically-linked corehost (src/native/corehost/wasihost), so this leg no longer needs to manufacture its own host from corerun. - corerun/CMakeLists.txt: drop the WasiHost-Static target (libWasiHost.a now comes from the wasihost corehost). - corerun.cpp: revert the wasi ICU preload + weak GlobalizationNative_LoadICUData decl; wasihost.cpp loads icudt.dat from CORE_ROOT. - Directory.Build.props: drop the duplicate libWasiHost.a platform-manifest entry (dotnet#130816 adds it in the wasi-specific section). - WasiApp.CoreCLR.targets: the per-app link already links the pack's libWasiHost.a; remove the dead WasiCoreCLRRelinkCoreRun opt-out and the _WasiCopyPrebuiltCoreRun fallback (there is no prebuilt corerun executable in the wasi CoreCLR runtime pack), and update comments to describe linking the shipping wasihost archive. - Refresh corerun/relink wording in the WASI app-builder and test/CI wiring comments to reflect the wasihost host. The per-app native link (ManagedToNativeGenerator -> compile callhelpers -> link libWasiHost.a + runtime-pack static libs + app callhelper .o via wasm-component-ld) is unchanged and matches the link dotnet#130816 validated. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f00a53c8-f7ba-4417-8ea6-30d0a1507a81
lewing
enabled auto-merge (squash)
July 16, 2026 22:16
Open
3 tasks
This was referenced Jul 17, 2026
Member
Author
|
/ba-g naot timeouts are constant |
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Jul 17, 2026
…library-test leg Adapt the CoreCLR-WASI library-test leg to build off the wasihost corehost PR (dotnet#130816). Both PRs produced libWasiHost.a in the runtime pack native dir; dotnet#130816 supplies it from a proper, statically-linked corehost (src/native/corehost/wasihost), so this leg no longer needs to manufacture its own host from corerun. - corerun/CMakeLists.txt: drop the WasiHost-Static target (libWasiHost.a now comes from the wasihost corehost). - corerun.cpp: revert the wasi ICU preload + weak GlobalizationNative_LoadICUData decl; wasihost.cpp loads icudt.dat from CORE_ROOT. - Directory.Build.props: drop the duplicate libWasiHost.a platform-manifest entry (dotnet#130816 adds it in the wasi-specific section). - WasiApp.CoreCLR.targets: the per-app link already links the pack's libWasiHost.a; remove the dead WasiCoreCLRRelinkCoreRun opt-out and the _WasiCopyPrebuiltCoreRun fallback (there is no prebuilt corerun executable in the wasi CoreCLR runtime pack), and update comments to describe linking the shipping wasihost archive. - Refresh corerun/relink wording in the WASI app-builder and test/CI wiring comments to reflect the wasihost host. The per-app native link (ManagedToNativeGenerator -> compile callhelpers -> link libWasiHost.a + runtime-pack static libs + app callhelper .o via wasm-component-ld) is unchanged and matches the link dotnet#130816 validated. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f00a53c8-f7ba-4417-8ea6-30d0a1507a81
lewing
added a commit
that referenced
this pull request
Jul 21, 2026
#130745) Draft. Stands up a CoreCLR-WASI library-test leg (smoke scope: `System.Runtime.Tests`), addressing part of #130129. Builds on the CoreCLR-WASI `wasihost` corehost (#130816, merged), which ships `libWasiHost.a` in the runtime pack. This PR generates each test's own reverse P/Invoke thunks and links them into that host per-app. ## What this does Adds a per-app native link of the shipping `wasihost` corehost (`libWasiHost.a`) so a test's own `[UnmanagedCallersOnly]` reverse P/Invoke thunks are covered — mirroring the browser-CoreCLR relink. The baked callhelpers table (`libcoreclr_gen_static.a`) only covers framework top-level UCO callbacks; library/test callbacks (e.g. a nested `WindowsUILanguageHelper.EnumUiLanguagesCallback`) are unknown to it and trap at first use without the per-app link. - **Host**: consumes `libWasiHost.a` from the `wasihost` corehost (#130816) — the leg does not manufacture its own host. - **Per-app link** (`src/mono/wasi/build/WasiApp.CoreCLR.targets`): `ManagedToNativeGenerator` (TargetOS=wasi) → compile the generated callhelpers with the wasi-sdk clang → link `libWasiHost.a` from the runtime-pack static archives + the app callhelper `.o` (replacing `libcoreclr_gen_static.a`) via `wasm-component-ld`. The `wasi:http` import that `System.Net.*` pulls in is declared with `-Wl,--component-type` (`WasiHttpWorld_component_type.wit`, as Mono does); wasmtime is given `-S http` by the test targets. - **Generator** (`ManagedToNativeGenerator.cs` / `PInvokeTableGenerator.cs`): a `WarnOnUnresolvedPInvokeModules` flag downgrades `WASM0066` to a message for untrimmed library-test closures (whose foreign-platform P/Invokes are unresolved on wasm and never called), so they don't fail the build under warn-as-error. - **Test/CI wiring**: `tests.wasi.targets`, `sendtohelix-wasi.targets`, `tests.proj` smoke set, and a `wasi-wasm-coreclr-library-tests` CI template (non-gating, rolling). The leg runs with full ICU globalization (non-invariant): the `wasihost` corehost preloads `icudt.dat` from `CORE_ROOT`. ## Validation Locally (macOS arm64, wasi-sdk + wasmtime): the baseline (`clr+libs+host+packs -os wasi -c Release`) builds green and stages `libWasiHost.a` from the `wasihost` corehost into the runtime pack. The `System.Runtime.Tests` bundle links the host per-app and discovers + runs the full suite: ``` Discovered: managed/System.Runtime.Tests.dll (found 9966 of 9966 test cases) Starting: managed/System.Runtime.Tests.dll ``` Managed exception dispatch through the interpreter EH + reverse UCO thunks works with no precode assert. A `System.Tests.VersionTests` subset ran 251/251 passing (`WASM EXIT 0`). ## Relationship to other work - **#130816** (merged) — the `wasihost` corehost this leg links. - **#130740** (merged) — the nested-UCO thunk-key generator fix the interpreter needs to resolve nested reverse thunks. - **#130634** stays scoped to the R2R `call_indirect` path (not this pure-interpreter leg). ## Tracked follow-ups (not in this PR) - **#130742** — build-switchable `wasi:http` capability (no-http vs http-capable host), and the longer-term "statify the app-declared imports" direction. - **#130739** — token-based reverse-thunk key robustness. - **#128362** — relocate `coreclr_compat.h` to a neutral shared location + stage the vm/minipal headers and the wit for out-of-tree/Helix runs (the per-app link currently uses in-repo fallbacks in-tree). - Polish: `-Wl,-u,__main_void` in place of `--whole-archive`, and incremental `Inputs`/`Outputs` on the link target. > [!NOTE] > This pull request was authored with GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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] Add CoreCLR-WASI corehost (wasihost)
Summary
Adds a proper, statically-linked corehost for the CoreCLR-WASI library-test leg, under
src/native/corehost/wasihost/, mirroringbrowserhostand the staticapphost. This lets theCoreCLR-WASI library-test leg run on a shipping host archive (
libWasiHost.a) instead ofrelinking the coreclr-internal
corerun.corerunkeeps its role for CoreCLR runtime tests.This is the foundation host for the CoreCLR-WASI library-test leg (#130745) — per @pavelsavara's
review there ("we should manufacture proper corehost for this ... similar as browserhost or apphost -
statically linked").
What it does
src/native/corehost/wasihost/produceslibWasiHost.a(OUTPUT_NAMEWasiHost), a self-containedSTATIC host archive installed to
sharedFramework. It is linked per-app (whole-archive, somain/_startare pulled) by the CoreCLR-WASI app builder together with the runtime-pack staticlibraries and the app-generated P/Invoke callhelpers.
The host is thin (browserhost-style, not hostfxr/hostpolicy):
CORE_ROOT.host_runtime_contract.pinvoke_overrideto the app-generatedcallhelpers_pinvoke_override.coreclr_initializeforwards this toPInvokeOverride::SetPInvokeOverride(..., RuntimeConfiguration)— the sanctioned host↔runtime P/Invoke override interface, the same registration
corerunperformsinternally. This keeps the archive self-contained (no coreclr
contract.h/specstrings.hdrag-in).icudt.datvia a weakGlobalizationNative_LoadICUData(skipped for invariant relinks).coreclr_initialize/coreclr_execute_assemblywith a realwasi:cli/runmain().WASM EXIT <n>marker underDOTNET_WASI_PRINT_EXIT_CODE=1(untilexit-with-code,stable in WASI 0.3, is reachable from a wasip2 target).
It reuses the
corerunpal header forCORE_ROOT/TPA/path handling so assembly discovery isbyte-identical to the corerun-based host.
Build enablement / packaging
corehost/CMakeLists.txt: newCLR_CMAKE_TARGET_WASIbranch that builds onlywasihost(nohostmiscdependency — the archive is self-contained), so wasi no longer falls into the fullapphost/fxr/hostpolicy branch.
corehost.proj: acquire the wasi-sdk and passWASI_SDK_PATHto the native build; stagelibWasiHost.ainto the runtime pack native dir (CopyWasiNativeFiles, mirroring browser'sCopyWasmNativeFiles).eng/liveBuilds.targets: packagelibWasiHost.afrom$(HostSharedFrameworkDir)for wasi CoreCLR(mirrors the browser
libBrowserHost.aentry; excluded from the runtime-tests build like browser).Directory.Build.props: add thelibWasiHost.aplatform manifest entry.Validation
./build.sh -s host.native -os wasi -c Release— 0 warnings / 0 errors; installs toHostSharedFrameworkDir.__main_argc_argvdefined (whole-archive entry),coreclr_*and theC++-mangled
callhelpers_pinvoke_overrideundefined (relink-provided),GlobalizationNative_LoadICUDataweak, JS-interop stubs defined.
System.Runtime.Testsagainst this archive (non-invariant, full ICU) withwasm-component-ld→ valid wasm component; under wasmtime it initializes CoreCLR, discovers all9930 test cases, and executes tests (a
System.Tests.VersionTestssubset ran 251/251 passing,WASM EXIT 0).Consumer
Paired with the CoreCLR-WASI library-test leg in #130745, which will flip its per-app relink from the
corerun static archive to this host-built
libWasiHost.aonce this lands.Note
This PR (code and description) was authored with GitHub Copilot.