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

+315
-94
lines changed

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+
}

src/mono/sample/wasm/browser-legacy/Wasm.Browser.LegacySample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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>
76
<DebugType>embedded</DebugType>
87
<WasmDebugLevel>1</WasmDebugLevel>
9-
<WasmBuildNative>true</WasmBuildNative>
8+
<WasmEnableES6>false</WasmEnableES6>
9+
<RunAOTCompilation>false</RunAOTCompilation>
1010
</PropertyGroup>
1111

1212
<ItemGroup>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ <h3 id="header">Wasm Browser Legacy Sample</h3>
3535
},
3636
};
3737
</script>
38-
<script type="text/javascript" src="main.js"></script>
38+
<script type="text/javascript" src="./main.js"></script>
3939

40-
<script defer src="dotnet.js"></script>
40+
<script defer src="./dotnet.js"></script>
4141

4242
</body>
4343

src/mono/sample/wasm/browser/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ ifneq ($(AOT),)
66
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
77
endif
88

9-
PROJECT_NAME=Wasm.Browser.Sample.csproj
9+
PROJECT_NAME=Wasm.Browser.CJS.Sample.csproj
1010

1111
run: run-browser

src/mono/sample/wasm/browser/Wasm.Browser.Sample.csproj renamed to src/mono/sample/wasm/browser/Wasm.Browser.CJS.Sample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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>
76
<DebugType>embedded</DebugType>
87
<WasmDebugLevel>1</WasmDebugLevel>
8+
<WasmEnableES6>false</WasmEnableES6>
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<WasmExtraFilesToDeploy Include="index.html" />
1313
</ItemGroup>
1414

1515
<PropertyGroup>
16-
<_SampleProject>Wasm.Browser.Sample.csproj</_SampleProject>
16+
<_SampleProject>Wasm.Browser.CJS.Sample.csproj</_SampleProject>
1717
</PropertyGroup>
1818

1919
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />

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

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,16 @@
44
<html>
55

66
<head>
7-
<title>Sample</title>
7+
<title>Sample CJS</title>
88
<meta charset="UTF-8">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010
</head>
1111

1212
<body>
13-
<h3 id="header">Wasm Browser Sample</h3>
14-
Result from Sample.Test.TestMeaning: <span id="out"></span>
15-
<script type='text/javascript'>
16-
function set_exit_code(exit_code, reason) {
17-
/* Set result in a tests_done element, to be read by xharness */
18-
const tests_done_elem = document.createElement("label");
19-
tests_done_elem.id = "tests_done";
20-
tests_done_elem.innerHTML = exit_code.toString();
21-
document.body.appendChild(tests_done_elem);
22-
23-
console.log(`WASM EXIT ${exit_code}`);
24-
};
25-
26-
const App = {
27-
init: ({ MONO, BINDING, Module }) => {
28-
const testMeaning = BINDING.bind_static_method("[Wasm.Browser.Sample] Sample.Test:TestMeaning");
29-
const ret = testMeaning();
30-
document.getElementById("out").innerHTML = ret;
31-
32-
console.debug(`ret: ${ret}`);
33-
let exit_code = ret == 42 ? 0 : 1;
34-
set_exit_code(exit_code);
35-
},
36-
};
37-
</script>
38-
<script type="text/javascript" src="dotnet.js"></script>
39-
<script type="text/javascript" src="main.js"></script>
40-
13+
<h3 id="header">Wasm Browser CJS Sample</h3>
14+
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
15+
<script type="text/javascript" src="./dotnet.js"></script>
16+
<script type="text/javascript" src="./main.js"></script>
4117
</body>
4218

4319
</html>

src/mono/sample/wasm/browser/main.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
2-
// The .NET Foundation licenses this file to you under the MIT license.
1+
function wasm_exit(exit_code) {
2+
/* Set result in a tests_done element, to be read by xharness in runonly CI test */
3+
const tests_done_elem = document.createElement("label");
4+
tests_done_elem.id = "tests_done";
5+
tests_done_elem.innerHTML = exit_code.toString();
6+
document.body.appendChild(tests_done_elem);
37

4-
"use strict";
8+
console.log(`WASM EXIT ${exit_code}`);
9+
}
510

6-
createDotnetRuntime(({ MONO, BINDING, Module }) => ({
7-
disableDotnet6Compatibility: true,
8-
configSrc: "./mono-config.json",
9-
onDotnetReady: () => {
10-
try {
11-
App.init({ MONO, BINDING, Module });
12-
} catch (error) {
13-
set_exit_code(1, error);
14-
throw (error);
15-
}
16-
},
17-
onAbort: (error) => {
18-
set_exit_code(1, error);
19-
},
20-
}));
11+
async function loadRuntime() {
12+
globalThis.exports = {};
13+
await import("./dotnet.js");
14+
return globalThis.exports.createDotnetRuntime;
15+
}
16+
17+
async function main() {
18+
try {
19+
const createDotnetRuntime = await loadRuntime();
20+
const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime(() => ({
21+
disableDotnet6Compatibility: true,
22+
configSrc: "./mono-config.json",
23+
}));
24+
25+
const testMeaning = BINDING.bind_static_method("[Wasm.Browser.CJS.Sample] Sample.Test:TestMeaning");
26+
const ret = testMeaning();
27+
document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`;
28+
29+
console.debug(`ret: ${ret}`);
30+
let exit_code = ret == 42 ? 0 : 1;
31+
wasm_exit(exit_code);
32+
} catch (err) {
33+
console.log(`WASM ERROR ${err}`);
34+
wasm_exit(2)
35+
}
36+
}
37+
38+
main();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TOP=../../../../..
2+
3+
include ../wasm.mk
4+
5+
ifneq ($(AOT),)
6+
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
7+
endif
8+
9+
ifneq ($(V),)
10+
DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
11+
endif
12+
13+
PROJECT_NAME=Wasm.Console.CJS.Sample.csproj
14+
CONSOLE_DLL=Wasm.Console.CJS.Sample.dll
15+
16+
run: run-console

0 commit comments

Comments
 (0)