Skip to content

Commit 494d4c5

Browse files
committed
Add packages and CI for multithreaded debug config.
1 parent c7f9549 commit 494d4c5

File tree

24 files changed

+373
-7
lines changed

24 files changed

+373
-7
lines changed

docs/workflow/building/coreclr/nativeaot.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ You should now be able to publish the project for Wasm: `dotnet publish -r brows
7676

7777
Once you build the repo, you can use the produced binaries in one of four ways specified below ("Using built binaries", "Building packages", "Convenience Visual Studio "repro" project", "Running tests").
7878

79+
## Building for Multithreaded packages
80+
81+
This is a work in progress and far from functional. Currentlty there exists just enough infrastucture to build packages for mutlithreaded runtime and libs, but they are not functional in the sense that they support multithreaded programs yet. To build the WASI packages:
82+
```
83+
build clr.aot+libs+nativeaot.packages -c Debug -a wasm -os wasi -cmakeargs -DCLR_CMAKE_TARGET_OS_SUBGROUP=multithread '/p:WasmEnableThreads=true'
84+
```
85+
To build the browser multithreaded packages:
86+
```
87+
build clr.aot+libs+nativeaot.packages -c Debug -a wasm -os browser -cmakeargs -DCLR_CMAKE_TARGET_OS_SUBGROUP=multithread '/p:WasmEnableThreads=true'
88+
```
89+
To build the runtime tests for WASI
90+
```
91+
src\tests\build nativeaot Debug wasm tree nativeaot wasi /p:LibrariesConfiguration=debug /p:TestWrapperTargetsWindows=true /p:WasmEnableThreads=true
92+
```
93+
To build the runtime tests for browser
94+
```
95+
src\tests\build nativeaot Debug wasm tree nativeaot browser /p:LibrariesConfiguration=debug /p:TestWrapperTargetsWindows=true /p:WasmEnableThreads=true
96+
```
97+
98+
7999
### Using built binaries
80100

81101
In this workflow, you have a project file that you want to `dotnet publish`, but you want to use your own build of the compiler/runtime/framework. You need to be using a daily build of the .NET SDK downloaded from the dotnet/sdk repo. It's typically enough to just download the daily build ZIP file, unpack it, and make sure the unpacked directory is the first thing in your PATH. Don't forget to add a NuGet.config as specified by the dotnet/sdk repo- you'll hit restore issues otherwise.

eng/native/configurecompiler.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ elseif (CLR_CMAKE_HOST_UNIX)
148148
add_compile_options(-Wno-alloca)
149149
add_compile_options(-Wno-implicit-int-float-conversion)
150150
endif()
151+
152+
if (CLR_CMAKE_TARGET_OS_SUBGROUP STREQUAL multithread AND CLR_CMAKE_HOST_BROWSER)
153+
add_compile_options(-pthread)
154+
endif(CLR_CMAKE_TARGET_OS_SUBGROUP STREQUAL multithread AND CLR_CMAKE_HOST_BROWSER)
151155
endif(MSVC)
152156

153157
if (CLR_CMAKE_ENABLE_SANITIZERS)

eng/native/gen-buildsys.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ if /i "%__Arch%" == "wasm" (
6565
set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!"
6666
if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_PATH!/"
6767
set __CmakeGenerator=Ninja
68+
if defined __CMakeArgs (
69+
if not "!__CMakeArgs:multithread=!" == "!__CMakeArgs!" (
70+
set __ExtraCmakeParams=%__ExtraCmakeParams% -D_WASI_EMULATED_PTHREAD
71+
)
72+
)
6873
set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm "-DWASI_SDK_PREFIX=!WASI_SDK_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!share/wasi-sysroot" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1"
6974
)
7075
) else (

eng/pipelines/common/platform-matrix.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,44 @@ jobs:
500500
buildConfig: ${{ parameters.buildConfig }}
501501
${{ insert }}: ${{ parameters.jobParameters }}
502502

503+
- ${{ if containsValue(parameters.platforms, 'wasi_multithread_wasm_win') }}:
504+
- template: xplat-setup.yml
505+
parameters:
506+
jobTemplate: ${{ parameters.jobTemplate }}
507+
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }}
508+
variables: ${{ parameters.variables }}
509+
osGroup: wasi
510+
osSubgroup: multithread
511+
archType: wasm
512+
targetRid: wasi-wasm
513+
platform: wasi_multithread_wasm_win
514+
shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
515+
jobParameters:
516+
hostedOs: windows
517+
runtimeFlavor: ${{ parameters.runtimeFlavor }}
518+
stagedBuild: ${{ parameters.stagedBuild }}
519+
buildConfig: ${{ parameters.buildConfig }}
520+
${{ insert }}: ${{ parameters.jobParameters }}
521+
522+
- ${{ if containsValue(parameters.platforms, 'browser_multithread_wasm_win') }}:
523+
- template: xplat-setup.yml
524+
parameters:
525+
jobTemplate: ${{ parameters.jobTemplate }}
526+
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }}
527+
variables: ${{ parameters.variables }}
528+
osGroup: browser
529+
osSubgroup: multithread
530+
archType: wasm
531+
targetRid: browser-wasm
532+
platform: browser_multithread_wasm_win
533+
shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
534+
jobParameters:
535+
hostedOs: windows
536+
runtimeFlavor: ${{ parameters.runtimeFlavor }}
537+
stagedBuild: ${{ parameters.stagedBuild }}
538+
buildConfig: ${{ parameters.buildConfig }}
539+
${{ insert }}: ${{ parameters.jobParameters }}
540+
503541
# WebAssembly Linux for NAOT-LLVM
504542
# Use a different name to differentiate from upstream as we need the -sanitizer image to get build tools that are not present in the stock browser_wasm image.
505543

eng/pipelines/libraries/helix-queues-setup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
- (Ubuntu.2204.Amd64)Ubuntu.2204.Amd64.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-helix-webassembly
176176

177177
# Browser WebAssembly windows
178-
- ${{ if in(parameters.platform, 'browser_wasm_win', 'wasi_wasm_win') }}:
178+
- ${{ if in(parameters.platform, 'browser_wasm_win', 'wasi_wasm_win', 'browser_multithread_wasm_win', 'wasi_multithread_wasm_win') }}:
179179
- (Windows.Amd64.Server2022.Open)windows.amd64.server2022.open@mcr.microsoft.com/dotnet-buildtools/prereqs:windowsservercore-ltsc2022-helix-webassembly
180180
- (Windows.Server2025.Amd64.Open)windows.server2025.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:windowsservercore-ltsc2025-helix-webassembly-amd64
181181

eng/pipelines/runtimelab.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ extends:
7171
parameters:
7272
librariesConfiguration: Debug
7373

74+
#
75+
# Build and test Wasm Debug multithreaded libraries and Debug runtime
76+
#
77+
- template: /eng/pipelines/common/platform-matrix.yml
78+
parameters:
79+
jobTemplate: /eng/pipelines/common/global-build-job.yml
80+
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
81+
buildConfig: debug
82+
platforms:
83+
- browser_multithread_wasm_win
84+
- wasi_multithread_wasm_win
85+
jobParameters:
86+
timeoutInMinutes: 300
87+
buildArgs: -s clr.aot+libs -c debug -rc $(_BuildConfig) -cmakeargs -DCLR_CMAKE_TARGET_OS_SUBGROUP=multithread '/p:WasmEnableThreads=true'
88+
postBuildSteps:
89+
- template: /eng/pipelines/runtimelab/runtimelab-post-build-steps.yml
90+
parameters:
91+
librariesConfiguration: Debug
92+
7493
#
7594
# Build and test with Debug libraries and Checked runtime
7695
#

eng/pipelines/runtimelab/runtimelab-post-build-steps.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ steps:
3131
displayName: Set up ILC emulation environment
3232

3333
- ${{ if eq(parameters.archType, 'wasm') }}:
34-
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.osGroup }} $(crossArg) $(_officialBuildParameter) ci tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }}
35-
displayName: Build runtime tests
34+
- ${{ if eq(parameters.platform, 'browser_multithread_wasm_win') }}:
35+
- script: |
36+
$(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} $(crossArg) $(_officialBuildParameter) ci browser tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} /p:WasmEnableThreads=true
37+
displayName: Build WebAssembly browser Mutlithread runtime tests
38+
- ${{ elseif eq(parameters.platform, 'wasi_multithread_wasm_win') }}:
39+
- script: |
40+
$(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} $(crossArg) $(_officialBuildParameter) ci wasi tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} /p:WasmEnableThreads=true
41+
displayName: Build WebAssembly wasi Mutlithread runtime tests
42+
- ${{ else }}:
43+
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.osGroup }} $(crossArg) $(_officialBuildParameter) ci tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }}
44+
displayName: Build runtime tests
3645
- ${{ else }}:
3746
- ${{ if eq(parameters.osGroup, 'windows') }}:
3847
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} $(crossArg) $(_officialBuildParameter) ci tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }}
@@ -49,7 +58,7 @@ steps:
4958
displayName: Run runtime tests
5059

5160
# Don't compile/run the libraries tests with emulated ILC to save CI time/resources.
52-
- ${{ if and(eq(parameters.archType, 'wasm'), eq(parameters.nameSuffix, '')) }}:
61+
- ${{ if and(and(eq(parameters.archType, 'wasm'), eq(parameters.nameSuffix, '')), not(in(parameters.platform, 'browser_multithread_wasm_win', 'wasi_multithread_wasm_win'))) }}:
5362
- script: $(Build.SourcesDirectory)/build$(scriptExt) libs.tests -test -a ${{ parameters.archType }} -os ${{ parameters.osGroup }} -lc ${{ parameters.librariesConfiguration }} -rc $(buildConfigUpper) /p:TestNativeAot=true /p:RunSmokeTestsOnly=true
5463
displayName: Build and run WebAssembly libraries tests
5564

@@ -61,3 +70,4 @@ steps:
6170
- template: /eng/pipelines/common/upload-intermediate-artifacts-step.yml
6271
parameters:
6372
name: ${{ parameters.platform }}${{ parameters.nameSuffix }}
73+

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ The .NET Foundation licenses this file to you under the MIT license.
438438
<CompileWasmArgs Condition="'$(NativeDebugSymbols)' == 'true'">$(CompileWasmArgs) -g3</CompileWasmArgs>
439439
<CompileWasmArgs Condition="'$(WasmEnableNonTrappingFloatToIntConversions)' == 'true'">$(CompileWasmArgs) -mnontrapping-fptoint</CompileWasmArgs>
440440
<CompileWasmArgs Condition="'$(IlcLlvmExceptionHandlingModel)' == 'wasm'">$(CompileWasmArgs) -fwasm-exceptions</CompileWasmArgs>
441+
<CompileWasmArgs Condition="'$(WasmEnableThreads)' == 'true'">$(CompileWasmArgs) -pthread -matomics -mbulk-memory</CompileWasmArgs>
441442
</PropertyGroup>
442443

443444
<PropertyGroup Condition="'$(_targetOS)' == 'browser'">
@@ -608,6 +609,7 @@ The .NET Foundation licenses this file to you under the MIT license.
608609
<CustomLinkerArg Include="-s MAXIMUM_MEMORY=$(EmccMaximumHeapSize)" Condition="'$(EmccMaximumHeapSize)' != ''" />
609610
<CustomLinkerArg Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" Condition="'$(EmccInitialHeapSize)' != ''" />
610611
<CustomLinkerArg Condition="'$(EmccEnableAssertions)' == 'true'" Include="-s ASSERTIONS=1" />
612+
<CustomLinkerArg Condition="'$(WasmEnableThreads)' == 'true'" Include="-pthread" />
611613
</ItemGroup>
612614

613615
<!-- wasm-ld only supports listing exports on the command line -->

src/coreclr/nativeaot/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ if(CLR_CMAKE_TARGET_OS STREQUAL wasi)
3232
add_definitions(-DTARGET_UNIX)
3333
endif(CLR_CMAKE_TARGET_OS STREQUAL wasi)
3434

35+
if((CLR_CMAKE_TARGET_OS STREQUAL wasi OR CLR_CMAKE_TARGET_OS STREQUAL emscripten)
36+
AND CLR_CMAKE_TARGET_OS_SUBGROUP STREQUAL multithread)
37+
add_definitions(-DFEATURE_WASM_MANAGED_THREADS)
38+
endif((CLR_CMAKE_TARGET_OS STREQUAL wasi OR CLR_CMAKE_TARGET_OS STREQUAL emscripten)
39+
AND CLR_CMAKE_TARGET_OS_SUBGROUP STREQUAL multithread)
40+
3541
if(CLR_CMAKE_TARGET_ANDROID)
3642
add_definitions(-DFEATURE_EMULATED_TLS)
3743
endif()

src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,8 @@ REDHAWK_PALEXPORT bool PalGetMaximumStackBounds(_Out_ void** ppStackLowOut, _Out
11511151
{
11521152
#if defined(HOST_WASM) && !defined(FEATURE_WASM_MANAGED_THREADS)
11531153
PalGetMaximumStackBounds_SingleThreadedWasm(&pStackLowOut, &pStackHighOut);
1154+
#elif defined(HOST_WASM) && defined(FEATURE_WASM_MANAGED_THREADS)
1155+
PalGetMaximumStackBounds_MultiThreadedWasm(&pStackLowOut, &pStackHighOut);
11541156
#elif defined(__APPLE__)
11551157
// This is a Mac specific method
11561158
pStackHighOut = pthread_get_stackaddr_np(pthread_self());

0 commit comments

Comments
 (0)