Skip to content

Commit 64649da

Browse files
authored
[wasm] updated samples for ES6 and CJS (#62292)
* samples for ES6 and CJS * hack for in-tree linking * binlog for samples
1 parent 6a9bfee commit 64649da

36 files changed

Lines changed: 315 additions & 94 deletions

eng/pipelines/runtime-manual.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ jobs:
503503
or(
504504
eq(variables['librariesContainsChange'], true),
505505
eq(variables['monoContainsChange'], true),
506+
eq(variables['isManualOrIsNotPR'], true),
506507
eq(variables['isFullMatrix'], true))
507508
508509
#

src/libraries/sendtohelixhelp.proj

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@
489489
<HelixCorrelationPayload Include="chromedriver" Uri="$(ChromeDriverUrl)" Condition="'$(NeedsToRunOnBrowser)' == 'true'" />
490490

491491
<_WorkItem Include="$(WorkItemArchiveWildCard)" Exclude="$(HelixCorrelationPayload)" />
492-
<_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Console.*.Test.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'WasmTestOnBrowser' and '$(Scenario)' != 'BuildWasmApps'" />
492+
<_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Console.*.Test.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'WasmTestOnBrowser' and '$(Scenario)' != 'BuildWasmApps' and '$(Scenario)' != 'WasmDebuggerTests'" />
493493
<_WorkItem Include="$(TestArchiveRoot)runonly/**/WebAssembly.Browser.*.Test.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnBrowser'" />
494494
<_WorkItem Include="$(TestArchiveRoot)browseronly/**/*.zip" Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnBrowser'" />
495495

@@ -542,20 +542,48 @@
542542
<XHarnessCommand>%XHARNESS_COMMAND%</XHarnessCommand>
543543
</PropertyGroup>
544544

545-
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'WasmTestOnBrowser' and '$(Scenario)' != 'WasmTestOnNodeJs' and '$(Scenario)' != 'BuildWasmApps' and '$(Scenario)' != 'WasmDebuggerTests'">
546-
<!-- Create a work item for run-only WASM console app -->
547-
<_RunOnlyWorkItem Include="$(TestArchiveRoot)runonly/**/*.Console.Sample.zip" />
548-
<HelixWorkItem Include="@(_RunOnlyWorkItem -> '%(FileName)')" >
545+
<!-- Create a work item for run-only WASM console V8 apps -->
546+
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and ('$(Scenario)' == 'normal' or '$(Scenario)' == '')">
547+
<_RunOnlyWorkItemCJS Include="$(TestArchiveRoot)runonly/**/*.Console.V8.CJS.Sample.zip" />
548+
<HelixWorkItem Include="@(_RunOnlyWorkItemCJS -> '%(FileName)')">
549549
<PayloadArchive>%(Identity)</PayloadArchive>
550550
<!-- No RunTests script generated for the sample project so we just use the direct command -->
551-
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --engine=V8 --engine-arg=--stack-trace-limit=1000 --js-file=test-main.js --output-directory=$(XHarnessOutput) -- --run %(FileName).dll</Command>
551+
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --engine=V8 --engine-arg=--stack-trace-limit=1000 --js-file=main.cjs --output-directory=$(XHarnessOutput) -- --run %(FileName).dll</Command>
552+
</HelixWorkItem>
553+
<_RunOnlyWorkItemES6 Include="$(TestArchiveRoot)runonly/**/*.Console.V8.ES6.Sample.zip" />
554+
<HelixWorkItem Include="@(_RunOnlyWorkItemES6 -> '%(FileName)')">
555+
<PayloadArchive>%(Identity)</PayloadArchive>
556+
<!-- No RunTests script generated for the sample project so we just use the direct command -->
557+
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --engine=V8 --engine-arg=--stack-trace-limit=1000 --js-file=v8shim.cjs --output-directory=$(XHarnessOutput) -- --run %(FileName).dll</Command>
552558
</HelixWorkItem>
553559
</ItemGroup>
554560

561+
<!-- Create a work item for run-only WASM console NodeJs apps -->
562+
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnNodeJs'">
563+
<_RunOnlyWorkItemCJS Include="$(TestArchiveRoot)runonly/**/*.Console.Node.CJS.Sample.zip" />
564+
<HelixWorkItem Include="@(_RunOnlyWorkItemCJS -> '%(FileName)')">
565+
<PayloadArchive>%(Identity)</PayloadArchive>
566+
<!-- No RunTests script generated for the sample project so we just use the direct command -->
567+
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --engine=NodeJS --engine-arg=--stack-trace-limit=1000 --js-file=main.cjs --output-directory=$(XHarnessOutput) -- --run %(FileName).dll</Command>
568+
</HelixWorkItem>
569+
<_RunOnlyWorkItemES6 Include="$(TestArchiveRoot)runonly/**/*.Console.Node.ES6.Sample.zip" />
570+
<HelixWorkItem Include="@(_RunOnlyWorkItemES6 -> '%(FileName)')">
571+
<PayloadArchive>%(Identity)</PayloadArchive>
572+
<!-- No RunTests script generated for the sample project so we just use the direct command -->
573+
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --engine=NodeJS --engine-arg=--stack-trace-limit=1000 --js-file=main.mjs --output-directory=$(XHarnessOutput) -- --run %(FileName).dll</Command>
574+
</HelixWorkItem>
575+
</ItemGroup>
576+
577+
<!-- Create a work items for run-only WASM browser apps -->
555578
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' == 'WasmTestOnBrowser'">
556-
<!-- Create a work item for run-only WASM browser app -->
557-
<_RunOnlyWorkItem Include="$(TestArchiveRoot)runonly/**/*.Browser.Sample.zip" />
558-
<HelixWorkItem Include="@(_RunOnlyWorkItem -> '%(FileName)')" >
579+
<_RunOnlyWorkItemCJS Include="$(TestArchiveRoot)runonly/**/*.Browser.CJS.Sample.zip" />
580+
<HelixWorkItem Include="@(_RunOnlyWorkItemCJS -> '%(FileName)')" >
581+
<PayloadArchive>%(Identity)</PayloadArchive>
582+
<!-- No RunTests script generated for the sample project so we just use the direct command -->
583+
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --browser=Chrome $(XHarnessBrowserPathArg) --html-file=index.html --output-directory=$(XHarnessOutput) -- %(FileName).dll</Command>
584+
</HelixWorkItem>
585+
<_RunOnlyWorkItemES6 Include="$(TestArchiveRoot)runonly/**/*.Browser.ES6.Sample.zip" />
586+
<HelixWorkItem Include="@(_RunOnlyWorkItemES6 -> '%(FileName)')" >
559587
<PayloadArchive>%(Identity)</PayloadArchive>
560588
<!-- No RunTests script generated for the sample project so we just use the direct command -->
561589
<Command>$(ExecXHarnessCmd) wasm $(XHarnessCommand) --app=. --browser=Chrome $(XHarnessBrowserPathArg) --html-file=index.html --output-directory=$(XHarnessOutput) -- %(FileName).dll</Command>

src/libraries/tests.proj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,12 @@
324324
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Compression\tests\System.IO.Compression.Tests.csproj" />
325325
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.Compression.ZipFile\tests\System.IO.Compression.ZipFile.Tests.csproj" />
326326
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.Xml\tests\Xslt\XslCompiledTransformApi\System.Xml.Xsl.XslCompiledTransformApi.Tests.csproj" />
327-
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console\Wasm.Console.Sample.csproj" />
328-
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser\Wasm.Browser.Sample.csproj" />
327+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console-v8-es6\Wasm.Console.V8.ES6.Sample.csproj" />
328+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console-v8-cjs\Wasm.Console.V8.CJS.Sample.csproj" />
329+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console-node-es6\Wasm.Console.Node.ES6.Sample.csproj" />
330+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\console-node-cjs\Wasm.Console.Node.CJS.Sample.csproj" />
331+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser-es6\Wasm.Browser.ES6.Sample.csproj" />
332+
<ProjectExclusions Include="$(MonoProjectRoot)sample\wasm\browser\Wasm.Browser.CJS.Sample.csproj" />
329333
</ItemGroup>
330334

331335
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(BrowserHost)' == 'windows' and '$(Scenario)' == 'WasmTestOnBrowser' and '$(RunDisabledWasmTestsOnWindows)' != 'true'">

src/mono/sample/mbr/browser/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h3 id="header">Wasm Hot Reload Sample</h3>
1919
const App = {
2020
init: function () {
2121
const update = BINDING.bind_static_method("[WasmDelta] Sample.Test:Update");
22-
const testMeaning = BINDING.bind_static_method("[Wasm.Browser.Sample] Sample.Test:TestMeaning");
22+
const testMeaning = BINDING.bind_static_method("[WasmDelta] Sample.Test:TestMeaning");
2323
const outElement = document.getElementById("out");
2424
document.getElementById("update").addEventListener("click", function () {
2525
update();

src/mono/sample/wasm/Directory.Build.targets

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
<Import Project="$(MonoProjectRoot)\wasm\build\WasmApp.InTree.targets" />
44

55
<Target Name="BuildSampleInTree"
6-
Inputs="Program.cs"
7-
Outputs="bin/$(Configuration)/AppBundle/dotnet.wasm">
6+
Inputs="
7+
Program.cs;
8+
$(_WasmMainJSFileName);
9+
"
10+
Outputs="
11+
bin/$(Configuration)/AppBundle/dotnet.wasm;
12+
bin/$(Configuration)/AppBundle/$(_WasmMainJSFileName);
13+
">
814
<Error Condition="'$(WasmMainJSPath)' == ''" Text="%24(WasmMainJSPath) property needs to be set" />
915
<PropertyGroup>
1016
<_ScriptExt Condition="'$(OS)' == 'Windows_NT'">.cmd</_ScriptExt>
@@ -13,7 +19,7 @@
1319
<_AOTFlag Condition="'$(RunAOTCompilation)' != ''">/p:RunAOTCompilation=$(RunAOTCompilation)</_AOTFlag>
1420
<_WasmMainJSFileName>$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
1521
</PropertyGroup>
16-
<Exec Command="$(_Dotnet) publish /p:Configuration=$(Configuration) /p:TargetArchitecture=wasm /p:TargetOS=Browser $(_AOTFlag) $(_SampleProject)" />
22+
<Exec Command="$(_Dotnet) publish -bl /p:Configuration=$(Configuration) /p:TargetArchitecture=wasm /p:TargetOS=Browser $(_AOTFlag) $(_SampleProject)" />
1723
</Target>
1824
<Target Name="RunSampleWithV8" DependsOnTargets="BuildSampleInTree">
1925
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TOP=../../../../..
2+
3+
include ../wasm.mk
4+
5+
ifneq ($(AOT),)
6+
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
7+
endif
8+
9+
PROJECT_NAME=Wasm.Browser.ES6.Sample.csproj
10+
11+
run: run-browser

src/mono/sample/wasm/browser-es6/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ namespace Sample
88
{
99
public class Test
1010
{
11-
public static void Main(string[] args)
11+
public static int Main(string[] args)
1212
{
1313
Console.WriteLine ("Hello, World!");
14+
return 0;
1415
}
1516

1617
[MethodImpl(MethodImplOptions.NoInlining)]

src/mono/sample/wasm/browser-es6/Wasm.Browser.ES6.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Configuration>Debug</Configuration>
43
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
54
<WasmMainJSPath>main.js</WasmMainJSPath>
65
<DebugSymbols>true</DebugSymbols>
@@ -16,5 +15,6 @@
1615
<PropertyGroup>
1716
<_SampleProject>Wasm.Browser.ES6.Sample.csproj</_SampleProject>
1817
</PropertyGroup>
18+
1919
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />
2020
</Project>

src/mono/sample/wasm/browser-es6/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<title>Sample ES6</title>
88
<meta charset="UTF-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10-
<link rel="modulepreload" href="main.js" />
11-
<link rel="modulepreload" href="dotnet.js" />
10+
<link rel="modulepreload" href="./main.js" />
11+
<link rel="modulepreload" href="./dotnet.js" />
1212
</head>
1313

1414
<body>
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import createDotnetRuntime from './dotnet.js'
22

3-
const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime((api) => ({
4-
disableDotnet6Compatibility: true,
5-
configSrc: "./mono-config.json",
6-
onAbort: () => {
7-
wasm_exit(1);
8-
},
9-
}));
10-
113
function wasm_exit(exit_code) {
4+
/* Set result in a tests_done element, to be read by xharness in runonly CI test */
5+
const tests_done_elem = document.createElement("label");
6+
tests_done_elem.id = "tests_done";
7+
tests_done_elem.innerHTML = exit_code.toString();
8+
document.body.appendChild(tests_done_elem);
9+
1210
console.log(`WASM EXIT ${exit_code}`);
1311
}
1412

15-
const testMeaning = BINDING.bind_static_method("[Wasm.Browser.ES6.Sample] Sample.Test:TestMeaning");
16-
const ret = testMeaning();
17-
document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`;
13+
try {
14+
const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime();
15+
const testMeaning = BINDING.bind_static_method("[Wasm.Browser.ES6.Sample] Sample.Test:TestMeaning");
16+
const ret = testMeaning();
17+
document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`;
18+
console.debug(`ret: ${ret}`);
1819

19-
console.debug(`ret: ${ret}`);
20-
let exit_code = ret == 42 ? 0 : 1;
21-
wasm_exit(exit_code);
20+
let exit_code = await MONO.mono_run_main("Wasm.Browser.ES6.Sample.dll", []);
21+
wasm_exit(exit_code);
22+
} catch (err) {
23+
console.log(`WASM ERROR ${err}`);
24+
wasm_exit(2);
25+
}

0 commit comments

Comments
 (0)