Skip to content

Commit 52e2158

Browse files
marafCopilot
andcommitted
Implement CoreCLR browser-wasm native build targets
Replace placeholder 'not implemented' targets in BrowserWasmApp.CoreCLR.targets with a working implementation that copies pre-built native files from the runtime pack. Unlike Mono which re-links dotnet.native.wasm per-app via emcc, CoreCLR pre-links it once during the runtime build (corehost.proj). Changes: - Import WasmApp.Common.props/targets for shared WasmBuildApp chain - Set WasmBuildNative=false to skip per-app emcc compile/link - Override _SetupToolchain to mark emscripten as unavailable (no src/ dir in CoreCLR runtime pack) - Add _CoreCLRBrowserCopyNativeAssets target to copy dotnet.native.wasm/js from runtime pack and register as WasmNativeAsset items for SDK bundling - Add DotNetCoreWeb ProjectCapability for VS debugging support Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 23bc7e3 commit 52e2158

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed
Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
11
<Project>
2-
<!-- TODO-WASM: These targets are invoked by public WasmSDK -->
3-
<Target Name="WasmBuildApp">
4-
<Message Importance="high" Text="WasmBuildApp for CoreCLR not implemented" />
2+
<!--
3+
CoreCLR browser-wasm app build targets.
4+
5+
Unlike Mono, CoreCLR pre-links dotnet.native.wasm once during the runtime build (via corehost.proj).
6+
The pre-built native files (dotnet.native.wasm, dotnet.native.js, etc.) are already in the runtime pack.
7+
This targets file imports the shared WasmApp.Common.targets infrastructure but skips per-app emcc
8+
compile/link by setting WasmBuildNative=false and marking the Emscripten toolchain as unavailable.
9+
-->
10+
11+
<Import Project="$(WasmCommonTargetsPath)WasmApp.Common.targets" />
12+
13+
<ItemGroup>
14+
<!-- Allow running/debugging from VS -->
15+
<ProjectCapability Include="DotNetCoreWeb" />
16+
</ItemGroup>
17+
18+
<!--
19+
Override _SetupToolchain to mark the Emscripten toolchain as missing.
20+
CoreCLR does not need emcc for app builds since native linking is done at runtime build time.
21+
This skips _ReadWasmProps (which reads wasm-props.json from a src/ dir that doesn't exist for CoreCLR)
22+
and all emcc-related targets.
23+
-->
24+
<Target Name="_SetupToolchain">
25+
<PropertyGroup>
26+
<_IsToolchainMissing>true</_IsToolchainMissing>
27+
</PropertyGroup>
528
</Target>
6-
<Target Name="WasmTriggerPublishApp">
7-
<Message Importance="high" Text="WasmTriggerPublishApp for CoreCLR not implemented" />
29+
30+
<!--
31+
Copy pre-built native files from the runtime pack to the intermediate output path,
32+
and register them as WasmNativeAsset items so the WebAssembly SDK can include them
33+
in the app bundle (boot JSON, static web assets, etc.).
34+
-->
35+
<Target Name="_CoreCLRBrowserCopyNativeAssets"
36+
AfterTargets="PrepareInputsForWasmBuild"
37+
Condition="'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)' != ''">
38+
<ItemGroup>
39+
<_CoreCLRNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.wasm" />
40+
<_CoreCLRNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js" />
41+
<_CoreCLRNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js.symbols"
42+
Condition="Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js.symbols')" />
43+
<_CoreCLRNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs"
44+
Condition="Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs')" />
45+
</ItemGroup>
46+
47+
<Copy SourceFiles="@(_CoreCLRNativeAsset)"
48+
DestinationFolder="$(_WasmIntermediateOutputPath)"
49+
SkipUnchangedFiles="true" />
50+
51+
<ItemGroup>
52+
<WasmNativeAsset Include="@(_CoreCLRNativeAsset->'$(_WasmIntermediateOutputPath)%(FileName)%(Extension)')" />
53+
</ItemGroup>
854
</Target>
9-
</Project>
55+
</Project>

src/mono/browser/build/WasmApp.InTree.props

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
<Import Sdk="Microsoft.NET.Sdk.WebAssembly" Project="Sdk.props" Condition="'$(UsingNativeAOT)' != 'true' and '$(UsingMicrosoftNETSdkWebAssembly)' == 'true'" />
1515
<Import Project="$(MSBuildThisFileDirectory)BrowserWasmApp.props" Condition="'$(UsingNativeAOT)' != 'true' and '$(RuntimeFlavor)' == 'Mono'" />
1616

17-
<!-- TODO-WASM https://github.com/dotnet/runtime/issues/120248 (CoreCLR on wasm defaults) -->
17+
<!-- CoreCLR on browser-wasm: import common props for shared WasmBuildApp chain definitions -->
18+
<Import Project="$(WasmCommonTargetsPath)WasmApp.Common.props" Condition="'$(UsingNativeAOT)' != 'true' and '$(RuntimeFlavor)' == 'CoreCLR'" />
1819
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
1920
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
2021
<WasmEnableWebcil>false</WasmEnableWebcil>
22+
<!-- CoreCLR pre-links dotnet.native.wasm during the runtime build (corehost.proj).
23+
No per-app emcc compile/link is needed. -->
24+
<WasmBuildNative>false</WasmBuildNative>
2125
</PropertyGroup>
2226

2327
<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsOutputTypeLibrary)' == 'true'">

0 commit comments

Comments
 (0)