Skip to content

Commit

Permalink
[build] Use MonoWasmBuildVariant to select runtime variant (#80024)
Browse files Browse the repository at this point in the history
Use `MonoWasmBuildVariant=multithread` and
`MonoWasmBuildVariant=perftrace` consistently to select the runtime
variant.  Previously we also supported setting `WasmEnableThreads` or
`WasmEnablePerfTracing` to configure the runtime variant.  This PR
removes support for that.

Note that this is distinct from what users do: the public
`WasmEnableThreads` (respectively, `WasmEnablePerfTracing`) property
are used in user project to choose the threaded (respectively,
diagnostic tracing) runtime pack in a user project.  That support is
not going way in this PR.

The only tricky bit is that when building and testing the sample
projects, we need to set the public properties, not the wasm build
variant property.

Fixes #75152
  • Loading branch information
lambdageek committed Jan 5, 2023
1 parent 81724f1 commit 92d7381
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
- Browser_wasm
#- Browser_wasm_win
nameSuffix: _Threading
extraBuildArgs: /p:WasmEnableThreads=true /p:_WasmPThreadPoolSize=8
extraBuildArgs: /p:MonoWasmBuildVariant=multithread /p:_WasmPThreadPoolSize=8
isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
isWasmOnlyBuild: ${{ parameters.isWasmOnlyBuild }}
# Always run for runtime-wasm because tests are not run in runtime
Expand All @@ -127,7 +127,7 @@ jobs:
- Browser_wasm
#- Browser_wasm_win
nameSuffix: _Threading_PerfTracing
extraBuildArgs: /p:WasmEnablePerfTracing=true
extraBuildArgs: /p:MonoWasmBuildVariant=perftrace
isExtraPlatformsBuild: ${{ parameters.isExtraPlatformsBuild }}
isWasmOnlyBuild: ${{ parameters.isWasmOnlyBuild }}
# Always run for runtime-wasm because tests are not run in runtime
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,15 @@ extends:
platforms:
- Browser_wasm
nameSuffix: _Threading
extraBuildArgs: /p:WasmEnableThreads=true
extraBuildArgs: /p:MonoWasmBuildVariant=multithread
alwaysRun: ${{ variables.isRollingBuild }}

- template: /eng/pipelines/common/templates/wasm-build-only.yml
parameters:
platforms:
- Browser_wasm
nameSuffix: _Threading_PerfTracing
extraBuildArgs: /p:WasmEnablePerfTracing=true
extraBuildArgs: /p:MonoWasmBuildVariant=perftrace
alwaysRun: ${{ variables.isRollingBuild }}

#
Expand Down
2 changes: 1 addition & 1 deletion eng/testing/tests.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

<_XHarnessArgs Condition="'$(IsFunctionalTest)' == 'true'" >$(_XHarnessArgs) --expected-exit-code=$(ExpectedExitCode)</_XHarnessArgs>
<_XHarnessArgs Condition="'$(WasmXHarnessArgs)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgs)</_XHarnessArgs>
<_XHarnessArgs Condition="('$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true') and '$(_XHarnessArs.Contains(&quot;--web-server-use-cop&quot;)' != 'true'">$(_XHarnessArgs) --web-server-use-cop</_XHarnessArgs>
<_XHarnessArgs Condition="('$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace') and '$(_XHarnessArs.Contains(&quot;--web-server-use-cop&quot;)' != 'true'">$(_XHarnessArgs) --web-server-use-cop</_XHarnessArgs>
<_XHarnessArgs >$(_XHarnessArgs) -s dotnet.js.symbols</_XHarnessArgs>
<_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbol-patterns wasm-symbol-patterns.txt</_XHarnessArgs>
<_XHarnessArgs Condition="'$(_UseWasmSymbolicator)' == 'true'" >$(_XHarnessArgs) --symbolicator WasmSymbolicator.dll,Microsoft.WebAssembly.Internal.SymbolicatorWrapperForXHarness</_XHarnessArgs>
Expand Down
4 changes: 2 additions & 2 deletions eng/testing/workloads-testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
-->
<Target Name="_GetRuntimePackNuGetsToBuild" Condition="'$(TargetOS)' == 'Browser' and '$(WasmSkipMissingRuntimePackBuild)' != 'true'" Returns="@(_NuGetsToBuild)">
<PropertyGroup>
<_DefaultBuildVariant Condition="'$(WasmEnableThreads)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread'">.multithread.</_DefaultBuildVariant>
<_DefaultBuildVariant Condition="'$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'perftrace'">.perftrace.</_DefaultBuildVariant>
<_DefaultBuildVariant Condition="'$(MonoWasmBuildVariant)' == 'multithread'">.multithread.</_DefaultBuildVariant>
<_DefaultBuildVariant Condition="'$(MonoWasmBuildVariant)' == 'perftrace'">.perftrace.</_DefaultBuildVariant>
<_DefaultBuildVariant Condition="'$(_DefaultBuildVariant)' == ''">.</_DefaultBuildVariant>

<_DefaultRuntimePackNuGetPath>$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono$(_DefaultBuildVariant)browser-wasm.$(PackageVersionForWorkloadManifests).nupkg</_DefaultRuntimePackNuGetPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<IncludeWerRelatedKeys>true</IncludeWerRelatedKeys>
<IncludeBreadcrumbStoreFolder>true</IncludeBreadcrumbStoreFolder>
<MacOSPackageDescription>The .NET Shared Framework</MacOSPackageDescription>

<MonoWasmBuildVariant Condition="'$(TargetsBrowser)' == 'true' and '$(MonoWasmBuildVariant)' == '' and '$(WasmEnableThreads)' == 'true'">multithread</MonoWasmBuildVariant>
<MonoWasmBuildVariant Condition="'$(TargetsBrowser)' == 'true' and '$(MonoWasmBuildVariant)' == '' and '$(WasmEnablePerfTracing)' == 'true'">perftrace</MonoWasmBuildVariant>
</PropertyGroup>

<PropertyGroup Condition="'$(RuntimeFlavor)' == 'Mono' and '$(RuntimeFlavor)' != '$(PrimaryRuntimeFlavor)'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
</PropertyGroup>

<PropertyGroup Condition="'$(WasmEnableThreads)' == 'true' or
'$(WasmEnablePerfTracing)' == 'true' or
'$(MonoWasmBuildVariant)' == 'multithread' or
<PropertyGroup Condition="'$(MonoWasmBuildVariant)' == 'multithread' or
'$(MonoWasmBuildVariant)' == 'perftrace'">
<!-- when wasm threading is enabled the implementation in CoreLib won't have the UnsupportedOSAttribute for browser,
but this contract still does since we only expose the wasm threading through System.Diagnostics.Tracing.WebAssembly.PerfTracing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<NoWarn>$(NoWarn);0809;0618;CS8614;CS3015</NoWarn>
<StrongNameKeyId>SilverlightPlatform</StrongNameKeyId>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<FeatureWasmPerfTracing Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</FeatureWasmPerfTracing>
<FeatureWasmThreads Condition="'$(WasmEnableThreads)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<FeatureWasmPerfTracing Condition="'$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</FeatureWasmPerfTracing>
<FeatureWasmThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmPerfTracing)' == 'true'">$(DefineConstants);FEATURE_WASM_PERFTRACING</DefineConstants>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
<DefineConstants>$(DefineConstants);BUILDING_CORELIB_REFERENCE</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<FeatureWasmThreads Condition="'$(TargetOS)' == 'Browser' and ('$(WasmEnableThreads)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread')">true</FeatureWasmThreads>
<FeatureWasmThreads Condition="'$(TargetOS)' == 'Browser' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<DefineConstants Condition="'$(FeatureWasmThreads)' == 'true'" >$(DefineConstants);FEATURE_WASM_THREADS</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(WasmEnableThreads)' == 'true' or
'$(MonoWasmBuildVariant)' == 'multithread'">
<ItemGroup Condition="'$(MonoWasmBuildVariant)' == 'multithread'">
<!-- when wasm threading is enabled the implementation in CoreLib won't have the UnsupportedOSAttribute for browser,
but this contract still does since we only expose the wasm threading through System.Diagnostics.Threading.Thread.WebAssembly.Threading
so we need to baseline the ApiCompat errors related to that. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(WasmEnableThreads)' == 'true' or
'$(MonoWasmBuildVariant)' == 'multithread'">
<ItemGroup Condition="'$(MonoWasmBuildVariant)' == 'multithread'">
<!-- when wasm threading is enabled the implementation in CoreLib won't have the UnsupportedOSAttribute for browser,
but this contract still does since we only expose the wasm threading through System.Diagnostics.Threading.ThreadPool.WebAssembly.Threading
so we need to baseline the ApiCompat errors related to that. -->
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
</ItemGroup>

<!-- Samples that require a multi-threaded runtime -->
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(WasmEnableThreads)' != 'true'" >
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(MonoWasmBuildVariant)' != 'multithread'" >
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-threads\Wasm.Browser.Threads.Sample.csproj" />
</ItemGroup>

<!-- Samples that require a perf-tracing wasm runtime -->
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(WasmEnablePerfTracing)' != 'true'" >
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(MonoWasmBuildVariant)' != 'perftrace'" >
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-eventpipe\Wasm.Browser.EventPipe.Sample.csproj" />
</ItemGroup>

Expand Down Expand Up @@ -369,7 +369,7 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\wasm\System.Net.WebSockets.Client.Wasm.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(WasmEnableThreads)' == 'true' and '$(RunDisabledWasmTests)' != 'true'">
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(MonoWasmBuildVariant)' == 'multithread' and '$(RunDisabledWasmTests)' != 'true'">
<!-- Issue: https://github.com/dotnet/runtime/issues/72101 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.Tests\System.Text.Json.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/74411 -->
Expand All @@ -378,7 +378,7 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(WasmEnablePerfTracing)' == 'true' and '$(RunDisabledWasmTests)' != 'true'">
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(MonoWasmBuildVariant)' == 'perftrace' and '$(RunDisabledWasmTests)' != 'true'">
<!-- Issue: https://github.com/dotnet/runtime/issues/74411 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
<!-- Issue: https://github.com/dotnet/runtime/issues/74413 -->
Expand Down
4 changes: 2 additions & 2 deletions src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<DefineConstants>$(DefineConstants);MONO_FEATURE_SRE</DefineConstants>

<FeatureMono>true</FeatureMono>
<FeatureWasmThreads Condition="'$(TargetsBrowser)' == 'true' and ('$(WasmEnableThreads)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread')">true</FeatureWasmThreads>
<FeatureWasmPerfTracing Condition="'$(TargetsBrowser)' == 'true' and ('$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace')">true</FeatureWasmPerfTracing>
<FeatureWasmThreads Condition="'$(TargetsBrowser)' == 'true' and '$(MonoWasmBuildVariant)' == 'multithread'">true</FeatureWasmThreads>
<FeatureWasmPerfTracing Condition="'$(TargetsBrowser)' == 'true' and ('$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace')">true</FeatureWasmPerfTracing>
<FeatureManagedEtwChannels>true</FeatureManagedEtwChannels>
<FeatureManagedEtw>true</FeatureManagedEtw>
<FeaturePortableTimer Condition="'$(TargetsBrowser)' != 'true'">true</FeaturePortableTimer>
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<RepositoryEngineeringCommonDir>$([MSBuild]::NormalizeDirectory('$(RepositoryEngineeringDir)', 'common'))</RepositoryEngineeringCommonDir>
<CrossToolchainFile>$([MSBuild]::NormalizePath('$(RepositoryEngineeringCommonDir)', 'cross', 'toolchain.cmake'))</CrossToolchainFile>
<MonoWasmThreads Condition="'$(MonoWasmBuildVariant)' == 'singlethread'">false</MonoWasmThreads>
<MonoWasmThreads Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreads>
<MonoWasmThreadsNoUser Condition="('$(WasmEnableThreads)' != 'true' and '$(WasmEnablePerfTracing)' == 'true') or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreadsNoUser>
<MonoWasmThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreads>
<MonoWasmThreadsNoUser Condition="'$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreadsNoUser>
</PropertyGroup>

<!-- default thread suspend for specific platforms -->
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PropertyGroup>
<OutputPath>bin</OutputPath>
<WasmAppDir>$(MSBuildProjectDirectory)\bin\$(Configuration)\AppBundle\</WasmAppDir>
<WasmXHarnessArgs Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true'">$(WasmXHarnessArgs) --web-server-use-cop</WasmXHarnessArgs>
<WasmXHarnessArgs Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">$(WasmXHarnessArgs) --web-server-use-cop</WasmXHarnessArgs>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<WasmNativeStrip>false</WasmNativeStrip>
Expand Down
8 changes: 4 additions & 4 deletions src/mono/sample/wasm/browser-eventpipe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To be able to run this sample you need to build the runtime with `/p:WasmEnableP

# Testing with mock

Build the runtime with `/p:WasmEnablePerfTracing=true /p:MonoDiagnosticsMock=true`
Build the runtime with `/p:MonoWasmBuildVariant=perftrace /p:MonoDiagnosticsMock=true`
Run this test with `/p:MonoDiagnosticsMock=true`

It will inject file [mock.js](./mock.js) into the worker thread, which is mocking the `dotnet trace` tool.
Expand All @@ -17,8 +17,8 @@ dotnet trace convert --format Speedscope c:\Downloads\trace.1665653486202.nettra

# Testing with dotnet trace tool

Build the runtime with `/p:WasmEnablePerfTracing=true`
Build version of dsrouter with WebSockets https://github.com/lambdageek/diagnostics/tree/wasm-server
Build the runtime with `/p:MonoWasmBuildVariant=perftrace`
Build a version of dsrouter with WebSockets support (versions from upstream that target net6.0 or later have the requisite support, see https://github.com/dotnet/diagnostics/blob/main/src/Tools/dotnet-dsrouter/dotnet-dsrouter.csproj)

In console #1 start dsrouter
```
Expand All @@ -40,4 +40,4 @@ In the browser click `Start Work` button and after it finished

In the #3 console press `Enter`

In the browser open dev tools and on performance tab import file `C:\Dev\socket_XXXXXXXX_YYYYYY.chromium.json` which dotnet trace produced
In the browser open dev tools and on performance tab import file `C:\Dev\socket_XXXXXXXX_YYYYYY.chromium.json` which dotnet trace produced
12 changes: 9 additions & 3 deletions src/mono/wasm/threads.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Threaded runtime #

## Building ##
## Building the runtime ##

Build with `/p:WasmEnableThreads=true` to enable support for multi-threading.
Build the runtime with `/p:MonoWasmBuildVariant=multithread` to enable support for multi-threading.

Build with `/p:WasmEnablePerfTracing=true` to enable support for EventPipe diagnostics - this enabled threading, but only for "internal" utility threads. User code is not allowed to start threads.
Build with `/p:MonoWasmBuildVariant=perftrace` to enable support for EventPipe diagnostics - this enabled threading, but only for "internal" utility threads. User code is not allowed to start threads.

Do not combine these options, just turn on one or the other.

## Building sample apps ##

Sample apps use the "public" properties `WasmEnableThreads` and `WasmEnablePerfTracing` to enable
the relevant functionality. This also works with released versions of .NET 7 or later and the
`wasmbrowser` template.

## Libraries feature defines ##

We use the `FeatureWasmThreads` property in the libraries projects to conditionally define
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</PropertyGroup>

<PropertyGroup>
<MonoWasmThreads Condition="'$(WasmEnableThreads)' == 'true' or '$(WasmEnablePerfTracing)' == 'true' or '$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreads>
<MonoWasmThreadsNoUser Condition="('$(WasmEnableThreads)' != 'true' and '$(WasmEnablePerfTracing)' == 'true') or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreadsNoUser>
<MonoWasmThreads Condition="'$(MonoWasmBuildVariant)' == 'multithread' or '$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreads>
<MonoWasmThreadsNoUser Condition="'$(MonoWasmBuildVariant)' == 'perftrace'">true</MonoWasmThreadsNoUser>
<MonoDiagnosticsMock Condition="'$(MonoDiagnosticsMock)' == '' and '$(Configuration)' == 'Release'">false</MonoDiagnosticsMock>
<MonoDiagnosticsMock Condition="'$(MonoDiagnosticsMock)' == '' and '$(Configuration)' == 'Debug'">true</MonoDiagnosticsMock>
</PropertyGroup>
Expand Down

0 comments on commit 92d7381

Please sign in to comment.