NativeSubDirectory="src"
IsNative="true" />
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
- Include="$(LibrariesNativeArtifactsPath)src\cjs\*.js"
- NativeSubDirectory="src\cjs"
- IsNative="true" />
- <LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
Include="$(LibrariesNativeArtifactsPath)src\es6\*.js"
NativeSubDirectory="src\es6"
IsNative="true" />
<_WasmPropertyNames Include="WasmDedup" />
<_WasmPropertyNames Include="WasmLinkIcalls" />
<_WasmPropertyNames Include="WasmNativeStrip" />
- <_WasmPropertyNames Include="WasmEnableES6" />
<_WasmPropertyNames Include="_WasmDevel" />
<_WasmPropertyNames Include="_WasmStrictVersionMatch" />
<_WasmPropertyNames Include="WasmEmitSymbolMap" />
<PlatformManifestFileEntry Include="icudt_optimal_no_CJK.dat" IsNative="true" />
<PlatformManifestFileEntry Include="package.json" IsNative="true" />
<PlatformManifestFileEntry Include="pal_random.lib.js" IsNative="true" />
- <PlatformManifestFileEntry Include="runtime.cjs.iffe.js" IsNative="true" />
- <PlatformManifestFileEntry Include="dotnet.cjs.lib.js" IsNative="true" />
- <PlatformManifestFileEntry Include="dotnet.cjs.pre.js" IsNative="true" />
- <PlatformManifestFileEntry Include="dotnet.cjs.post.js" IsNative="true" />
- <PlatformManifestFileEntry Include="dotnet.cjs.extpost.js" IsNative="true" />
<PlatformManifestFileEntry Include="runtime.es6.iffe.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.pre.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.lib.js" IsNative="true" />
+++ /dev/null
-TOP=../../../../..
-
-include ../wasm.mk
-
-ifneq ($(AOT),)
-override MSBUILD_ARGS+=/p:RunAOTCompilation=true
-endif
-
-PROJECT_NAME=Wasm.Browser.CJS.Sample.csproj
-
-run: run-browser
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Sample
-{
- public class Test
- {
- public static void Main(string[] args)
- {
- Console.WriteLine ("Hello, World!");
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static int TestMeaning()
- {
- return 42;
- }
- }
-}
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
- <WasmMainJSPath>main.js</WasmMainJSPath>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>embedded</DebugType>
- <WasmDebugLevel>1</WasmDebugLevel>
- <WasmEnableES6>false</WasmEnableES6>
-
- <GenerateRunScriptForSample Condition="'$(ArchiveTests)' == 'true'">true</GenerateRunScriptForSample>
- <RunScriptCommand>$(ExecXHarnessCmd) wasm test-browser --app=. --browser=Chrome $(XHarnessBrowserPathArg) --html-file=index.html --output-directory=$(XHarnessOutput) -- $(MSBuildProjectName).dll</RunScriptCommand>
- </PropertyGroup>
-
- <ItemGroup>
- <WasmExtraFilesToDeploy Include="index.html" />
- </ItemGroup>
-
- <PropertyGroup>
- <_SampleProject>Wasm.Browser.CJS.Sample.csproj</_SampleProject>
- </PropertyGroup>
-
- <Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />
-</Project>
+++ /dev/null
-<!DOCTYPE html>
-<!-- Licensed to the .NET Foundation under one or more agreements. -->
-<!-- The .NET Foundation licenses this file to you under the MIT license. -->
-<html>
-
-<head>
- <title>Sample CJS</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-</head>
-
-<body>
- <h3 id="header">Wasm Browser CJS Sample</h3>
- Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
- <script type="text/javascript" src="./main.js"></script>
-</body>
-
-</html>
\ No newline at end of file
+++ /dev/null
-function wasm_exit(exit_code, reason) {
- /* Set result in a tests_done element, to be read by xharness in runonly CI test */
- const tests_done_elem = document.createElement("label");
- tests_done_elem.id = "tests_done";
- tests_done_elem.innerHTML = exit_code.toString();
- if (exit_code) tests_done_elem.style.background = "red";
- document.body.appendChild(tests_done_elem);
-
- if (reason) console.error(reason);
- console.log(`WASM EXIT ${exit_code}`);
-}
-
-async function loadDotnet(file) {
- const cjsExport = new Promise((resolve) => {
- globalThis.__onDotnetRuntimeLoaded = (createDotnetRuntime) => {
- delete globalThis.__onDotnetRuntimeLoaded;
- resolve(createDotnetRuntime);
- };
- });
-
- await import(file);
- return await cjsExport;
-}
-
-
-async function main() {
- try {
- const createDotnetRuntime = await loadDotnet("./dotnet.js");
- const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime(() => ({
- disableDotnet6Compatibility: true,
- configSrc: "./mono-config.json",
- }));
-
- const testMeaning = BINDING.bind_static_method("[Wasm.Browser.CJS.Sample] Sample.Test:TestMeaning");
- const ret = testMeaning();
- document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`;
-
- console.debug(`ret: ${ret}`);
- let exit_code = ret == 42 ? 0 : 1;
- wasm_exit(exit_code);
- } catch (err) {
- wasm_exit(2, err)
- }
-}
-
-main();
\ No newline at end of file
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime.CompilerServices;
-
-namespace Sample
-{
- public class Test
- {
- public static void Main(string[] args)
- {
- Console.WriteLine ("Hello, World!");
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- public static int TestMeaning()
- {
- return 42;
- }
- }
-}
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
- <WasmMainJSPath>main.js</WasmMainJSPath>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>embedded</DebugType>
- <WasmDebugLevel>1</WasmDebugLevel>
- <WasmEnableES6>false</WasmEnableES6>
- <RunAOTCompilation>false</RunAOTCompilation>
- </PropertyGroup>
-
- <ItemGroup>
- <WasmExtraFilesToDeploy Include="index.html" />
- </ItemGroup>
-
- <PropertyGroup>
- <_SampleProject>Wasm.Browser.LegacySample.csproj</_SampleProject>
- </PropertyGroup>
-
- <Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />
-</Project>
+++ /dev/null
-<!DOCTYPE html>
-<!-- Licensed to the .NET Foundation under one or more agreements. -->
-<!-- The .NET Foundation licenses this file to you under the MIT license. -->
-<html>
-
-<head>
- <title>Legacy global module sample</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-</head>
-
-<body>
- <h3 id="header">Wasm Browser Legacy Sample</h3>
- Result from Sample.Test.TestMeaning: <span id="out"></span>
- <script type='text/javascript'>
- function wasm_exit(exit_code, reason) {
- /* Set result in a tests_done element, to be read by xharness */
- const tests_done_elem = document.createElement("label");
- tests_done_elem.id = "tests_done";
- tests_done_elem.innerHTML = exit_code.toString();
- if (exit_code) tests_done_elem.style.background = "red";
- document.body.appendChild(tests_done_elem);
-
- if(reason) console.error(reason);
- console.log(`WASM EXIT ${exit_code}`);
- };
-
- const App = {
- init: function () {
- const testMeaning = BINDING.bind_static_method("[Wasm.Browser.LegacySample] Sample.Test:TestMeaning");
- const ret = testMeaning();
- document.getElementById("out").innerHTML = ret;
-
- console.debug(`ret: ${ret}`);
- let exit_code = ret == 42 ? 0 : 1;
- wasm_exit(exit_code);
- },
- };
- </script>
- <script type="text/javascript" src="./main.js"></script>
-
- <script defer src="./dotnet.js"></script>
-
-</body>
-
-</html>
\ No newline at end of file
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-"use strict";
-var Module = {
- configSrc: "./mono-config.json",
- onDotnetReady: () => {
- try {
- App.init();
- } catch (error) {
- wasm_exit(1, error);
- throw (error);
- }
- },
- onAbort: (error) => {
- wasm_exit(1, error);
- },
-};
<html>
<head>
- <title>Sample CJS</title>
+ <title>Sample event pipe</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="modulepreload" href="./main.js" />
</head>
<body>
- <h3 id="header">Wasm Browser CJS Sample</h3>
+ <h3 id="header">Wasm Browser Event Pipe Sample</h3>
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
<script type="module" src="./dotnet.worker.js"></script>
<script type="module" src="./main.js"></script>
override MSBUILD_ARGS+=/p:RunAOTCompilation=true
endif
-PROJECT_NAME=Wasm.Browser.ES6.Sample.csproj
+PROJECT_NAME=Wasm.Browser.Sample.csproj
run: run-browser
<WasmExtraFilesToDeploy Include="index.html" />
</ItemGroup>
<PropertyGroup>
- <_SampleProject>Wasm.Browser.ES6.Sample.csproj</_SampleProject>
+ <_SampleProject>Wasm.Browser.Sample.csproj</_SampleProject>
</PropertyGroup>
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />
</Project>
<html>
<head>
- <title>Sample ES6</title>
+ <title>Wasm Browser Sample</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="modulepreload" href="./main.js" />
</head>
<body>
- <h3 id="header">Wasm Browser ES6 Sample</h3>
+ <h3 id="header">Wasm Browser Sample</h3>
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span>
<script type='module' src="./main.js"></script>
</body>
}
};
- const exports = await MONO.mono_wasm_get_assembly_exports("Wasm.Browser.ES6.Sample.dll");
+ const exports = await MONO.mono_wasm_get_assembly_exports("Wasm.Browser.Sample.dll");
const meaning = exports.Sample.Test.TestMeaning();
console.debug(`meaning: ${meaning}`);
if (!exports.Sample.Test.IsPrime(meaning)) {
console.debug(`ret: ${meaning}`);
}
- let exit_code = await MONO.mono_run_main("Wasm.Browser.ES6.Sample.dll", []);
+ let exit_code = await MONO.mono_run_main("Wasm.Browser.Sample.dll", []);
wasm_exit(exit_code);
} catch (err) {
wasm_exit(2, err);
+++ /dev/null
-TOP=../../../../..
-
-include ../wasm.mk
-
-ifneq ($(AOT),)
-override MSBUILD_ARGS+=/p:RunAOTCompilation=true
-endif
-
-ifneq ($(V),)
-DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
-endif
-
-PROJECT_NAME=Wasm.Console.Node.CJS.Sample.csproj
-CONSOLE_DLL=Wasm.Console.Node.CJS.Sample.dll
-MAIN_JS=main.cjs
-
-run: run-console-node
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Threading.Tasks;
-
-public class Test
-{
- public static async Task<int> Main(string[] args)
- {
- await Task.Delay(1);
- Console.WriteLine("Hello World!");
- return 42;
- }
-}
+++ /dev/null
-This sample uses CommonJS version of `dotnet.js` running on NodeJS
\ No newline at end of file
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
- <WasmMainJSPath>main.cjs</WasmMainJSPath>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>embedded</DebugType>
- <WasmDebugLevel>1</WasmDebugLevel>
- <WasmEnableES6>false</WasmEnableES6>
- <RunAOTCompilation>false</RunAOTCompilation>
-
- <GenerateRunScriptForSample Condition="'$(ArchiveTests)' == 'true'">true</GenerateRunScriptForSample>
- <ExpectedExitCode>42</ExpectedExitCode>
- <RunScriptCommand>$(ExecXHarnessCmd) wasm test --app=. --engine=NodeJS --engine-arg=--stack-trace-limit=1000 --js-file=main.cjs --output-directory=$(XHarnessOutput) --expected-exit-code $(ExpectedExitCode) -- --run $(MSBuildProjectName).dll</RunScriptCommand>
- </PropertyGroup>
-
- <ItemGroup>
- <WasmExtraFilesToDeploy Include="package.json" />
- </ItemGroup>
-
- <PropertyGroup>
- <_SampleProject>Wasm.Console.Node.CJS.Sample.csproj</_SampleProject>
- <_SampleAssembly>Wasm.Console.Node.CJS.Sample.dll</_SampleAssembly>
- </PropertyGroup>
-
- <Target Name="RunSample" DependsOnTargets="RunSampleWithNode" />
-</Project>
+++ /dev/null
-const createDotnetRuntime = require("./dotnet.js");
-
-async function main() {
- const { MONO } = await createDotnetRuntime();
- const app_args = process.argv.slice(2);
- const dllName = "Wasm.Console.Node.CJS.Sample.dll";
- await MONO.mono_run_main_and_exit(dllName, app_args);
-};
-main();
+++ /dev/null
-{
- "type": "commonjs"
-}
\ No newline at end of file
DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
endif
-PROJECT_NAME=Wasm.Console.Node.ES6.Sample.csproj
-CONSOLE_DLL=Wasm.Console.Node.ES6.Sample.dll
+PROJECT_NAME=Wasm.Console.Node.Sample.csproj
+CONSOLE_DLL=Wasm.Console.Node.Sample.dll
MAIN_JS=main.mjs
run: run-console-node
</ItemGroup>
<PropertyGroup>
- <_SampleProject>Wasm.Console.Node.ES6.Sample.csproj</_SampleProject>
- <_SampleAssembly>Wasm.Console.Node.ES6.Sample.dll</_SampleAssembly>
+ <_SampleProject>Wasm.Console.Node.Sample.csproj</_SampleProject>
+ <_SampleAssembly>Wasm.Console.Node.Sample.dll</_SampleAssembly>
</PropertyGroup>
<Target Name="RunSample" DependsOnTargets="RunSampleWithNode" />
}));
const app_args = process.argv.slice(2);
-const dllName = "Wasm.Console.Node.ES6.Sample.dll";
+const dllName = "Wasm.Console.Node.Sample.dll";
await MONO.mono_run_main_and_exit(dllName, app_args);
DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
endif
-PROJECT_NAME=Wasm.Console.Node.ES6.Sample.csproj
-CONSOLE_DLL=Wasm.Console.Node.ES6.Sample.dll
+PROJECT_NAME=Wasm.Console.Node.Sample.csproj
+CONSOLE_DLL=Wasm.Console.Node.Sample.dll
MAIN_JS=main.mjs
run: run-console-node
+++ /dev/null
-TOP=../../../../..
-
-include ../wasm.mk
-
-ifneq ($(AOT),)
-override MSBUILD_ARGS+=/p:RunAOTCompilation=true
-endif
-
-ifneq ($(V),)
-DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
-endif
-
-PROJECT_NAME=Wasm.Console.V8.CJS.Sample.csproj
-CONSOLE_DLL=Wasm.Console.V8.CJS.Sample.dll
-MAIN_JS=main.cjs
-
-run: run-console
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Threading.Tasks;
-
-public class Test
-{
- public static async Task<int> Main(string[] args)
- {
- await Task.Delay(1);
- Console.WriteLine("Hello World!");
- for (int i = 0; i < args.Length; i++) {
- Console.WriteLine($"args[{i}] = {args[i]}");
- }
- return 0;
- }
-}
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
- <WasmMainJSPath>main.cjs</WasmMainJSPath>
- <WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
- <WasmEnableES6>false</WasmEnableES6>
-
- <GenerateRunScriptForSample Condition="'$(ArchiveTests)' == 'true'">true</GenerateRunScriptForSample>
- <RunScriptCommand>$(ExecXHarnessCmd) wasm test --app=. --engine=V8 --engine-arg=--stack-trace-limit=1000 --js-file=main.cjs --output-directory=$(XHarnessOutput) -- --run $(MSBuildProjectName).dll</RunScriptCommand>
- </PropertyGroup>
-
- <PropertyGroup>
- <_SampleProject>Wasm.Console.V8.CJS.Sample.csproj</_SampleProject>
- <_SampleAssembly>Wasm.Console.V8.CJS.Sample.dll</_SampleAssembly>
- </PropertyGroup>
-
- <Target Name="RunSample" DependsOnTargets="RunSampleWithV8" />
-</Project>
+++ /dev/null
-load("./dotnet.js")
-
-const dllName = "Wasm.Console.V8.CJS.Sample.dll";
-const app_args = Array.from(arguments);
-
-async function main() {
- const { MONO } = await createDotnetRuntime();
- await MONO.mono_run_main_and_exit(dllName, app_args);
-}
-
-main();
\ No newline at end of file
DOTNET_MONO_LOG_LEVEL=--setenv=MONO_LOG_LEVEL=debug
endif
-PROJECT_NAME=Wasm.Console.V8.ES6.Sample.csproj
-CONSOLE_DLL=Wasm.Console.V8.ES6.Sample.dll
+PROJECT_NAME=Wasm.Console.V8.Sample.csproj
+CONSOLE_DLL=Wasm.Console.V8.Sample.dll
MAIN_JS=v8shim.cjs
run: run-console
</ItemGroup>
<PropertyGroup>
- <_SampleProject>Wasm.Console.V8.ES6.Sample.csproj</_SampleProject>
- <_SampleAssembly>Wasm.Console.V8.ES6.Sample.dll</_SampleAssembly>
+ <_SampleProject>Wasm.Console.V8.Sample.csproj</_SampleProject>
+ <_SampleAssembly>Wasm.Console.V8.Sample.dll</_SampleAssembly>
</PropertyGroup>
<Target Name="RunSample" DependsOnTargets="RunSampleWithV8" />
import createDotnetRuntime from './dotnet.js'
-const dllName = "Wasm.Console.V8.ES6.Sample.dll";
+const dllName = "Wasm.Console.V8.Sample.dll";
const app_args = Array.from(arguments);
async function main() {
* console Hello world sample
-`dotnet build /t:RunSample console-v8-cjs/Wasm.Console.V8.CJS.Sample.csproj`
+`dotnet build /t:RunSample console-v8-es6/Wasm.Console.V8.Sample.csproj`
* browser TestMeaning sample
-`dotnet build /t:RunSample browser/Wasm.Browser.CJS.Sample.csproj`
+`dotnet build /t:RunSample browser/Wasm.Browser.Sample.csproj`
To build and run the samples with AOT, add `/p:RunAOTCompilation=true` to the above command lines.
- *after* any of the wasm build targets, use `AfterTargets="WasmBuildApp"` on that target
- Avoid depending on this target, because it is available only when the workload is installed. Use `$(WasmNativeWorkload)` to check if it is installed.
-- `WasmEnableES6==false` will cause native re-link and produce `dotnet.js` as CJS module. When `Module.disableDotnet6Compatibility` is set it would not pollute global namespace.
+- When `Module.disableDotnet6Compatibility` is set it would not pollute global namespace.
## `Publish`
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true' and '$(RunAOTCompilationAfterBuild)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
- <!-- need to re-link dotnet.js when not targeting ES6 -->
- <WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableES6)' == 'false'" >true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
</PropertyGroup>
<!-- AOT==true overrides WasmBuildNative -->
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
- <!-- need to re-link dotnet.js when not targeting ES6 -->
- <WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableES6)' == 'false'" >true</WasmBuildNative>
<!-- not aot, not trimmed app, no reason to relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(PublishTrimmed)' != 'true'">false</WasmBuildNative>
<_EmccCommonFlags Include="$(_DefaultEmccFlags)" />
<_EmccCommonFlags Include="$(EmccFlags)" />
- <_EmccCommonFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' != 'false'" />
+ <_EmccCommonFlags Include="-s EXPORT_ES6=1" />
<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeStrip)' == 'false'" />
<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' != 'false'" />
<_EmccCommonFlags Include="-s DISABLE_EXCEPTION_CATCHING=0" Condition="'$(WasmExceptionHandling)' == 'false'" />
<JSFileType Include="extpost.js" Kind="extern-post-js" />
<_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" />
- <_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\cjs\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" Condition="'$(WasmEnableES6)' == 'false'" />
- <_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\es6\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" Condition="'$(WasmEnableES6)' != 'false'" />
+ <_WasmExtraJSFile Include="$(_WasmRuntimePackSrcDir)\es6\*.%(JSFileType.Identity)" Kind="%(JSFileType.Kind)" />
<_WasmNativeFileForLinking Include="@(NativeFileReference)" />
<WasmAppBuilder
AppDir="$(WasmAppDir)"
MainJS="$(WasmMainJSPath)"
- WasmEnableES6="$(WasmEnableES6)"
MainHTMLPath="$(WasmMainHTMLPath)"
Assemblies="@(_WasmAssembliesInternal)"
MainAssemblyName="$(WasmMainAssemblyFileName)"
// Trying to access object as an array
if (!DotnetObjectId.TryParse(c_obj_id, out var id) || id.Scheme != "object")
- Assert.True(false, "Unexpected object id format. Maybe this test is out of sync with the object id format in dotnet.cjs.lib.js?");
+ Assert.True(false, "Unexpected object id format. Maybe this test is out of sync with the object id format in dotnet.es6.lib.js?");
await GetProperties($"dotnet:array:{id.Value}", expect_ok: false);
});
locals = new JArray(locals.Union(locals_internal));
if (locals_private != null)
locals = new JArray(locals.Union(locals_private));
- // FIXME: Should be done when generating the list in dotnet.cjs.lib.js, but not sure yet
+ // FIXME: Should be done when generating the list in dotnet.es6.lib.js, but not sure yet
// whether to remove it, and how to do it correctly.
if (locals is JArray)
{
var locals_internal = frame_props.Value["internalProperties"];
var locals_private = frame_props.Value["privateProperties"];
- // FIXME: Should be done when generating the list in dotnet.cjs.lib.js, but not sure yet
+ // FIXME: Should be done when generating the list in dotnet.es6.lib.js, but not sure yet
// whether to remove it, and how to do it correctly.
if (locals is JArray)
{
"ignorePatterns": [
"node_modules/**/*.*",
"bin/**/*.*",
- "cjs/*.js",
"es6/*.js",
],
"rules": {
+++ /dev/null
-var require = require || undefined;
-var __dirname = __dirname || "";
-// if loaded into global namespace and configured with global Module, we will self start in compatibility mode
-const __isWorker = typeof globalThis.importScripts === "function";
-let ENVIRONMENT_IS_GLOBAL = !__isWorker && (typeof globalThis.Module === "object" && globalThis.__dotnet_runtime === __dotnet_runtime);
-if (ENVIRONMENT_IS_GLOBAL) {
- createDotnetRuntime(() => { return globalThis.Module; }).then((exports) => exports);
-}
-else if (typeof globalThis.__onDotnetRuntimeLoaded === "function") {
- globalThis.__onDotnetRuntimeLoaded(createDotnetRuntime);
-}
\ No newline at end of file
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-/* eslint-disable no-undef */
-
-"use strict";
-
-#if USE_PTHREADS
-const usePThreads = `true`;
-const isPThread = `ENVIRONMENT_IS_PTHREAD`;
-#else
-const usePThreads = `false`;
-const isPThread = `false`;
-#endif
-
-const DotnetSupportLib = {
- $DOTNET: {},
- // these lines will be placed early on emscripten runtime creation, passing import and export objects into __dotnet_runtime IFFE
- // we replace implementation of fetch
- // replacement of require is there for consistency with ES6 code
- $DOTNET__postset: `
-let __dotnet_replacement_PThread = ${usePThreads} ? {} : undefined;
-if (${usePThreads}) {
- __dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWorker;
- __dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS;
-}
-let __dotnet_replacements = {scriptUrl: undefined, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread};
-if (ENVIRONMENT_IS_NODE) {
- __dotnet_replacements.requirePromise = Promise.resolve(require);
-}
-let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
- { isESM:false, isGlobal:ENVIRONMENT_IS_GLOBAL, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:Promise.resolve(require)},
- { mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_exports: EXPORTS, marshaled_imports: IMPORTS },
- __dotnet_replacements);
-updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
-var fetch = __dotnet_replacements.fetch;
-_scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory;
-if (ENVIRONMENT_IS_NODE) {
- __dotnet_replacements.requirePromise.then(someRequire => {
- require = someRequire;
- });
-}
-var noExitRuntime = __dotnet_replacements.noExitRuntime;
-if (${usePThreads}) {
- PThread.loadWasmModuleToWorker = __dotnet_replacements.pthreadReplacements.loadWasmModuleToWorker;
- PThread.threadInitTLS = __dotnet_replacements.pthreadReplacements.threadInitTS;
-}
-`,
-};
-
-// the methods would be visible to EMCC linker
-// --- keep in sync with exports.ts ---
-const linked_functions = [
- // mini-wasm.c
- "mono_set_timeout",
-
- // mini-wasm-debugger.c
- "mono_wasm_asm_loaded",
- "mono_wasm_fire_debugger_agent_message",
- "mono_wasm_debugger_log",
- "mono_wasm_add_dbg_command_received",
-
- // mono-threads-wasm.c
- "schedule_background_exec",
-
- // driver.c
- "mono_wasm_invoke_js_blazor",
- "mono_wasm_trace_logger",
- "mono_wasm_set_entrypoint_breakpoint",
- "mono_wasm_event_pipe_early_startup_callback",
-
- // corebindings.c
- "mono_wasm_invoke_js_with_args_ref",
- "mono_wasm_get_object_property_ref",
- "mono_wasm_set_object_property_ref",
- "mono_wasm_get_by_index_ref",
- "mono_wasm_set_by_index_ref",
- "mono_wasm_get_global_object_ref",
- "mono_wasm_create_cs_owned_object_ref",
- "mono_wasm_release_cs_owned_object",
- "mono_wasm_typed_array_to_array_ref",
- "mono_wasm_typed_array_copy_to_ref",
- "mono_wasm_typed_array_from_ref",
- "mono_wasm_typed_array_copy_from_ref",
- "mono_wasm_compile_function_ref",
- "mono_wasm_bind_js_function",
- "mono_wasm_invoke_bound_function",
- "mono_wasm_bind_cs_function",
- "mono_wasm_marshal_promise",
-
- // pal_icushim_static.c
- "mono_wasm_load_icu_data",
- "mono_wasm_get_icudt_name",
-
- // pal_crypto_webworker.c
- "dotnet_browser_can_use_subtle_crypto_impl",
- "dotnet_browser_simple_digest_hash",
- "dotnet_browser_sign",
- "dotnet_browser_encrypt_decrypt",
- "dotnet_browser_derive_bits",
-
- #if USE_PTHREADS
- /// mono-threads-wasm.c
- "mono_wasm_pthread_on_pthread_attached",
- /// diagnostics_server.c
- "mono_wasm_diagnostic_server_on_server_thread_created",
- "mono_wasm_diagnostic_server_on_runtime_server_init",
- "mono_wasm_diagnostic_server_stream_signal_work_available",
- #endif
-];
-
-// -- this javascript file is evaluated by emcc during compilation! --
-// we generate simple proxy for each exported function so that emcc will include them in the final output
-for (let linked_function of linked_functions) {
- const fn_template = `return __dotnet_runtime.__linker_exports.${linked_function}.apply(__dotnet_runtime, arguments)`;
- DotnetSupportLib[linked_function] = new Function(fn_template);
-}
-
-autoAddDeps(DotnetSupportLib, "$DOTNET");
-mergeInto(LibraryManager.library, DotnetSupportLib);
+++ /dev/null
-createDotnetRuntime.ready = createDotnetRuntime.ready.then(() => {
- return __dotnet_exportedAPI;
-})
+++ /dev/null
-const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {}, EXPORTS = {};
-if (ENVIRONMENT_IS_GLOBAL) {
- if (globalThis.Module.ready) {
- throw new Error("MONO_WASM: Module.ready couldn't be redefined.")
- }
- globalThis.Module.ready = Module.ready;
- Module = createDotnetRuntime = globalThis.Module;
- if (!createDotnetRuntime.locateFile) createDotnetRuntime.locateFile = createDotnetRuntime.__locateFile = (path) => scriptDirectory + path;
-}
-else if (typeof createDotnetRuntime === "object") {
- Module = { ready: Module.ready, __undefinedConfig: Object.keys(createDotnetRuntime).length === 1 };
- Object.assign(Module, createDotnetRuntime);
- createDotnetRuntime = Module;
- if (!createDotnetRuntime.locateFile) createDotnetRuntime.locateFile = createDotnetRuntime.__locateFile = (path) => scriptDirectory + path;
-}
-else if (typeof createDotnetRuntime === "function") {
- Module = { ready: Module.ready };
- const extension = createDotnetRuntime({ MONO, BINDING, INTERNAL, IMPORTS, EXPORTS, Module })
- if (extension.ready) {
- throw new Error("MONO_WASM: Module.ready couldn't be redefined.")
- }
- Object.assign(Module, extension);
- createDotnetRuntime = Module;
- if (!createDotnetRuntime.locateFile) createDotnetRuntime.locateFile = createDotnetRuntime.__locateFile = (path) => scriptDirectory + path;
-}
-else {
- throw new Error("MONO_WASM: Can't locate global Module object or moduleFactory callback of createDotnetRuntime function.")
-}
\ No newline at end of file
if (monoDiagnosticsMock) {
const mockPrefix = "mock:";
const scriptURL = mockURL.substring(mockPrefix.length);
- // revisit this if we ever have a need to mock using CJS, for now we just support ESM
return import(scriptURL).then((mockModule) => {
const script = mockModule.default;
return mock(script, { trace: true });
__dotnet_replacements.requirePromise = import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url));
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
- { isESM:true, isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
+ { isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_exports: EXPORTS, marshaled_imports: IMPORTS },
__dotnet_replacements);
updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews;
}
if (typeof module.disableDotnet6Compatibility === "undefined") {
- module.disableDotnet6Compatibility = imports.isESM;
+ module.disableDotnet6Compatibility = true;
}
// here we expose objects global namespace for tests and backward compatibility
if (imports.isGlobal || !module.disableDotnet6Compatibility) {
export const __initializeImportsAndExports: any = initializeImportsAndExports; // don't want to export the type
// the methods would be visible to EMCC linker
-// --- keep in sync with dotnet.cjs.lib.js ---
+// --- keep in sync with dotnet.es6.lib.js ---
const mono_wasm_threads_exports = !MonoWasmThreads ? undefined : {
// mono-threads-wasm.c
mono_wasm_pthread_on_pthread_attached,
};
// the methods would be visible to EMCC linker
-// --- keep in sync with dotnet.cjs.lib.js ---
+// --- keep in sync with dotnet.es6.lib.js ---
export const __linker_exports: any = {
// mini-wasm.c
mono_set_timeout,
export let IMPORTS: any;
// these are imported and re-exported from emscripten internals
-export let ENVIRONMENT_IS_ESM: boolean;
export let ENVIRONMENT_IS_NODE: boolean;
export let ENVIRONMENT_IS_SHELL: boolean;
export let ENVIRONMENT_IS_WEB: boolean;
EXPORTS = exports.marshaled_exports; // [JSExport]
IMPORTS = exports.marshaled_imports; // [JSImport]
- ENVIRONMENT_IS_ESM = imports.isESM;
ENVIRONMENT_IS_NODE = imports.isNode;
ENVIRONMENT_IS_SHELL = imports.isShell;
ENVIRONMENT_IS_WEB = imports.isWeb;
There are `-extern-pre-js`,`-pre-js`, `-post-js`, `-extern-post-js`.
In `src\mono\wasm\build\WasmApp.Native.targets` we apply them by file naming convention as: `*.extpre.js`,`*.pre.js`, `*.post.js`, `*.extpost.js`
-- For ES6 with `WasmEnableES6 == true` from `src/es6`folder
-- For CommonJS with `WasmEnableES6 == false` from `src/cjs`folder
In `src\mono\wasm\runtime\CMakeLists.txt` which links only in-tree, we use same mapping explicitly. Right now CommonJS is default.
-# dotnet.cjs.extpost.js
-- Is at the end of file but is executed first (1)
-- Applied only when linking CommonJS
-- If `globalThis.Module` exist it takes it and start runtime with it.
-- Otherwise user could still use the `createDotnetRuntime` export or `globalThis.createDotnetRuntime` if it was loaded into global namespace.
-
-# dotnet.cjs.pre.js
-- Executed second (2)
-- Applied only when linking CommonJS
-- Will try to see if it was executed with `globalThis.Module` and if so, it would use it's instance as `Module`. It would preserve emscripten's `Module.ready`
-- Otherwise it would load it would assume it was called via `createDotnetRuntime` export same as described for `dotnet.es6.pre.js` below.
-
# dotnet.es6.pre.js
- Executed second (2)
- Applied only when linking ES6
import Configuration from "consts:configuration";
import MonoWasmThreads from "consts:monoWasmThreads";
-import { ENVIRONMENT_IS_ESM, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, ENVIRONMENT_IS_WORKER, INTERNAL, Module, runtimeHelpers } from "./imports";
+import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, ENVIRONMENT_IS_WORKER, INTERNAL, Module, runtimeHelpers } from "./imports";
import { afterUpdateGlobalBufferAndViews } from "./memory";
import { afterLoadWasmModuleToWorker } from "./pthreads/browser";
import { afterThreadInitTLS } from "./pthreads/worker";
}
export async function init_polyfills_async(): Promise<void> {
- if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_ESM) {
+ if (ENVIRONMENT_IS_NODE) {
// wait for locateFile setup on NodeJs
INTERNAL.require = await runtimeHelpers.requirePromise;
if (globalThis.performance === dummyPerformance) {
// Check worker, not web, since window could be polyfilled
replacements.scriptUrl = self.location.href;
}
- // when ENVIRONMENT_IS_ESM we have scriptUrl from import.meta.url from dotnet.es6.lib.js
- if (!ENVIRONMENT_IS_ESM) {
- if (ENVIRONMENT_IS_WEB) {
- if (
- (typeof (globalThis.document) === "object") &&
- (typeof (globalThis.document.createElement) === "function")
- ) {
- // blazor injects a module preload link element for dotnet.[version].[sha].js
- const blazorDotNetJS = Array.from(document.head.getElementsByTagName("link")).filter(elt => elt.rel !== undefined && elt.rel == "modulepreload" && elt.href !== undefined && elt.href.indexOf("dotnet") != -1 && elt.href.indexOf(".js") != -1);
- if (blazorDotNetJS.length == 1) {
- replacements.scriptUrl = blazorDotNetJS[0].href;
- } else {
- const temp = globalThis.document.createElement("a");
- temp.href = "dotnet.js";
- replacements.scriptUrl = temp.href;
- }
- }
- }
- if (ENVIRONMENT_IS_NODE) {
- if (typeof __filename !== "undefined") {
- // unix vs windows
- replacements.scriptUrl = __filename;
- }
- }
- }
if (!replacements.scriptUrl) {
// probably V8 shell in non ES6
replacements.scriptUrl = "./dotnet.js";
input: "exports.ts",
output: [
{
- file: nativeBinDir + "/src/cjs/runtime.cjs.iffe.js",
- name,
- banner,
- format,
- plugins,
- },
- {
file: nativeBinDir + "/src/es6/runtime.es6.iffe.js",
name,
banner,
}
export type EarlyImports = {
- isESM: boolean,
isGlobal: boolean,
isNode: boolean,
isWorker: boolean,
}
async function loadDotnet(file) {
- const cjsExport = new Promise((resolve) => {
- globalThis.__onDotnetRuntimeLoaded = (createDotnetRuntime) => {
- delete globalThis.__onDotnetRuntimeLoaded;
- resolve(createDotnetRuntime);
- };
- });
-
const { default: createDotnetRuntime } = await import(file);
- if (createDotnetRuntime) {
- // this runs when loaded module was ES6
- delete globalThis.__onDotnetRuntimeLoaded;
- return createDotnetRuntime;
- }
-
- return await cjsExport;
+ return createDotnetRuntime;
}
// this can't be function because of `arguments` scope
<PropertyGroup>
<ICULibDir Condition="'$(MonoWasmThreads)' != 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib'))</ICULibDir>
<ICULibDir Condition="'$(MonoWasmThreads)' == 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib'))</ICULibDir>
- <WasmEnableES6 Condition="'$(WasmEnableES6)' == ''">true</WasmEnableES6>
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">false</WasmEnableSIMD>
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
<EmccCmd>emcc</EmccCmd>
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" />
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=4" />
<_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=2" /> <!-- hard error if worker pool is exhausted -->
- <!--
- <_EmccLinkFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' == 'true'" />
- -->
<_EmccLinkFlags Include="-s ALLOW_MEMORY_GROWTH=1" />
<_EmccLinkFlags Include="-s NO_EXIT_RUNTIME=1" />
<_EmccLinkFlags Include="-s FORCE_FILESYSTEM=1" />
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags)</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>
- <CMakeConfigurationLinkFlags Condition="'$(WasmEnableES6)' != 'false'">$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
+ <CMakeConfigurationLinkFlags>$(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags Condition="'$(MonoWasmThreads)' == 'true'">$(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth</CMakeConfigurationLinkFlags>
<CMakeConfigurationLinkFlags >$(CMakeConfigurationLinkFlags) --emit-symbol-map</CMakeConfigurationLinkFlags>
DestinationFolder="$(NativeBinDir)src"
SkipUnchangedFiles="true" />
- <Copy SourceFiles="runtime/cjs/dotnet.cjs.pre.js;
- runtime/cjs/dotnet.cjs.lib.js;
- runtime/cjs/dotnet.cjs.post.js;
- runtime/cjs/dotnet.cjs.extpost.js;"
- DestinationFolder="$(NativeBinDir)src/cjs"
- SkipUnchangedFiles="true" />
-
<Copy SourceFiles="runtime/es6/dotnet.es6.pre.js;
runtime/es6/dotnet.es6.lib.js;
runtime/es6/dotnet.es6.post.js;"
$(_EmccCompileRspPath);
$(_EmccLinkRspPath);
$(NativeBinDir)src\emcc-props.json" />
- <WasmSrcFilesCjs Include="$(NativeBinDir)src\cjs\*.js;" />
<WasmSrcFilesEs6 Include="$(NativeBinDir)src\es6\*.js;" />
<WasmHeaderFiles Include="$(NativeBinDir)include\wasm\*.h" />
</ItemGroup>
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)src"
SkipUnchangedFiles="true" />
- <Copy SourceFiles="@(WasmSrcFilesCjs)"
- DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)src\cjs"
- SkipUnchangedFiles="true" />
-
<Copy SourceFiles="@(WasmSrcFilesEs6)"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)src\es6"
SkipUnchangedFiles="true" />
[Required]
public string? MainJS { get; set; }
- public string? WasmEnableES6 { get; set; }
-
[Required]
public string[] Assemblies { get; set; } = Array.Empty<string>();
}
string packageJsonPath = Path.Combine(AppDir, "package.json");
- if (WasmEnableES6 != "false" && !File.Exists(packageJsonPath))
+ if (!File.Exists(packageJsonPath))
{
var json = @"{ ""type"":""module"" }";
File.WriteAllText(packageJsonPath, json);