diff --git a/Directory.Build.props b/Directory.Build.props index e2c0de947f3364..777662d9bf2db4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -17,7 +17,7 @@ Solaris Linux windows - true + true @@ -27,7 +27,7 @@ arm armel arm64 - wasm + wasm x64 x64 $(TargetArchitecture) @@ -124,7 +124,7 @@ <_portableOS Condition="'$(_runtimeOSFamily)' == 'FreeBSD'">freebsd <_portableOS Condition="'$(_runtimeOSFamily)' == 'illumos'">illumos <_portableOS Condition="'$(_runtimeOSFamily)' == 'Solaris'">solaris - <_portableOS Condition="'$(_runtimeOS)' == 'Browser'">browser + <_portableOS Condition="'$(_runtimeOS)' == 'Browser' or '$(_runtimeOS)' == 'Node'">browser <_portableOS Condition="'$(_runtimeOS)' == 'maccatalyst'">maccatalyst <_portableOS Condition="'$(_runtimeOS)' == 'ios'">ios <_portableOS Condition="'$(_runtimeOS)' == 'iOSSimulator'">iossimulator @@ -146,9 +146,9 @@ <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'linux-musl' and $(TargetArchitecture.StartsWith('arm')) and !$(_hostArch.StartsWith('arm'))">linux-x64 - <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser'">linux-x64 - <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and $([MSBuild]::IsOSPlatform('WINDOWS'))">win-x64 - <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and $([MSBuild]::IsOSPlatform('OSX'))">osx-x64 + <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' or '$(_runtimeOS)' == 'node'">linux-x64 + <_toolRuntimeRID Condition="('$(_runtimeOS)' == 'browser' or '$(_runtimeOS)' == 'node') and $([MSBuild]::IsOSPlatform('WINDOWS'))">win-x64 + <_toolRuntimeRID Condition="('$(_runtimeOS)' == 'browser' or '$(_runtimeOS)' == 'node') and $([MSBuild]::IsOSPlatform('OSX'))">osx-x64 <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'android'">linux-x64 @@ -179,7 +179,7 @@ <_outputRID Condition="'$(TargetOS)' == 'tvOS'">tvos-$(TargetArchitecture) <_outputRID Condition="'$(TargetOS)' == 'tvOSSimulator'">tvossimulator-$(TargetArchitecture) <_outputRID Condition="'$(TargetOS)' == 'Android'">android-$(TargetArchitecture) - <_outputRID Condition="'$(TargetOS)' == 'Browser'">browser-$(TargetArchitecture) + <_outputRID Condition="'$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node'">browser-$(TargetArchitecture) $(PackageRID) $(_outputRID) @@ -198,7 +198,7 @@ true true true - true + true true true diff --git a/eng/Subsets.props b/eng/Subsets.props index 105b34254c6c2b..82b759c4e779cb 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -46,7 +46,7 @@ mono.llvm+ mono.llvm+ - $(DefaultMonoSubsets)mono.wasmruntime+ + $(DefaultMonoSubsets)mono.wasmruntime+ $(DefaultMonoSubsets)mono.aotcross+ $(DefaultMonoSubsets)mono.runtime+mono.corelib+mono.packages @@ -228,7 +228,7 @@ - + diff --git a/eng/build.ps1 b/eng/build.ps1 index 5980695e3a2c34..5ecc79f289be4a 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -6,7 +6,7 @@ Param( [string][Alias('f')]$framework, [string]$vs, [string][Alias('v')]$verbosity = "minimal", - [ValidateSet("windows","Linux","OSX","Android","Browser")][string]$os, + [ValidateSet("windows","Linux","OSX","Android","Browser", "Node")][string]$os, [switch]$allconfigurations, [switch]$coverage, [string]$testscope, @@ -37,7 +37,7 @@ function Get-Help() { Write-Host " -help (-h) Print help and exit." Write-Host " -librariesConfiguration (-lc) Libraries build configuration: Debug or Release." Write-Host " [Default: Debug]" - Write-Host " -os Target operating system: windows, Linux, OSX, Android or Browser." + Write-Host " -os Target operating system: windows, Linux, OSX, Android, Browser or Node." Write-Host " [Default: Your machine's OS.]" Write-Host " -runtimeConfiguration (-rc) Runtime build configuration: Debug, Release or Checked." Write-Host " Checked is exclusive to the CLR runtime. It is the same as Debug, except code is" @@ -249,12 +249,12 @@ foreach ($argument in $PSBoundParameters.Keys) $failedBuilds = @() -if ($os -eq "Browser") { +if ($os -eq "Browser" -or $os -eq "Node") { # override default arch for Browser, we only support wasm $arch = "wasm" if ($msbuild -eq $True) { - Write-Error "Using the -msbuild option isn't supported when building for Browser on Windows, we need need ninja for Emscripten." + Write-Error "Using the -msbuild option isn't supported when building for Browser or Node on Windows, we need need ninja for Emscripten." exit 1 } } @@ -263,7 +263,7 @@ foreach ($config in $configuration) { $argumentsWithConfig = $arguments + " -configuration $((Get-Culture).TextInfo.ToTitleCase($config))"; foreach ($singleArch in $arch) { $argumentsWithArch = "/p:TargetArchitecture=$singleArch " + $argumentsWithConfig - if ($os -eq "Browser") { + if ($os -eq "Browser" -or $os -eq "Node") { $env:__DistroRid="browser-$singleArch" } else { $env:__DistroRid="win-$singleArch" diff --git a/eng/build.sh b/eng/build.sh index 128e720d3c0b2d..71163b22b45a06 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -29,7 +29,7 @@ usage() echo " --librariesConfiguration (-lc) Libraries build configuration: Debug or Release." echo " [Default: Debug]" echo " --os Target operating system: windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS," - echo " tvOSSimulator, iOS, iOSSimulator, Android, Browser, NetBSD, illumos or Solaris." + echo " tvOSSimulator, iOS, iOSSimulator, Android, Browser, Node, NetBSD, illumos or Solaris." echo " [Default: Your machine's OS.]" echo " --projects Project or solution file(s) to build." echo " --runtimeConfiguration (-rc) Runtime build configuration: Debug, Release or Checked." @@ -277,13 +277,15 @@ while [[ $# > 0 ]]; do os="Android" ;; browser) os="Browser" ;; + node) + os="Node" ;; illumos) os="illumos" ;; solaris) os="Solaris" ;; *) echo "Unsupported target OS '$2'." - echo "The allowed values are windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS, tvOSSimulator, iOS, iOSSimulator, Android, Browser, illumos and Solaris." + echo "The allowed values are windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS, tvOSSimulator, iOS, iOSSimulator, Android, Browser, Node, illumos and Solaris." exit 1 ;; esac @@ -461,8 +463,8 @@ if [ ${#actInt[@]} -eq 0 ]; then arguments="-restore -build $arguments" fi -if [ "$os" = "Browser" ] && [ "$arch" != "wasm" ]; then - # override default arch for Browser, we only support wasm +if [[ "$os" = "Browser" ] || [ "$os" = "Node" ]] && [ "$arch" != "wasm" ]; then + # override default arch for Browser and Node, we only support wasm arch=wasm fi diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 11ea3bf8f3aea7..8b597eeeb01ad9 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -164,14 +164,14 @@ $(LibrariesNativeArtifactsPath)*.pdb" IsNative="true" Exclude="@(ExcludeNativeLibrariesRuntimeFiles)" /> - - - solaris - + true browser diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 83d95eae00859f..8b29e7974fdd79 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -39,7 +39,7 @@ <_MobileIntermediateOutputPath>$(IntermediateOutputPath)mobile - + <_runnerFilesToPublish Include="$(AndroidTestRunnerDir)*" Condition="'$(TargetOS)' == 'Android'" /> <_runnerFilesToPublish Include="$(AppleTestRunnerDir)*" Condition="'$(TargetOS)' == 'MacCatalyst' or '$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator'" /> - <_runnerFilesToPublish Include="$(WasmTestRunnerDir)*" Condition="'$(TargetOS)' == 'Browser'" /> + <_runnerFilesToPublish Include="$(WasmTestRunnerDir)*" Condition="'$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node'" /> <_resolvedFilesToPublishToFileName Include="@(ResolvedFileToPublish -> '%(FileName)%(Extension)')" /> diff --git a/eng/testing/tests.targets b/eng/testing/tests.targets index dd40856e629b1b..2935827ed2c09a 100644 --- a/eng/testing/tests.targets +++ b/eng/testing/tests.targets @@ -4,13 +4,13 @@ RunnerTemplate.sh AppleRunnerTemplate.sh AndroidRunnerTemplate.sh - WasmRunnerTemplate.sh - WasmRunnerTemplate.cmd + WasmRunnerTemplate.sh + WasmRunnerTemplate.cmd $(MSBuildThisFileDirectory)$(RunScriptInputName) RunTests.sh - RunTests.cmd + RunTests.cmd $([MSBuild]::NormalizePath('$(OutDir)', '$(RunScriptOutputName)')) %RUNTIME_PATH%\ @@ -35,19 +35,19 @@ - + <_ZipSourceDirectory>$(OutDir) - <_ZipSourceDirectory Condition="'$(TargetOS)' == 'Browser' or '$(TestSingleFile)' == 'true'">$(BundleDir) + <_ZipSourceDirectory Condition="'$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node' or '$(TestSingleFile)' == 'true'">$(BundleDir) @@ -63,8 +63,8 @@ - $(RunScriptCommand) $RSP_FILE - $(RunScriptCommand) %RSP_FILE% + $(RunScriptCommand) $RSP_FILE + $(RunScriptCommand) %RSP_FILE% $([MSBuild]::Escape('$(RunScriptCommand)')) @@ -108,7 +108,7 @@ $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)'))">$(RunTestsCommand) --runtime-path "$(NetCoreAppCurrentTestHostPath.TrimEnd('\/'))" $(RunTestsCommand) --rsp-file "$(TestRspFile)" "$(RunScriptOutputPath)" $(AssemblyName) $(TargetArchitecture) $(TargetOS.ToLowerInvariant()) $(TestProjectName) $(AdditionalXHarnessArguments) - "$(RunScriptOutputPath)" $(JSEngine) $(AssemblyName).dll $(Scenario) + "$(RunScriptOutputPath)" $(JSEngine) $(AssemblyName).dll $(Scenario) diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props b/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props index aeed390ba536b2..70f009716e4385 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props +++ b/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props @@ -1,5 +1,5 @@ - + WasmTestOnBrowser $(TestArchiveRoot)browseronly/ $(TestArchiveTestsRoot)$(OSPlatformConfig)/ diff --git a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj index fd58dca4e44f61..7dfe19965330e7 100644 --- a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj +++ b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj @@ -8,7 +8,7 @@ --> $(Features.Replace('strict', '') - true + true diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/Microsoft.Extensions.FileProviders.Physical.Tests.csproj b/src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/Microsoft.Extensions.FileProviders.Physical.Tests.csproj index d57fed0ca59497..c3242950754b56 100644 --- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/Microsoft.Extensions.FileProviders.Physical.Tests.csproj +++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/Microsoft.Extensions.FileProviders.Physical.Tests.csproj @@ -4,7 +4,7 @@ Microsoft.Extensions.FileProviders.Physical $(NetCoreAppCurrent);net461 true - true + true diff --git a/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj b/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj index d39b20d6d9f5e2..0d8d2d511b81f9 100644 --- a/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj +++ b/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent);net472 - true + true diff --git a/src/libraries/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj b/src/libraries/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj index d0beb0ebc46996..24a695b68d7e6f 100644 --- a/src/libraries/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj +++ b/src/libraries/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj @@ -3,7 +3,7 @@ true true $(NetCoreAppCurrent) - true + true 0436 $(NetCoreAppCurrent);net461 - true + true true $(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.Collections/tests/System.Collections.Tests.csproj b/src/libraries/System.Collections/tests/System.Collections.Tests.csproj index 66f5dee8d5ba6d..0865eb1642f290 100644 --- a/src/libraries/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/libraries/System.Collections/tests/System.Collections.Tests.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) true - true + true diff --git a/src/libraries/System.Composition.TypedParts/tests/System.Composition.TypedParts.Tests.csproj b/src/libraries/System.Composition.TypedParts/tests/System.Composition.TypedParts.Tests.csproj index 293590ae99aff9..1f587fb6e9e049 100644 --- a/src/libraries/System.Composition.TypedParts/tests/System.Composition.TypedParts.Tests.csproj +++ b/src/libraries/System.Composition.TypedParts/tests/System.Composition.TypedParts.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent);net461 - true + true diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj index 3a766de5aaebd3..05c844ae26096a 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj @@ -5,7 +5,7 @@ true true $(NetCoreAppCurrent)-windows;net461 - true + true $(NetCoreAppCurrent) true - true + true diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj index ad027e8be25474..f0b8d215972941 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj +++ b/src/libraries/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser true - true + true diff --git a/src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj b/src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj index 776b69684d3d7b..9ec482b23d57d1 100644 --- a/src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj +++ b/src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj @@ -4,7 +4,7 @@ $(DefineConstants);TargetsWindows true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser - true + true true - true + true @@ -17,7 +17,7 @@ - + diff --git a/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj b/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj index 1b9175f3eb5e12..7d6ef19b18410c 100644 --- a/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj +++ b/src/libraries/System.Drawing.Common/tests/System.Drawing.Common.Tests.csproj @@ -3,7 +3,7 @@ true true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;net48 - true + true diff --git a/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj b/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj index 53f60dbcb90928..04f58ff0338ae1 100644 --- a/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj +++ b/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj b/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj index d68a7be37b621e..4134605fcc4d6e 100644 --- a/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj +++ b/src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser true - true + true diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj b/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj index 67c502fa83412a..8bf5c319347efb 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj +++ b/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj @@ -2,7 +2,7 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-FreeBSD - true + true diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj index 5765f53e6056ec..01999bdcd39e8f 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj +++ b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser - true + true diff --git a/src/libraries/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj b/src/libraries/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj index b639953aff8443..6b1ea1adc080f9 100644 --- a/src/libraries/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj +++ b/src/libraries/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj @@ -3,7 +3,7 @@ true true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj index cd15cfbbf59d5d..a946692b7cdab5 100644 --- a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj +++ b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.Net.Connections/tests/System.Net.Connections.Tests/System.Net.Connections.Tests.csproj b/src/libraries/System.Net.Connections/tests/System.Net.Connections.Tests/System.Net.Connections.Tests.csproj index 7ddfadfd04df2b..cd2f10d10ed93d 100644 --- a/src/libraries/System.Net.Connections/tests/System.Net.Connections.Tests/System.Net.Connections.Tests.csproj +++ b/src/libraries/System.Net.Connections/tests/System.Net.Connections.Tests/System.Net.Connections.Tests.csproj @@ -3,7 +3,7 @@ $(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 672ce364f7061f..85a5103c56843c 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -9,17 +9,17 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX - + WasmTestOnBrowser $(TestArchiveRoot)browseronly/ $(TestArchiveTestsRoot)$(OSPlatformConfig)/ $(DefineConstants);TARGET_BROWSER - + - - + + true ../src/Resources/Strings.resx $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX - true + true diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj index 2f9dea9c37cde4..79e3af4e35a3b9 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser true - true + true diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj index 7b2b9ee2c9fd60..f820b102497aad 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj @@ -4,7 +4,7 @@ ../../src/Resources/Strings.resx $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser annotations - true + true diff --git a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj index 07e4ae778c3708..61f1bfdab549d6 100644 --- a/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj +++ b/src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj @@ -3,7 +3,7 @@ true ../../src/Resources/Strings.resx $(NetCoreAppCurrent) - true + true diff --git a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj index 86a7dacccaefdf..b5bd3f7af0b2a5 100644 --- a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj +++ b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj @@ -3,7 +3,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser true true - true + true diff --git a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj index 28312f8be52a77..2e0a55119d01dd 100644 --- a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj +++ b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj @@ -4,7 +4,7 @@ true $(NetCoreAppCurrent) $(DefineConstants);NETSTANDARD - true + true $(NoWarn);SYSLIB0014 diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index bb131408de3252..c7722065c401ec 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -4,7 +4,7 @@ true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS annotations - true + true diff --git a/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj b/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj index da4dde4e192b90..61d77ea0d96069 100644 --- a/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/UnitTests/System.Net.Security.Unit.Tests.csproj @@ -12,7 +12,7 @@ $(NoWarn);3021 $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS annotations - true + true diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj index dbb949b29df177..152f18fefea983 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj @@ -3,7 +3,7 @@ true true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser - true + true diff --git a/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj b/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj index f05e39076dabe6..addc537e4605ad 100644 --- a/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj +++ b/src/libraries/System.Net.WebClient/tests/System.Net.WebClient.Tests.csproj @@ -4,7 +4,7 @@ $(DefineConstants);NETSTANDARD $(NoWarn);SYSLIB0014 - true + true diff --git a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj index 956ee4d4146122..df0a6172c4c076 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj +++ b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj @@ -5,17 +5,17 @@ $(DefineConstants);NETSTANDARD - + WasmTestOnBrowser $(TestArchiveRoot)browseronly/ $(TestArchiveTestsRoot)$(OSPlatformConfig)/ $(DefineConstants);TARGET_BROWSER - + - - + + - + \ No newline at end of file diff --git a/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj b/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj index 62a8a2e49b35b3..514114fe6935d1 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj +++ b/src/libraries/System.Reflection.MetadataLoadContext/tests/System.Reflection.MetadataLoadContext.Tests.csproj @@ -74,7 +74,7 @@ - + diff --git a/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj b/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj index 78f02cee29ad0e..5fbe76cfc1edf6 100644 --- a/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj +++ b/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj @@ -8,7 +8,7 @@ $(NoWarn),SYSLIB0013 - true + true - + diff --git a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj index dc1a2cccd21a57..2e883a5169bcc5 100644 --- a/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj +++ b/src/libraries/System.Runtime.Loader/tests/System.Runtime.Loader.Tests.csproj @@ -42,14 +42,14 @@ - + @@ -64,7 +64,7 @@ + Condition="'$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node'"> diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj index ee45bdc5e97e9d..a986f6c808afbb 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj @@ -7,7 +7,7 @@ - true + true $(WasmXHarnessArgs) --timeout=1800 diff --git a/src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj b/src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj index dff58ce1bf5ce5..65435dc7636fed 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj +++ b/src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj @@ -4,7 +4,7 @@ $(NoWarn);xUnit2008 $(NetCoreAppCurrent);net48 - true + true diff --git a/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj b/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj index 45be5f85721731..72b41ebbd4a20d 100644 --- a/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj +++ b/src/libraries/System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj @@ -1,7 +1,7 @@ $(NetCoreAppCurrent);net461 - true + true diff --git a/src/libraries/pretest.proj b/src/libraries/pretest.proj index 3e924e083abd51..538eea2e2fd060 100644 --- a/src/libraries/pretest.proj +++ b/src/libraries/pretest.proj @@ -21,7 +21,7 @@ - + - + diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 25d7168bdc4639..88e97d4665318b 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -51,7 +51,7 @@ $(TestRunNamePrefix)$(Scenario)- $(WaitForWorkItemCompletion) - true + true @@ -60,7 +60,7 @@ test/functional/cli/$(TestScope)/ - + true @@ -74,20 +74,20 @@ - + - + - + SetStressModes_$(Scenario).cmd - SetStressModes_$(Scenario).sh + SetStressModes_$(Scenario).sh @@ -141,7 +141,7 @@ @(HelixPreCommand) - true + true @@ -268,7 +268,7 @@ - + 768968 @@ -288,7 +288,7 @@ - + @@ -310,21 +310,21 @@ - + - - + Condition="'$(IncludeHelixCorrelationPayload)' == 'true' and '$(TargetOS)' != 'Browser' and '$(TargetOS)' != 'Node'" /> + + <_WorkItem Include="$(WorkItemArchiveWildCard)" Exclude="$(HelixCorrelationPayload)" /> - <_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Console.*.Test.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'WasmTestOnBrowser' and '$(Scenario)' != 'BuildWasmApps'" /> - <_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Browser.*.Test.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnBrowser'" /> - <_WorkItem Include="$(TestArchiveRoot)browseronly/**/*.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnBrowser'" /> + <_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Console.*.Test.zip" Condition="('$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node') and '$(Scenario)' != 'WasmTestOnBrowser' and '$(Scenario)' != 'BuildWasmApps'" /> + <_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Browser.*.Test.zip" Condition="('$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node') and '$(Scenario)' == 'WasmTestOnBrowser'" /> + <_WorkItem Include="$(TestArchiveRoot)browseronly/**/*.zip" Condition="('$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node') and '$(Scenario)' == 'WasmTestOnBrowser'" /> %(Identity) @@ -333,18 +333,18 @@ - + dotnet exec $XHARNESS_CLI_PATH $HELIX_WORKITEM_UPLOAD_ROOT/xharness-output $XHARNESS_COMMAND - + dotnet exec %XHARNESS_CLI_PATH% %HELIX_WORKITEM_UPLOAD_ROOT%\xharness-output %XHARNESS_COMMAND% - + <_RunOnlyWorkItem Include="$(TestArchiveRoot)runonly/**/*.Console.Sample.zip" /> @@ -354,7 +354,7 @@ - + <_RunOnlyWorkItem Include="$(TestArchiveRoot)runonly/**/*.Browser.Sample.zip" /> @@ -373,7 +373,7 @@ - + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index b1ca6c3a1ddba5..befdeb87ef3c61 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -13,7 +13,7 @@ false - + @@ -254,7 +254,7 @@ - + @@ -275,7 +275,7 @@ - + @@ -283,7 +283,7 @@ - + @@ -315,7 +315,7 @@ - + @@ -354,7 +354,7 @@ @@ -381,7 +381,7 @@ BuildInParallel="false" /> - + diff --git a/src/mono/nuget/mono-packages.proj b/src/mono/nuget/mono-packages.proj index 9403ca9fb34bf0..cdf3db0f70a027 100644 --- a/src/mono/nuget/mono-packages.proj +++ b/src/mono/nuget/mono-packages.proj @@ -3,7 +3,7 @@ - + diff --git a/src/mono/sample/wasm/console/Wasm.Console.Sample.csproj b/src/mono/sample/wasm/console/Wasm.Console.Sample.csproj index 7097ef20ab9bd6..3585e344176bf7 100644 --- a/src/mono/sample/wasm/console/Wasm.Console.Sample.csproj +++ b/src/mono/sample/wasm/console/Wasm.Console.Sample.csproj @@ -3,6 +3,7 @@ true $(MonoProjectRoot)\wasm\runtime-test.js true + true @@ -10,4 +11,5 @@ + diff --git a/src/mono/sample/wasm/console/package.json b/src/mono/sample/wasm/console/package.json new file mode 100644 index 00000000000000..14114d59e24266 --- /dev/null +++ b/src/mono/sample/wasm/console/package.json @@ -0,0 +1,18 @@ +{ + "name": "console-sample-in-node", + "version": "1.0.0", + "description": "Runs the MONO WASM Console sample in the NodeJS environment", + "main": "runtime.js", + "scripts": { + "test": "node --trace-warnings runtime.js --run Wasm.Console.Sample.dll" + }, + "author": "Microsoft", + "license": "MIT", + "dependencies": { + "fs": "0.0.1-security", + "node-fetch": "^2.6.1", + "path": "^0.12.7", + "perf_hooks": "0.0.1", + "ws": "^7.5.0" + } +} diff --git a/src/mono/wasm/build/README.md b/src/mono/wasm/build/README.md index ea7b73ebe2214f..b82271a70f3b92 100644 --- a/src/mono/wasm/build/README.md +++ b/src/mono/wasm/build/README.md @@ -45,6 +45,7 @@ The various task inputs correspond to properties as: - `run-v8.sh` script is emitted to `$(WasmRunV8ScriptPath)` which defaults to `$(WasmAppDir)`. - To control it's generation use `$(WasmGenerateRunV8Script)` (false by default) + - Note that if building for NodeJS you can also use `$(WasmGenerateRunV8Script)` to generate a `run-node.sh` or `run-v8.cmd` file (depending on OS used to build). This should be a step towards eventually having this build as a sdk. diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index b886f327d71626..ce7109a4790515 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -154,6 +154,7 @@ + @@ -175,6 +176,34 @@ + + + $(WasmAppDir)run-node.sh + $(WasmAppDir)run-node.cmd + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 8b3395f4ec50e8..8001f14cace747 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -4,21 +4,19 @@ // //glue code to deal with the differences between chrome, ch, d8, jsc and sm. -var is_browser = typeof window != "undefined"; +const is_browser = typeof window != "undefined"; +const is_node = !is_browser && typeof process != 'undefined'; // if the engine doesn't provide a console -if (typeof (console) === "undefined") { - var console = { +if (typeof (console) === "undefined"){ + console = { log: globalThis.print, clear: function () { } }; } - -globalThis.testConsole = console; - function proxyMethod (prefix, func, asJson) { return function() { - var args = [...arguments]; + let args = [...arguments]; if (asJson) { func (JSON.stringify({ method: prefix, @@ -31,15 +29,15 @@ function proxyMethod (prefix, func, asJson) { }; }; -var methods = ["debug", "trace", "warn", "info", "error"]; -for (var m of methods) { - if (typeof(console[m]) != "function") { +const methods = ["debug", "trace", "warn", "info", "error"]; +for (let m of methods) { + if (typeof(console[m]) !== "function") { console[m] = proxyMethod(`console.${m}: `, console.log, false); } } function proxyJson (func) { - for (var m of ["log", ...methods]) + for (let m of ["log", ...methods]) console[m] = proxyMethod(`console.${m}`,func, true); } @@ -49,28 +47,16 @@ if (is_browser) { let consoleWebSocket = new WebSocket(consoleUrl); consoleWebSocket.onopen = function(event) { proxyJson(function (msg) { consoleWebSocket.send (msg); }); - globalThis.testConsole.log("browser: Console websocket connected."); + console.log("browser: Console websocket connected."); }; consoleWebSocket.onerror = function(event) { - console.log(`websocket error: ${event}`); + console.error(`websocket error: ${event}`); }; - - // We expect to be run by tests/runtime/run.js which passes in the arguments using http parameters - var url = new URL (decodeURI (window.location)); - arguments = []; - for (var v of url.searchParams) { - if (v [0] == "arg") { - arguments.push (v [1]); - } - } } -//proxyJson(console.log); - - -let print = globalThis.testConsole.log; -let printErr = globalThis.testConsole.error; -if (typeof crypto === 'undefined') { +if (is_node) { + var crypto = require('crypto'); +} else if (typeof crypto === 'undefined') { // **NOTE** this is a simple insecure polyfill for testing purposes only // /dev/random doesn't work on js shells, so define our own // See library_fs.js:createDefaultDevices () @@ -81,8 +67,9 @@ if (typeof crypto === 'undefined') { } } } - -if (typeof performance == 'undefined') { +if (is_node) { + var { performance } = require("perf_hooks"); +} else if (typeof performance === 'undefined') { // performance.now() is used by emscripten and doesn't work in JSC var performance = { now: function () { @@ -91,141 +78,213 @@ if (typeof performance == 'undefined') { } } +// get arguments +let testArguments = []; try { - if (typeof arguments == "undefined") - arguments = WScript.Arguments; - load = WScript.LoadScriptFile; - read = WScript.LoadBinaryFile; -} catch (e) { -} + if (is_node) { + testArguments = process.argv.slice (2); + + }else if (is_browser) { + // We expect to be run by tests/runtime/run.js which passes in the arguments using http parameters + const url = new URL (decodeURI (window.location)); + for (let param of url.searchParams) { + if (param [0] == "arg") { + testArguments.push (param [1]); + } + } -try { - if (typeof arguments == "undefined") { - if (typeof scriptArgs !== "undefined") - arguments = scriptArgs; + }else if (typeof arguments === "undefined") { + if (typeof scriptArgs !== "undefined") { + testArguments = scriptArgs; + + }else if (typeof WScript !== "undefined" && WScript.Arguments){ + testArguments = WScript.Arguments; + } + } else{ + testArguments = arguments; } } catch (e) { + console.error(e); } -if (arguments === undefined) - arguments = []; +// abstract all IO into a compact universally available method so that it is consistent and reliable +const IOHandler = { + load: null, // load js file into project and evaluate it + read: null, // return the contents of a file as a string + + init: function() { + // load: function that loads and executes a script + let loadFunc = globalThis.load; // shells (v8, JavaScriptCore, Spidermonkey) + if (!loadFunc){ + if (typeof WScript !== "undefined"){ // Chakra + loadFunc = WScript.LoadScriptFile; + + } else if (is_node) { // NodeJS + loadFunc = async function (file) { + let req = require(file); + + // sometimes the require returns a function which returns a promise (such as in dotnet.js). + // othertimes it returns the variable or object that is needed. We handle both cases + if (typeof(req) === 'function') { + req = await req(Module); // pass Module so emsdk can use it + } -//end of all the nice shell glue code. + // add to the globalThis the file under the namespace of the upercase filename without js extension + globalThis[file.substring(2,file.length - 3).replace("-","_").toUpperCase()] = req; + }; + } else if (is_browser) { // vanila JS in browser + loadFunc = function (file) { + const script = document.createElement ("script"); + script.src = file; + document.head.appendChild (script); + } + } + } + IOHandler.load = async (file) => await loadFunc(file); + + // read: function that just reads a file into a variable + let readFunc = globalThis.read; // shells (v8, JavaScriptCore, Spidermonkey) + if (!readFunc){ + if (typeof WScript !== "undefined"){ + readFunc = WScript.LoadBinaryFile; // Chakra + + } else if (is_node) { // NodeJS + const fs = require ('fs'); + readFunc = function (path) { + return fs.readFileSync(path).toString(); + }; + } else if (is_browser) { // vanila JS in browser + readFunc = fetch; + } + } + IOHandler.read = async (file) => await readFunc(file); + }, -// set up a global variable to be accessed in App.init -var testArguments = arguments; + writeContentToFile: function(content, path) { // writes a string to a file + const stream = FS.open(path, 'w+'); + FS.write(stream, content, 0, content.length, 0); + FS.close(stream); + }, + + fetch: function(asset, params) { // returns an async fetch request in the form of {ok: boolean, url: string, arrayBuffer: Promise} + if (is_browser) { + return fetch (asset, params); + + } else { // shells and node + return new Promise ((resolve, reject) => { + let bytes = null, error = null; + try { + if (is_node){ + const fs = require ('fs'); + const buffer = fs.readFileSync(asset); + bytes = buffer.buffer; + } else { + bytes = read (asset, 'binary'); + } + } catch (exc) { + error = exc; + } + const response = { ok: (bytes && !error), url: asset, + arrayBuffer: function () { + return new Promise ((resolve2, reject2) => { + if (error) + reject2 (error); + else + resolve2 (new Uint8Array (bytes)); + } + )} + } + resolve (response); + }) + } + } +}; +IOHandler.init(); +// end of all the nice shell glue code. function test_exit (exit_code) { if (is_browser) { // Notify the selenium script Module.exit_code = exit_code; - Module.print ("WASM EXIT " + exit_code); - var tests_done_elem = document.createElement ("label"); + console.log ("WASM EXIT " + exit_code); + const tests_done_elem = document.createElement ("label"); tests_done_elem.id = "tests_done"; tests_done_elem.innerHTML = exit_code.toString (); document.body.appendChild (tests_done_elem); + } else if (is_node) { + Module.exit_code = exit_code; + console.log ("WASM EXIT " + exit_code); } else { Module.wasm_exit (exit_code); } } function fail_exec (reason) { - Module.print (reason); + console.error (reason); test_exit (1); } -function inspect_object (o) { - var r = ""; - for(var p in o) { - var t = typeof o[p]; - r += "'" + p + "' => '" + t + "', "; - } - return r; -} - // Preprocess arguments -var args = testArguments; -console.info("Arguments: " + testArguments); -profilers = []; -setenv = {}; -runtime_args = []; -enable_gc = true; -enable_zoneinfo = false; -working_dir='/'; -while (args !== undefined && args.length > 0) { - if (args [0].startsWith ("--profile=")) { - var arg = args [0].substring ("--profile=".length); +console.log("Arguments: " + testArguments); +let profilers = []; +let setenv = {}; +let runtime_args = []; +let enable_gc = true; +let working_dir='/'; +while (testArguments !== undefined && testArguments.length > 0) { + if (testArguments [0].startsWith ("--profile=")) { + const arg = testArguments [0].substring ("--profile=".length); profilers.push (arg); - args = args.slice (1); - } else if (args [0].startsWith ("--setenv=")) { - var arg = args [0].substring ("--setenv=".length); - var parts = arg.split ('='); + testArguments = testArguments.slice (1); + } else if (testArguments [0].startsWith ("--setenv=")) { + const arg = testArguments [0].substring ("--setenv=".length); + const parts = arg.split ('='); if (parts.length != 2) - fail_exec ("Error: malformed argument: '" + args [0]); + fail_exec ("Error: malformed argument: '" + testArguments [0]); setenv [parts [0]] = parts [1]; - args = args.slice (1); - } else if (args [0].startsWith ("--runtime-arg=")) { - var arg = args [0].substring ("--runtime-arg=".length); - runtime_args.push (arg); - args = args.slice (1); - } else if (args [0] == "--disable-on-demand-gc") { + testArguments = testArguments.slice (1); + } else if (testArguments [0].startsWith ("--runtime-arg=")) { + const arg = testArguments [0].substring ("--runtime-arg=".length); + runtime_args = testArguments.push (arg); + testArguments = testArguments.slice (1); + } else if (testArguments [0] == "--disable-on-demand-gc") { enable_gc = false; - args = args.slice (1); - } else if (args [0].startsWith ("--working-dir=")) { - var arg = args [0].substring ("--working-dir=".length); + testArguments = testArguments.slice (1); + } else if (testArguments [0].startsWith ("--working-dir=")) { + const arg = testArguments [0].substring ("--working-dir=".length); working_dir = arg; - args = args.slice (1); + testArguments = testArguments.slice (1); } else { break; } } -testArguments = args; // cheap way to let the testing infrastructure know we're running in a browser context (or not) setenv["IsBrowserDomSupported"] = is_browser.toString().toLowerCase(); -function writeContentToFile(content, path) -{ - var stream = FS.open(path, 'w+'); - FS.write(stream, content, 0, content.length, 0); - FS.close(stream); -} - -function loadScript (url) -{ - if (is_browser) { - var script = document.createElement ("script"); - script.src = url; - document.head.appendChild (script); - } else { - load (url); - } -} - +// must be var as dotnet.js uses it var Module = { mainScriptUrlOrBlob: "dotnet.js", config: null, - print, - printErr, preInit: async function() { - Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); + Module.config = await Module.MONO.mono_wasm_load_config("./mono-config.json"); }, - + onAbort: function(x) { - print ("ABORT: " + x); - var err = new Error(); - print ("Stacktrace: \n"); - print (err.stack); + console.log ("ABORT: " + x); + const err = new Error(); + console.log ("Stacktrace: \n"); + console.error (err.stack); test_exit (1); }, onRuntimeInitialized: function () { // Have to set env vars here to enable setting MONO_LOG_LEVEL etc. - for (var variable in setenv) { - MONO.mono_wasm_setenv (variable, setenv [variable]); + for (let variable in setenv) { + Module.MONO.mono_wasm_setenv (variable, setenv [variable]); } if (!enable_gc) { @@ -233,13 +292,13 @@ var Module = { } Module.config.loaded_cb = function () { - let wds = FS.stat (working_dir); - if (wds === undefined || !FS.isDir (wds.mode)) { + let wds = Module.FS.stat (working_dir); + if (wds === undefined || !Module.FS.isDir (wds.mode)) { fail_exec (`Could not find working directory ${working_dir}`); return; } - FS.chdir (working_dir); + Module.FS.chdir (working_dir); App.init (); }; Module.config.fetch_file_cb = function (asset) { @@ -249,76 +308,45 @@ var Module = { /* var content = new Uint8Array (read (asset, 'binary')); var path = asset.substr(Module.config.deploy_prefix.length); - writeContentToFile(content, path); + IOHandler.writeContentToFile(content, path); */ - - if (typeof window != 'undefined') { - return fetch (asset, { credentials: 'same-origin' }); - } else { - // The default mono_load_runtime_and_bcl defaults to using - // fetch to load the assets. It also provides a way to set a - // fetch promise callback. - // Here we wrap the file read in a promise and fake a fetch response - // structure. - return new Promise ((resolve, reject) => { - var bytes = null, error = null; - try { - bytes = read (asset, 'binary'); - } catch (exc) { - error = exc; - } - var response = { ok: (bytes && !error), url: asset, - arrayBuffer: function () { - return new Promise ((resolve2, reject2) => { - if (error) - reject2 (error); - else - resolve2 (new Uint8Array (bytes)); - } - )} - } - resolve (response); - }) - } + return IOHandler.fetch (asset, { credentials: 'same-origin' }); }; - MONO.mono_load_runtime_and_bcl_args (Module.config); + Module.MONO.mono_load_runtime_and_bcl_args (Module.config); }, }; -loadScript ("dotnet.js"); +globalThis.Module = Module; // needed as some functions (such as call_static_method) need access to Module. -const IGNORE_PARAM_COUNT = -1; - -var App = { +const App = { init: function () { - var wasm_set_main_args = Module.cwrap ('mono_wasm_set_main_args', 'void', ['number', 'number']); - var wasm_strdup = Module.cwrap ('mono_wasm_strdup', 'number', ['string']); + const wasm_set_main_args = Module.cwrap ('mono_wasm_set_main_args', 'void', ['number', 'number']); + const wasm_strdup = Module.cwrap ('mono_wasm_strdup', 'number', ['string']); Module.wasm_exit = Module.cwrap ('mono_wasm_exit', 'void', ['number']); console.info("Initializing....."); - for (var i = 0; i < profilers.length; ++i) { - var init = Module.cwrap ('mono_wasm_load_profiler_' + profilers [i], 'void', ['string']) - + for (let i = 0; i < profilers.length; ++i) { + const init = Module.cwrap ('mono_wasm_load_profiler_' + profilers [i], 'void', ['string']); init (""); } - if (args.length == 0) { + if (testArguments.length == 0) { fail_exec ("Missing required --run argument"); return; } - if (args[0] == "--regression") { - var exec_regression = Module.cwrap ('mono_wasm_exec_regression', 'number', ['number', 'string']) + if (testArguments[0] == "--regression") { + const exec_regression = Module.cwrap ('mono_wasm_exec_regression', 'number', ['number', 'string']); - var res = 0; + let res = 0; try { - res = exec_regression (10, args[1]); - Module.print ("REGRESSION RESULT: " + res); + res = exec_regression (10, testArguments[1]); + console.log ("REGRESSION RESULT: " + res); } catch (e) { - Module.print ("ABORT: " + e); - print (e.stack); + console.error ("ABORT: " + e); + console.error (e.stack); res = 1; } @@ -329,32 +357,32 @@ var App = { } if (runtime_args.length > 0) - MONO.mono_wasm_set_runtime_options (runtime_args); + Module.MONO.mono_wasm_set_runtime_options (runtime_args); - if (args[0] == "--run") { + if (testArguments[0] == "--run") { // Run an exe - if (args.length == 1) { + if (testArguments.length == 1) { fail_exec ("Error: Missing main executable argument."); return; } - main_assembly_name = args[1]; - var app_args = args.slice (2); + main_assembly_name = testArguments[1]; + const app_args = testArguments.slice (2); - var main_argc = args.length - 2 + 1; - var main_argv = Module._malloc (main_argc * 4); + const main_argc = testArguments.length - 2 + 1; + const main_argv = Module._malloc (main_argc * 4); aindex = 0; - Module.setValue (main_argv + (aindex * 4), wasm_strdup (args [1]), "i32") + Module.setValue (main_argv + (aindex * 4), wasm_strdup (testArguments [1]), "i32"); aindex += 1; - for (var i = 2; i < args.length; ++i) { - Module.setValue (main_argv + (aindex * 4), wasm_strdup (args [i]), "i32"); + for (let i = 2; i < testArguments.length; ++i) { + Module.setValue (main_argv + (aindex * 4), wasm_strdup (testArguments [i]), "i32"); aindex += 1; } wasm_set_main_args (main_argc, main_argv); // Automatic signature isn't working correctly - let result = Module.mono_call_assembly_entry_point (main_assembly_name, [app_args], "m"); - let onError = function (error) + const result = Module.mono_call_assembly_entry_point (main_assembly_name, [app_args], "m"); + const onError = function (error) { console.error (error); if (error.stack) @@ -369,19 +397,29 @@ var App = { } } else { - fail_exec ("Unhandled argument: " + args [0]); + fail_exec ("Unhandled argument: " + testArguments [0]); } }, call_test_method: function (method_name, args, signature) { + // note: arguments here is the array of arguments passsed to this function if ((arguments.length > 2) && (typeof (signature) !== "string")) throw new Error("Invalid number of arguments for call_test_method"); - var fqn = "[System.Private.Runtime.InteropServices.JavaScript.Tests]System.Runtime.InteropServices.JavaScript.Tests.HelperMarshal:" + method_name; + const fqn = "[System.Private.Runtime.InteropServices.JavaScript.Tests]System.Runtime.InteropServices.JavaScript.Tests.HelperMarshal:" + method_name; try { - return BINDING.call_static_method(fqn, args || [], signature); + return Module.BINDING.call_static_method(fqn, args || [], signature); } catch (exc) { console.error("exception thrown in", fqn); throw exc; } } }; + +// load the config and runtime files which will start the runtime init and subsiquently the tests +// uses promise chain as loading is async but we can't use await here +IOHandler + .load ("./dotnet.js") + .catch(function(err) { + console.error(err); + fail_exec("failed to load the mono-config.js or dotnet.js files"); + }); diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 36837f62cf7096..469efe1ff7a2f3 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -60,15 +60,15 @@ var MonoSupportLib = { _id_table: {}, pump_message: function () { - if (!this.mono_background_exec) - this.mono_background_exec = Module.cwrap ("mono_background_exec", null); + if (!MONO.mono_background_exec) + MONO.mono_background_exec = Module.cwrap ("mono_background_exec", null); while (MONO.timeout_queue.length > 0) { --MONO.pump_count; MONO.timeout_queue.shift()(); } while (MONO.pump_count > 0) { --MONO.pump_count; - this.mono_background_exec (); + MONO.mono_background_exec (); } }, @@ -2522,17 +2522,17 @@ var MonoSupportLib = { }, mono_set_timeout: function (timeout, id) { - if (!this.mono_set_timeout_exec) - this.mono_set_timeout_exec = Module.cwrap ("mono_set_timeout_exec", null, [ 'number' ]); + if (!MONO.mono_set_timeout_exec) + MONO.mono_set_timeout_exec = Module.cwrap ("mono_set_timeout_exec", null, [ 'number' ]); if (typeof globalThis.setTimeout === 'function') { globalThis.setTimeout (function () { - this.mono_set_timeout_exec (id); + MONO.mono_set_timeout_exec (id); }, timeout); } else { ++MONO.pump_count; MONO.timeout_queue.push(function() { - this.mono_set_timeout_exec (id); + MONO.mono_set_timeout_exec (id); }) } }, diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 489d88259f5f3e..3512d18dc52275 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -16,7 +16,7 @@ - + @@ -66,12 +66,13 @@ <_EmccCommonFlags Include="-s ALLOW_MEMORY_GROWTH=1" /> <_EmccCommonFlags Include="-s NO_EXIT_RUNTIME=1" /> <_EmccCommonFlags Include="-s FORCE_FILESYSTEM=1" /> - <_EmccCommonFlags Include="-s "EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']"" /> + <_EmccCommonFlags Include="-s "EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction', 'MONO', 'BINDING', 'DOTNET', 'FS']"" /> <_EmccCommonFlags Include="-s "EXPORTED_FUNCTIONS=['_putchar']"" /> <_EmccCommonFlags Include="--source-map-base http://example.com" /> <_EmccCommonFlags Include="-emit-llvm" /> - - <_EmccCommonFlags Include="-s MODULARIZE=1" Condition="'$(WasmEnableES6)' != 'false'" /> + + <_EmccCommonFlags Include="-s MODULARIZE=1" Condition="'$(TargetOS)' == 'Node'"/> + <_EmccCommonFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' != 'false'" /> @@ -271,6 +272,7 @@ + diff --git a/src/tasks/AotCompilerTask/MonoAOTCompiler.props b/src/tasks/AotCompilerTask/MonoAOTCompiler.props index 097758ae0c783b..6e437fb86fcbdf 100644 --- a/src/tasks/AotCompilerTask/MonoAOTCompiler.props +++ b/src/tasks/AotCompilerTask/MonoAOTCompiler.props @@ -24,7 +24,7 @@ - + diff --git a/src/tasks/tasks.proj b/src/tasks/tasks.proj index e681cfd2740ddc..21773a387c8fd1 100644 --- a/src/tasks/tasks.proj +++ b/src/tasks/tasks.proj @@ -6,9 +6,9 @@ + Condition="'$(TargetOS)' != 'Browser' and '$(TargetOS)' != 'Node'" /> + Condition="'$(TargetOS)' != 'Browser' and '$(TargetOS)' != 'Node'" /> - + - <_PropertiesToPass Condition="'$(TargetOS)' == 'Browser' Or '$(TargetOS)' == 'Android'"> + <_PropertiesToPass Condition="'$(TargetOS)' == 'Browser' or '$(TargetOS)' == 'Node' Or '$(TargetOS)' == 'Android'"> $(_PropertiesToPass); IncludeDotNetCli=$(IncludeDotNetCli); DotNetCliRuntime=$(DotNetCliRuntime); @@ -81,7 +81,7 @@ osx-$(TargetArchitecture) linux-$(TargetArchitecture) linux-musl-$(TargetArchitecture) - browser-wasm + browser-wasm android-$(TargetArchitecture) @@ -98,7 +98,7 @@ $(HelixRuntimeRid) - + sdk $([System.IO.File]::ReadAllText('$(RepoRoot)global.json')) $([System.Text.RegularExpressions.Regex]::Match($(GlobalJsonContent), '(%3F<="dotnet": ").*(%3F=")')) diff --git a/src/tests/Common/tests.targets b/src/tests/Common/tests.targets index 639d08a0863d24..bf179816169fb5 100644 --- a/src/tests/Common/tests.targets +++ b/src/tests/Common/tests.targets @@ -55,7 +55,7 @@ $(CORE_ROOT)\corerun $(CORE_ROOT)\corerun.exe - $(DotnetRoot)/dotnet + $(DotnetRoot)/dotnet + Condition="'@(NativeProjectBinaries)' == '' And '$(TargetOS)' != 'Browser' And '$(TargetOS)' != 'Node' And '$(TargetOS)' != 'Android'"/> - + false false diff --git a/src/tests/Interop/ICastable/Castable.csproj b/src/tests/Interop/ICastable/Castable.csproj index 3d721d1b432e27..459ac5630e16d2 100644 --- a/src/tests/Interop/ICastable/Castable.csproj +++ b/src/tests/Interop/ICastable/Castable.csproj @@ -2,7 +2,7 @@ Exe true - true + true