-
Notifications
You must be signed in to change notification settings - Fork 216
[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
Changes from 1 commit
494d4c5
46699a7
7fc1d34
e8e2de4
301c775
456f600
4099b10
c3ed443
3261466
900df40
8ccf2ec
d494b8e
06f4e2d
2672e75
3b7cfbc
ddf7606
9f681c6
384c77e
f52f534
3f6f0ed
0a72ac1
f39a0cb
539edc4
f49ca4d
521afe1
1b4daba
5be5163
44eba75
1e6d545
9073092
f9597f7
e47224c
024e938
9f213e9
c2c2c37
6483fb1
0a8d87e
1ecfb04
fae5d14
fb468b9
250b2a6
06dacf0
d6ccf55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -76,6 +76,26 @@ You should now be able to publish the project for Wasm: `dotnet publish -r brows | |||||
|
||||||
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"). | ||||||
|
||||||
## Building for Multithreaded packages | ||||||
|
||||||
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: | ||||||
``` | ||||||
build clr.aot+libs+nativeaot.packages -c Debug -a wasm -os wasi -cmakeargs -DCLR_CMAKE_TARGET_OS_SUBGROUP=multithread '/p:WasmEnableThreads=true' | ||||||
``` | ||||||
To build the browser multithreaded packages: | ||||||
``` | ||||||
build clr.aot+libs+nativeaot.packages -c Debug -a wasm -os browser -cmakeargs -DCLR_CMAKE_TARGET_OS_SUBGROUP=multithread '/p:WasmEnableThreads=true' | ||||||
``` | ||||||
To build the runtime tests for WASI | ||||||
``` | ||||||
src\tests\build nativeaot Debug wasm tree nativeaot wasi /p:LibrariesConfiguration=debug /p:TestWrapperTargetsWindows=true /p:WasmEnableThreads=true | ||||||
``` | ||||||
To build the runtime tests for browser | ||||||
``` | ||||||
src\tests\build nativeaot Debug wasm tree nativeaot browser /p:LibrariesConfiguration=debug /p:TestWrapperTargetsWindows=true /p:WasmEnableThreads=true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or is it needed for some reason? |
||||||
``` | ||||||
|
||||||
|
||||||
### Using built binaries | ||||||
|
||||||
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. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,11 @@ 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 | ||
if defined __CMakeArgs ( | ||
if not "!__CMakeArgs:multithread=!" == "!__CMakeArgs!" ( | ||
set __ExtraCmakeParams=%__ExtraCmakeParams% -D_WASI_EMULATED_PTHREAD | ||
) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
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" | ||
) | ||
) else ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,6 +500,44 @@ jobs: | |
buildConfig: ${{ parameters.buildConfig }} | ||
${{ insert }}: ${{ parameters.jobParameters }} | ||
|
||
- ${{ if containsValue(parameters.platforms, 'wasi_multithread_wasm_win') }}: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need these new platforms; we should be able to use the existing ones like here: https://github.com/dotnet/runtime/blob/9e5e6aa7bc36aeb2a154709a9d1192030c30a2ef/eng/pipelines/common/templates/wasm-build-only.yml#L17-L36, utilizing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
- template: xplat-setup.yml | ||
parameters: | ||
jobTemplate: ${{ parameters.jobTemplate }} | ||
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }} | ||
variables: ${{ parameters.variables }} | ||
osGroup: wasi | ||
osSubgroup: multithread | ||
archType: wasm | ||
targetRid: wasi-wasm | ||
platform: wasi_multithread_wasm_win | ||
shouldContinueOnError: ${{ parameters.shouldContinueOnError }} | ||
jobParameters: | ||
hostedOs: windows | ||
runtimeFlavor: ${{ parameters.runtimeFlavor }} | ||
stagedBuild: ${{ parameters.stagedBuild }} | ||
buildConfig: ${{ parameters.buildConfig }} | ||
${{ insert }}: ${{ parameters.jobParameters }} | ||
|
||
- ${{ if containsValue(parameters.platforms, 'browser_multithread_wasm_win') }}: | ||
- template: xplat-setup.yml | ||
parameters: | ||
jobTemplate: ${{ parameters.jobTemplate }} | ||
helixQueuesTemplate: ${{ parameters.helixQueuesTemplate }} | ||
variables: ${{ parameters.variables }} | ||
osGroup: browser | ||
osSubgroup: multithread | ||
archType: wasm | ||
targetRid: browser-wasm | ||
platform: browser_multithread_wasm_win | ||
shouldContinueOnError: ${{ parameters.shouldContinueOnError }} | ||
jobParameters: | ||
hostedOs: windows | ||
runtimeFlavor: ${{ parameters.runtimeFlavor }} | ||
stagedBuild: ${{ parameters.stagedBuild }} | ||
buildConfig: ${{ parameters.buildConfig }} | ||
${{ insert }}: ${{ parameters.jobParameters }} | ||
|
||
# WebAssembly Linux 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. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,17 @@ steps: | |
displayName: Set up ILC emulation environment | ||
|
||
- ${{ if eq(parameters.archType, 'wasm') }}: | ||
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.osGroup }} $(crossArg) $(_officialBuildParameter) ci tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} | ||
displayName: Build runtime tests | ||
- ${{ if eq(parameters.platform, 'browser_multithread_wasm_win') }}: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to avoid this duplication. We can add a parameter to these post-build steps like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
- script: | | ||
$(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} $(crossArg) $(_officialBuildParameter) ci browser tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} /p:WasmEnableThreads=true | ||
displayName: Build WebAssembly browser Mutlithread runtime tests | ||
- ${{ elseif eq(parameters.platform, 'wasi_multithread_wasm_win') }}: | ||
- script: | | ||
$(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.archType }} $(crossArg) $(_officialBuildParameter) ci wasi tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} /p:WasmEnableThreads=true | ||
displayName: Build WebAssembly wasi Mutlithread runtime tests | ||
- ${{ else }}: | ||
- script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) nativeaot $(buildConfigUpper) ${{ parameters.osGroup }} $(crossArg) $(_officialBuildParameter) ci tree nativeaot /p:LibrariesConfiguration=${{ parameters.librariesConfiguration }} | ||
displayName: Build runtime tests | ||
- ${{ else }}: | ||
- ${{ if eq(parameters.osGroup, 'windows') }}: | ||
- 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: | |
displayName: Run runtime tests | ||
|
||
# Don't compile/run the libraries tests with emulated ILC to save CI time/resources. | ||
- ${{ if and(eq(parameters.archType, 'wasm'), eq(parameters.nameSuffix, '')) }}: | ||
- ${{ if and(and(eq(parameters.archType, 'wasm'), eq(parameters.nameSuffix, '')), not(in(parameters.platform, 'browser_multithread_wasm_win', 'wasi_multithread_wasm_win'))) }}: | ||
- 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 | ||
displayName: Build and run WebAssembly libraries tests | ||
|
||
|
@@ -61,3 +70,4 @@ steps: | |
- template: /eng/pipelines/common/upload-intermediate-artifacts-step.yml | ||
parameters: | ||
name: ${{ parameters.platform }}${{ parameters.nameSuffix }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,6 +438,7 @@ The .NET Foundation licenses this file to you under the MIT license. | |
<CompileWasmArgs Condition="'$(NativeDebugSymbols)' == 'true'">$(CompileWasmArgs) -g3</CompileWasmArgs> | ||
<CompileWasmArgs Condition="'$(WasmEnableNonTrappingFloatToIntConversions)' == 'true'">$(CompileWasmArgs) -mnontrapping-fptoint</CompileWasmArgs> | ||
<CompileWasmArgs Condition="'$(IlcLlvmExceptionHandlingModel)' == 'wasm'">$(CompileWasmArgs) -fwasm-exceptions</CompileWasmArgs> | ||
<CompileWasmArgs Condition="'$(WasmEnableThreads)' == 'true'">$(CompileWasmArgs) -pthread -matomics -mbulk-memory</CompileWasmArgs> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to modify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't think there were any triples for threads, at least not yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will comment it. The problem is that cmake fails for zlib-ng with pthread as the libc is not build with threads (atomics, bulk-memory) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just pthread is left now, thanks. |
||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(_targetOS)' == 'browser'"> | ||
|
@@ -608,6 +609,7 @@ The .NET Foundation licenses this file to you under the MIT license. | |
<CustomLinkerArg Include="-s MAXIMUM_MEMORY=$(EmccMaximumHeapSize)" Condition="'$(EmccMaximumHeapSize)' != ''" /> | ||
<CustomLinkerArg Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" Condition="'$(EmccInitialHeapSize)' != ''" /> | ||
<CustomLinkerArg Condition="'$(EmccEnableAssertions)' == 'true'" Include="-s ASSERTIONS=1" /> | ||
<CustomLinkerArg Condition="'$(WasmEnableThreads)' == 'true'" Include="-pthread" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw earlier Emscripten gives some warning like "JS will be slow with memory growth + threads", seems we should disable it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. disabled growth and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I only meant to disable the warning. I don't think we can disable memory growth... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol, I was thinking we would block users from running slow code. |
||
</ItemGroup> | ||
|
||
<!-- wasm-ld only supports listing exports on the command line --> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1151,6 +1151,8 @@ REDHAWK_PALEXPORT bool PalGetMaximumStackBounds(_Out_ void** ppStackLowOut, _Out | |
{ | ||
#if defined(HOST_WASM) && !defined(FEATURE_WASM_MANAGED_THREADS) | ||
PalGetMaximumStackBounds_SingleThreadedWasm(&pStackLowOut, &pStackHighOut); | ||
#elif defined(HOST_WASM) && defined(FEATURE_WASM_MANAGED_THREADS) | ||
PalGetMaximumStackBounds_MultiThreadedWasm(&pStackLowOut, &pStackHighOut); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, have updated this and removed |
||
#elif defined(__APPLE__) | ||
// This is a Mac specific method | ||
pStackHighOut = pthread_get_stackaddr_np(pthread_self()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#ifndef FEATURE_WASM_MANAGED_THREADS | ||
#ifdef FEATURE_WASM_MANAGED_THREADS | ||
int __cxa_thread_atexit(void (*func)(), void *obj, void *dso_symbol); | ||
void PalGetMaximumStackBounds_MultiThreadedWasm(void** ppStackLowOut, void** ppStackHighOut); | ||
#else | ||
void PalGetMaximumStackBounds_SingleThreadedWasm(void** ppStackLowOut, void** ppStackHighOut); | ||
#endif // !FEATURE_WASM_MANAGED_THREADS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should funnel
/p:WasmEnableThreads
down to cmake/clang automatically. E. g. the libs native build setsCMAKE_USE_PTHREADS
, we can extended that pattern to the CoreCLR'sruntime.proj
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done