Skip to content

Commit 82ef541

Browse files
[wasm coreclr] Make clr.runtime+libs build on Windows (#115058)
* [coreclr][wasm] Make clr.runtime+libs build on Windows * Try to enable windows build of wasm coreclr * More things required to do the right things on windows --------- Co-authored-by: Steve Pfister <[email protected]>
1 parent cb695d9 commit 82ef541

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

eng/native/configureplatform.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL haiku)
434434
set(CLR_CMAKE_TARGET_HAIKU 1)
435435
endif(CLR_CMAKE_TARGET_OS STREQUAL haiku)
436436

437-
if(CLR_CMAKE_TARGET_OS STREQUAL emscripten)
437+
if(CLR_CMAKE_TARGET_OS STREQUAL emscripten OR CLR_CMAKE_TARGET_OS STREQUAL browser)
438438
set(CLR_CMAKE_TARGET_UNIX 1)
439439
set(CLR_CMAKE_TARGET_BROWSER 1)
440440
endif(CLR_CMAKE_TARGET_OS STREQUAL emscripten)
@@ -478,7 +478,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL windows)
478478
endif()
479479

480480
# check if host & target os/arch combination are valid
481-
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_ANDROID)
481+
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER)
482482
if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows))
483483
message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}")
484484
endif()

eng/pipelines/runtime.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ extends:
123123
buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
124124
platforms:
125125
- browser_wasm
126+
- browser_wasm_win
126127
jobParameters:
127128
nameSuffix: AllSubsets_CoreCLR
128129
buildArgs: -s clr.runtime+libs -rc Release -c Release -lc $(_BuildConfig)

src/coreclr/build-runtime.cmd

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set __TargetArchArm=0
4646
set __TargetArchArm64=0
4747
set __TargetArchLoongArch64=0
4848
set __TargetArchRiscV64=0
49+
set __TargetArchWasm=0
4950

5051
set __BuildTypeDebug=0
5152
set __BuildTypeChecked=0
@@ -66,6 +67,7 @@ set __UnprocessedBuildArgs=
6667

6768
set __BuildNative=1
6869
set __RestoreOptData=1
70+
set __CrossTarget=0
6971
set __HostOS=
7072
set __HostArch=
7173
set __PgoOptDataPath=
@@ -94,6 +96,7 @@ if /i "%1" == "-arm" (set __TargetArchArm=1&shift&goto Arg_Loop)
9496
if /i "%1" == "-arm64" (set __TargetArchArm64=1&shift&goto Arg_Loop)
9597
if /i "%1" == "-loongarch64" (set __TargetArchLoongArch64=1&shift&goto Arg_Loop)
9698
if /i "%1" == "-riscv64" (set __TargetArchRiscV64=1&shift&goto Arg_Loop)
99+
if /i "%1" == "-wasm" (set __TargetArchWasm=1&shift&goto Arg_Loop)
97100

98101
if /i "%1" == "-debug" (set __BuildTypeDebug=1&shift&goto Arg_Loop)
99102
if /i "%1" == "-checked" (set __BuildTypeChecked=1&shift&goto Arg_Loop)
@@ -152,6 +155,7 @@ if /i "%1" == "-enforcepgo" (set __EnforcePgo=1&shift&goto Arg_Loop)
152155
if /i "%1" == "-pgodatapath" (set __PgoOptDataPath=%~2&set __PgoOptimize=1&shift&shift&goto Arg_Loop)
153156
if /i "%1" == "-component" (set __RequestedBuildComponents=%__RequestedBuildComponents%-%2&set "__remainingArgs=!__remainingArgs:*%2=!"&shift&shift&goto Arg_Loop)
154157
if /i "%1" == "-fsanitize" (set __CMakeArgs=%__CMakeArgs% "-DCLR_CMAKE_ENABLE_SANITIZERS=%2"&shift&shift&goto Arg_Loop)
158+
if /i "%1" == "-keepnativesymbols" (set __CMakeArgs=%__CMakeArgs% "-DCLR_CMAKE_KEEP_NATIVE_SYMBOLS=true"&shift&goto Arg_Loop)
155159

156160
REM TODO these are deprecated remove them eventually
157161
REM don't add more, use the - syntax instead
@@ -175,7 +179,7 @@ if defined VCINSTALLDIR (
175179

176180
if defined __BuildAll goto BuildAll
177181

178-
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
182+
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64 + __TargetArchWasm
179183
if %__TotalSpecifiedTargetArch% GTR 1 (
180184
echo Error: more than one build architecture specified, but "all" not specified.
181185
goto Usage
@@ -187,6 +191,7 @@ if %__TargetArchArm%==1 set __TargetArch=arm
187191
if %__TargetArchArm64%==1 set __TargetArch=arm64
188192
if %__TargetArchLoongArch64%==1 set __TargetArch=loongarch64
189193
if %__TargetArchRiscV64%==1 set __TargetArch=riscv64
194+
if %__TargetArchWasm%==1 set __TargetArch=wasm
190195
if "%__HostArch%" == "" set __HostArch=%__TargetArch%
191196

192197
set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
@@ -281,7 +286,14 @@ REM ============================================================================
281286

282287
@if defined _echo @echo on
283288

284-
if not "%__TargetOS%"=="android" (
289+
if "%__TargetOS%"=="android" (
290+
set __CrossTarget=1
291+
)
292+
if "%__TargetOS%"=="browser" (
293+
set __CrossTarget=1
294+
)
295+
296+
if %__CrossTarget% EQU 0 (
285297
call "%__RepoRootDir%\eng\native\version\copy_version_files.cmd"
286298
) else (
287299
call powershell -NoProfile -ExecutionPolicy ByPass -File "%__RepoRootDir%\eng\native\version\copy_version_files.ps1"
@@ -486,7 +498,7 @@ REM ============================================================================
486498

487499
set __TargetArchList=
488500

489-
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
501+
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64 + __TargetArchWasm
490502
if %__TotalSpecifiedTargetArch% EQU 0 (
491503
REM Nothing specified means we want to build all architectures.
492504
set __TargetArchList=x64 x86 arm arm64
@@ -504,6 +516,7 @@ if %__TargetArchArm%==1 set __TargetArchList=%__TargetArchList% arm
504516
if %__TargetArchArm64%==1 set __TargetArchList=%__TargetArchList% arm64
505517
if %__TargetArchLoongArch64%==1 set __TargetArchList=%__TargetArchList% loongarch64
506518
if %__TargetArchRiscV64%==1 set __TargetArchList=%__TargetArchList% riscv64
519+
if %__TargetArchWasm%==1 set __TargetArchList=%__TargetArchList% wasm
507520

508521
set __BuildTypeList=
509522

src/coreclr/runtime-prereqs.proj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="Sdk.props" Sdk="Microsoft.Build.NoTargets" />
33
<PropertyGroup>
44
<NativeVersionFile Condition="$([MSBuild]::IsOsPlatform(Windows))">$(ArtifactsObjDir)_version.h</NativeVersionFile>
5-
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
5+
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
66
<RuntimeVersionFile>$(ArtifactsObjDir)runtime_version.h</RuntimeVersionFile>
77
<NativeSourceLinkFile>$(ArtifactsObjDir)native.sourcelink.json</NativeSourceLinkFile>
88
<VerifySourceLinkFileExists>false</VerifySourceLinkFileExists>
@@ -16,16 +16,16 @@
1616
<Target Name="BuildPrereqs" BeforeTargets="Build" DependsOnTargets="GenerateRuntimeVersionFile;GenerateNativeSourcelinkFile" />
1717

1818
<!--
19-
This is a workaround when cross-compiling on Windows for Android.
19+
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.
2020
2121
https://github.com/dotnet/arcade/issues/15496
2222
-->
23-
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
23+
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
2424
<PropertyGroup>
2525
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
2626
</PropertyGroup>
2727
</Target>
28-
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
28+
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
2929
<PropertyGroup>
3030
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
3131
</PropertyGroup>

src/coreclr/runtime.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<PropertyGroup>
111111
<_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd</_CoreClrBuildScript>
112112
<_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh</_CoreClrBuildScript>
113-
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))"> </_CoreClrBuildPreSource>
113+
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))">&quot;$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))&quot; &amp;&amp; </_CoreClrBuildPreSource>
114114
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and !$([MSBuild]::IsOsPlatform(Windows))">source &quot;$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh&quot; &amp;&amp; </_CoreClrBuildPreSource>
115115
</PropertyGroup>
116116

src/native/corehost/corehost.proj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<IntermediateOutputRootPath>$(ArtifactsObjDir)$(OutputRID).$(Configuration)\</IntermediateOutputRootPath>
1414
<!-- Global location for version files -->
1515
<NativeVersionFile Condition="$([MSBuild]::IsOsPlatform(Windows))">$(ArtifactsObjDir)_version.h</NativeVersionFile>
16-
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
16+
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
1717
</PropertyGroup>
1818

1919
<Target Name="CopySingleFileHost" AfterTargets="Build">
@@ -92,16 +92,16 @@
9292
</Target>
9393

9494
<!--
95-
This is a workaround when cross-compiling on Windows for Android.
95+
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.
9696
9797
https://github.com/dotnet/arcade/issues/15496
9898
-->
99-
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
99+
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
100100
<PropertyGroup>
101101
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
102102
</PropertyGroup>
103103
</Target>
104-
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
104+
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
105105
<PropertyGroup>
106106
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
107107
</PropertyGroup>

src/native/libs/build-native.cmd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set __Ninja=1
2121
set __icuDir=""
2222
set __usePThreads=0
2323
set __ExtraCmakeParams=
24+
set __CrossTarget=0
2425

2526
:Arg_Loop
2627
:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing
@@ -63,7 +64,14 @@ if NOT [%errorlevel%] == [0] goto :Failure
6364
echo Commencing build of native components
6465
echo.
6566

66-
if /i not "%__TargetOS%" == "android" (
67+
if "%__TargetOS%"=="android" (
68+
set __CrossTarget=1
69+
)
70+
if "%__TargetOS%"=="browser" (
71+
set __CrossTarget=1
72+
)
73+
74+
if %__CrossTarget% EQU 0 (
6775
call "%__repoRoot%\eng\native\version\copy_version_files.cmd"
6876
) else (
6977
call powershell -NoProfile -ExecutionPolicy ByPass -File "%__repoRoot%\eng\native\version\copy_version_files.ps1"

src/native/libs/build-native.proj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<!-- Hardcode version paths in a global location. -->
44
<NativeVersionFile Condition="'$(TargetOS)' == 'windows'">$(ArtifactsObjDir)_version.h</NativeVersionFile>
5-
<NativeVersionFile Condition="'$(TargetOS)' != 'windows' or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
5+
<NativeVersionFile Condition="'$(TargetOS)' != 'windows' or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
66
<AssemblyName>.NET Runtime</AssemblyName>
77
<_BuildNativeTargetOS>$(TargetOS)</_BuildNativeTargetOS>
88
<_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic</_BuildNativeTargetOS>
@@ -77,16 +77,16 @@
7777
</Target>
7878

7979
<!--
80-
This is a workaround when cross-compiling on Windows for Android.
80+
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.
8181
8282
https://github.com/dotnet/arcade/issues/15496
8383
-->
84-
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
84+
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
8585
<PropertyGroup>
8686
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
8787
</PropertyGroup>
8888
</Target>
89-
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
89+
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
9090
<PropertyGroup>
9191
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
9292
</PropertyGroup>

0 commit comments

Comments
 (0)