Skip to content

[wasm coreclr] Make clr.runtime+libs build on Windows #115058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL haiku)
set(CLR_CMAKE_TARGET_HAIKU 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL haiku)

if(CLR_CMAKE_TARGET_OS STREQUAL emscripten)
if(CLR_CMAKE_TARGET_OS STREQUAL emscripten OR CLR_CMAKE_TARGET_OS STREQUAL browser)
Copy link
Member

@akoeplinger akoeplinger Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? I think we should be using emscripten here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run build.cmd -os browser, the CLR_CMAKE_TARGET_OS is set to browser. Where is CLR_CMAKE_TARGET_OS set to emscripten? Maybe we should make it work similar on coreclr then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emscripten toolchain sets CMAKE_SYSTEM_NAME to 'emscripten' and CLR_CMAKE_HOST_OS will pick that up by default. In mono, we aren't fully integrated with configureplatform.cmake and so we don't pass CLR_CMAKE_TARGET_OS like coreclr does. If it's not specified, it'll take the value of CLR_CMAKE_HOST_OS and that is 'emscripten'.

I think it might be better to set CLR_CMAKE_TARGET_OS to 'browser' in mono and let coreclr act normally.

set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_BROWSER 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL emscripten)
Expand Down Expand Up @@ -478,7 +478,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL windows)
endif()

# check if host & target os/arch combination are valid
if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) AND NOT CLR_CMAKE_TARGET_WASI AND NOT CLR_CMAKE_TARGET_ANDROID)
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)
if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows))
message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}")
endif()
Expand Down
1 change: 1 addition & 0 deletions eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extends:
buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
platforms:
- browser_wasm
- browser_wasm_win
jobParameters:
nameSuffix: AllSubsets_CoreCLR
buildArgs: -s clr.runtime+libs -rc Release -c Release -lc $(_BuildConfig)
Expand Down
19 changes: 16 additions & 3 deletions src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set __TargetArchArm=0
set __TargetArchArm64=0
set __TargetArchLoongArch64=0
set __TargetArchRiscV64=0
set __TargetArchWasm=0

set __BuildTypeDebug=0
set __BuildTypeChecked=0
Expand All @@ -66,6 +67,7 @@ set __UnprocessedBuildArgs=

set __BuildNative=1
set __RestoreOptData=1
set __CrossTarget=0
set __HostOS=
set __HostArch=
set __PgoOptDataPath=
Expand Down Expand Up @@ -94,6 +96,7 @@ if /i "%1" == "-arm" (set __TargetArchArm=1&shift&goto Arg_Loop)
if /i "%1" == "-arm64" (set __TargetArchArm64=1&shift&goto Arg_Loop)
if /i "%1" == "-loongarch64" (set __TargetArchLoongArch64=1&shift&goto Arg_Loop)
if /i "%1" == "-riscv64" (set __TargetArchRiscV64=1&shift&goto Arg_Loop)
if /i "%1" == "-wasm" (set __TargetArchWasm=1&shift&goto Arg_Loop)

if /i "%1" == "-debug" (set __BuildTypeDebug=1&shift&goto Arg_Loop)
if /i "%1" == "-checked" (set __BuildTypeChecked=1&shift&goto Arg_Loop)
Expand Down Expand Up @@ -152,6 +155,7 @@ if /i "%1" == "-enforcepgo" (set __EnforcePgo=1&shift&goto Arg_Loop)
if /i "%1" == "-pgodatapath" (set __PgoOptDataPath=%~2&set __PgoOptimize=1&shift&shift&goto Arg_Loop)
if /i "%1" == "-component" (set __RequestedBuildComponents=%__RequestedBuildComponents%-%2&set "__remainingArgs=!__remainingArgs:*%2=!"&shift&shift&goto Arg_Loop)
if /i "%1" == "-fsanitize" (set __CMakeArgs=%__CMakeArgs% "-DCLR_CMAKE_ENABLE_SANITIZERS=%2"&shift&shift&goto Arg_Loop)
if /i "%1" == "-keepnativesymbols" (set __CMakeArgs=%__CMakeArgs% "-DCLR_CMAKE_KEEP_NATIVE_SYMBOLS=true"&shift&goto Arg_Loop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use #114466 for that instead.

Copy link
Member Author

@radekdoulik radekdoulik Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way it is useful when you run the build-runtime scripts directly, to have faster roundtrip of runtime build. The build-runtime.sh already has this option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the batch gods are happy as the build fails locally for me with the ever clear The system cannot find the path specified.. The command line processing in this batch file can be brittle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you call it? It worked fine for me.

I will enable windows build on CI to see if it works there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.\build.cmd -Subset clr+libs -os browser -arch wasm


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

if defined __BuildAll goto BuildAll

set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64 + __TargetArchWasm
if %__TotalSpecifiedTargetArch% GTR 1 (
echo Error: more than one build architecture specified, but "all" not specified.
goto Usage
Expand All @@ -187,6 +191,7 @@ if %__TargetArchArm%==1 set __TargetArch=arm
if %__TargetArchArm64%==1 set __TargetArch=arm64
if %__TargetArchLoongArch64%==1 set __TargetArch=loongarch64
if %__TargetArchRiscV64%==1 set __TargetArch=riscv64
if %__TargetArchWasm%==1 set __TargetArch=wasm
if "%__HostArch%" == "" set __HostArch=%__TargetArch%

set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease
Expand Down Expand Up @@ -281,7 +286,14 @@ REM ============================================================================

@if defined _echo @echo on

if not "%__TargetOS%"=="android" (
if "%__TargetOS%"=="android" (
set __CrossTarget=1
)
if "%__TargetOS%"=="browser" (
set __CrossTarget=1
)

if %__CrossTarget% EQU 0 (
call "%__RepoRootDir%\eng\native\version\copy_version_files.cmd"
) else (
call powershell -NoProfile -ExecutionPolicy ByPass -File "%__RepoRootDir%\eng\native\version\copy_version_files.ps1"
Expand Down Expand Up @@ -486,7 +498,7 @@ REM ============================================================================

set __TargetArchList=

set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64
set /A __TotalSpecifiedTargetArch=__TargetArchX64 + __TargetArchX86 + __TargetArchArm + __TargetArchArm64 + __TargetArchLoongArch64 + __TargetArchRiscV64 + __TargetArchWasm
if %__TotalSpecifiedTargetArch% EQU 0 (
REM Nothing specified means we want to build all architectures.
set __TargetArchList=x64 x86 arm arm64
Expand All @@ -504,6 +516,7 @@ if %__TargetArchArm%==1 set __TargetArchList=%__TargetArchList% arm
if %__TargetArchArm64%==1 set __TargetArchList=%__TargetArchList% arm64
if %__TargetArchLoongArch64%==1 set __TargetArchList=%__TargetArchList% loongarch64
if %__TargetArchRiscV64%==1 set __TargetArchList=%__TargetArchList% riscv64
if %__TargetArchWasm%==1 set __TargetArchList=%__TargetArchList% wasm

set __BuildTypeList=

Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/runtime-prereqs.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="Sdk.props" Sdk="Microsoft.Build.NoTargets" />
<PropertyGroup>
<NativeVersionFile Condition="$([MSBuild]::IsOsPlatform(Windows))">$(ArtifactsObjDir)_version.h</NativeVersionFile>
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
<RuntimeVersionFile>$(ArtifactsObjDir)runtime_version.h</RuntimeVersionFile>
<NativeSourceLinkFile>$(ArtifactsObjDir)native.sourcelink.json</NativeSourceLinkFile>
<VerifySourceLinkFileExists>false</VerifySourceLinkFileExists>
Expand All @@ -16,16 +16,16 @@
<Target Name="BuildPrereqs" BeforeTargets="Build" DependsOnTargets="GenerateRuntimeVersionFile;GenerateNativeSourcelinkFile" />

<!--
This is a workaround when cross-compiling on Windows for Android.
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.

https://github.com/dotnet/arcade/issues/15496
-->
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
</PropertyGroup>
</Target>
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<PropertyGroup>
<_CoreClrBuildScript Condition="$([MSBuild]::IsOsPlatform(Windows))">build-runtime.cmd</_CoreClrBuildScript>
<_CoreClrBuildScript Condition="!$([MSBuild]::IsOsPlatform(Windows))">build-runtime.sh</_CoreClrBuildScript>
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))"> </_CoreClrBuildPreSource>
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and $([MSBuild]::IsOsPlatform(Windows))">&quot;$([MSBuild]::NormalizePath('$(RepoRoot)src/mono/browser/emsdk', 'emsdk_env.cmd'))&quot; &amp;&amp; </_CoreClrBuildPreSource>
<_CoreClrBuildPreSource Condition="'$(TargetsBrowser)' == 'true' and !$([MSBuild]::IsOsPlatform(Windows))">source &quot;$(RepoRoot)src/mono/browser/emsdk/emsdk_env.sh&quot; &amp;&amp; </_CoreClrBuildPreSource>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/native/corehost/corehost.proj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<IntermediateOutputRootPath>$(ArtifactsObjDir)$(OutputRID).$(Configuration)\</IntermediateOutputRootPath>
<!-- Global location for version files -->
<NativeVersionFile Condition="$([MSBuild]::IsOsPlatform(Windows))">$(ArtifactsObjDir)_version.h</NativeVersionFile>
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
<NativeVersionFile Condition="!$([MSBuild]::IsOsPlatform(Windows)) or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
</PropertyGroup>

<Target Name="CopySingleFileHost" AfterTargets="Build">
Expand Down Expand Up @@ -92,16 +92,16 @@
</Target>

<!--
This is a workaround when cross-compiling on Windows for Android.
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.

https://github.com/dotnet/arcade/issues/15496
-->
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
</PropertyGroup>
</Target>
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
</PropertyGroup>
Expand Down
10 changes: 9 additions & 1 deletion src/native/libs/build-native.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set __Ninja=1
set __icuDir=""
set __usePThreads=0
set __ExtraCmakeParams=
set __CrossTarget=0

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

if /i not "%__TargetOS%" == "android" (
if "%__TargetOS%"=="android" (
set __CrossTarget=1
)
if "%__TargetOS%"=="browser" (
set __CrossTarget=1
)

if %__CrossTarget% EQU 0 (
call "%__repoRoot%\eng\native\version\copy_version_files.cmd"
) else (
call powershell -NoProfile -ExecutionPolicy ByPass -File "%__repoRoot%\eng\native\version\copy_version_files.ps1"
Expand Down
8 changes: 4 additions & 4 deletions src/native/libs/build-native.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Hardcode version paths in a global location. -->
<NativeVersionFile Condition="'$(TargetOS)' == 'windows'">$(ArtifactsObjDir)_version.h</NativeVersionFile>
<NativeVersionFile Condition="'$(TargetOS)' != 'windows' or '$(TargetsAndroid)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
<NativeVersionFile Condition="'$(TargetOS)' != 'windows' or '$(TargetsMobile)' == 'true'">$(ArtifactsObjDir)_version.c</NativeVersionFile>
<AssemblyName>.NET Runtime</AssemblyName>
<_BuildNativeTargetOS>$(TargetOS)</_BuildNativeTargetOS>
<_BuildNativeTargetOS Condition="'$(TargetsLinuxBionic)' == 'true'">linux-bionic</_BuildNativeTargetOS>
Expand Down Expand Up @@ -77,16 +77,16 @@
</Target>

<!--
This is a workaround when cross-compiling on Windows for Android.
This is a workaround when cross-compiling on Windows for non-windows (Mobile for now) targets.

https://github.com/dotnet/arcade/issues/15496
-->
<Target Name="_BeforeAndroidNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_BeforeCrossTargetNativeVersionFile" BeforeTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.h</NativeVersionFile>
</PropertyGroup>
</Target>
<Target Name="_AfterAndroidNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsAndroid)' == 'true'">
<Target Name="_AfterCrossTargetNativeVersionFile" AfterTargets="GenerateNativeVersionFile" Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(TargetsMobile)' == 'true'">
<PropertyGroup>
<NativeVersionFile>$(ArtifactsObjDir)_version.c</NativeVersionFile>
</PropertyGroup>
Expand Down
Loading