Skip to content

[NativeAOT-LLVM] Wasm managed threads - build new nupkg #3060

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

Draft
wants to merge 14 commits into
base: feature/NativeAOT-LLVM
Choose a base branch
from
4 changes: 2 additions & 2 deletions eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if /i "%__Arch%" == "wasm" (
set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!"
if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_PATH!/"
set __CmakeGenerator=Ninja
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"
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 -D_WASI_EMULATED_PTHREAD"
)
) else (
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0"
Expand Down Expand Up @@ -102,7 +102,7 @@ if not "%__ConfigureOnly%" == "1" (
if /i "%__UseEmcmake%" == "1" (
call "!EMSDK!/emsdk_env" > nul 2>&1 && emcmake "%CMakePath%" %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
) else (
"%CMakePath%" %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
"%CMakePath%" --trace-source=zlib-ng.cmake %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
)

if "%errorlevel%" == "0" (
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-nodejs.ps1 $(Build.SourcesDirectory)/wasm-tools
displayName: Install NodeJS

- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), or(eq(parameters.platform, 'wasi_wasm_win'), eq(parameters.platform, 'wasi_wasm_linux_x64_naot_llvm'))) }}:
- ${{ if and(eq(parameters.runtimeFlavor, 'coreclr'), in(parameters.platform, 'wasi_wasm_win', 'wasi_wasm_linux_x64_naot_llvm', 'wasi_multithread_wasm_win')) }}:
# Install Wasi Wasm dependencies: wasi-sdk, wasmtime
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-wasi-sdk.ps1 -CI -InstallDir $(Build.SourcesDirectory)/wasm-tools
displayName: Install wasi-sdk
Expand All @@ -228,7 +228,7 @@ jobs:
- script: pwsh $(Build.SourcesDirectory)/eng/pipelines/runtimelab/install-jco.ps1 $(Build.SourcesDirectory)
displayName: Install Jco

- ${{ if or(eq(parameters.platform, 'browser_wasm_win'), and(eq(parameters.platform, 'wasi_wasm_win'), not(eq(parameters.runtimeFlavor, 'coreclr')))) }}:
- ${{ if or(eq(parameters.platform, 'browser_wasm_win'), and(in(parameters.platform, 'wasi_wasm_win', 'wasi_multithread_wasm_win'), not(eq(parameters.runtimeFlavor, 'coreclr')))) }}:
# Update machine certs
- task: PowerShell@2
displayName: Update machine certs
Expand Down
23 changes: 23 additions & 0 deletions eng/pipelines/common/platform-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,29 @@ jobs:
buildConfig: ${{ parameters.buildConfig }}
${{ insert }}: ${{ parameters.jobParameters }}

- ${{ if containsValue(parameters.platforms, 'wasi_multithread_wasm_win') }}:
- template: xplat-setup.yml
parameters:
jobTemplate: ${{ parameters.jobTemplate }}
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }}
variables: ${{ parameters.variables }}
osGroup: wasi
archType: wasm
targetRid: wasi-wasm
platform: wasi_wasm_win
shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
jobParameters:
hostedOs: windows
runtimeFlavor: ${{ parameters.runtimeFlavor }}
stagedBuild: ${{ parameters.stagedBuild }}
buildConfig: ${{ parameters.buildConfig }}
# Turn on threads by adding to the buildArgs
# ${{ each param in parameters.jobParameters }}:
# ${{ each pair in param }}:
# ${{ if ne(pair.key, 'buildArgs') }}:
# ${{ pair.key }}: ${{ pair.value }}
# buildArgs: ${{ buildArgs }} '/p:WasmEnableThreads=true'

# Browser WebAssembly Linux X64 for NAOT-LLVM
# 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.

Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/runtimelab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extends:
- windows_x64
- browser_wasm_win
- wasi_wasm_win
# - wasi_multithread_wasm_win
- Browser_wasm_linux_x64_naot_llvm
- wasi_wasm_linux_x64_naot_llvm
jobParameters:
Expand Down Expand Up @@ -103,6 +104,7 @@ extends:
- windows_x64
- Browser_wasm_win
- wasi_wasm_win
# - wasi_multithread_wasm_win
- wasi_wasm_linux_x64_naot_llvm
- Browser_wasm_linux_x64_naot_llvm
jobParameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<PropertyGroup Condition="'$(TargetsSingleThreadedWasm)' != 'true'">
<FeaturePortableThreadPool>true</FeaturePortableThreadPool>
<FeaturePortableTimer>true</FeaturePortableTimer>
<FeatureWasmManagedThreads Condition="'$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
<FeatureWasmPerfTracing Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and ('$(WasmEnableThreads)' == 'true')">true</FeatureWasmPerfTracing>
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
<DefineConstants Condition="'$(FeatureWasmPerfTracing)' == 'true'">$(DefineConstants);FEATURE_WASM_PERFTRACING</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<FeatureHardwareIntrinsics>true</FeatureHardwareIntrinsics>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public static bool IsEntered(object obj)

#region Public Wait/Pulse methods

#if !FEATURE_WASM_MANAGED_THREADS
[UnsupportedOSPlatform("browser")]
#endif
public static bool Wait(object obj, int millisecondsTimeout)
{
return GetCondition(obj).Wait(millisecondsTimeout, obj);
Expand Down
3 changes: 2 additions & 1 deletion src/installer/pkg/projects/nativeaot-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<ItemGroup>
<Project Include="Microsoft.DotNet.ILCompiler.LLVM\Microsoft.DotNet.ILCompiler.LLVM.pkgproj" />
<ProjectReference Include="@(Project)" />
<ProjectReference Include="@(Project)" AdditionalProperties="PackageTargetRuntime=$(OutputRID)" />
<ProjectReference Include="@(Project)" Condition="'$(WasmEnableThreads)' != 'true'" AdditionalProperties="PackageTargetRuntime=$(OutputRID)" />
<ProjectReference Include="@(Project)" Condition="'$(WasmEnableThreads)' == 'true'" AdditionalProperties="PackageTargetRuntime=multithread.$(OutputRID)" />
<ProjectReference Condition="'$(BuildHostTools)' == 'true'" Include="@(Project)" AdditionalProperties="PackageTargetRuntime=$(NETCoreSdkRuntimeIdentifier);PackHostILCompiler=true" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="'$(FeatureWasmManagedThreads)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Unix.cs" Condition="'$(TargetsWindows)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Portable.cs" />
Expand Down
6 changes: 4 additions & 2 deletions src/native/external/zlib-ng.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)

# zlib-ng uses atomics, so we need to enable threads when requested for browser/wasi, otherwise the wasm target won't have thread support.
if (CMAKE_USE_PTHREADS)
add_compile_options(-pthread)
add_linker_flag(-pthread)
#add_compile_options(-pthread)
#add_linker_flag(-pthread)
add_compile_options(-D_WASI_EMULATED_PTHREAD )
add_linker_flag(-Wl,-lwasi-emulated-pthread)
endif()
endif()

Expand Down
Loading