Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/mono/wasm/templates/templates/console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
using System;
using System.Runtime.InteropServices.JavaScript;

Console.WriteLine("Hello, Console!");
Console.WriteLine("Hello, Console");

public partial class MyClass
{
[JSExport]
internal static string Greeting()
{
var text = $"Hello, World! Greetings from node version: {GetNodeVersion()}";
Console.WriteLine(text);
return text;
}

[JSImport("node.process.version")]
internal static partial string GetNodeVersion();

}
5 changes: 2 additions & 3 deletions src/mono/wasm/templates/templates/console/app-support.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ try {
initRunArgs();
mergeArguments();

createDotnetRuntime(({ MONO, INTERNAL, BINDING, Module }) => ({
createDotnetRuntime(({ MONO, INTERNAL, BINDING, IMPORTS, Module }) => ({
disableDotnet6Compatibility: true,
config: null,
configSrc: "./mono-config.json",
Expand Down Expand Up @@ -166,7 +166,7 @@ try {
if (runArgs.runtimeArgs.length > 0)
INTERNAL.mono_wasm_set_runtime_options(runArgs.runtimeArgs);

Object.assign(App, { MONO, BINDING, Module, runArgs });
Object.assign(App, { MONO, BINDING, IMPORTS, Module, runArgs });

try {
if (App.main) {
Expand All @@ -190,4 +190,3 @@ try {
catch (err) {
set_exit_code(2, err);
}

23 changes: 23 additions & 0 deletions src/mono/wasm/templates/templates/console/console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetArchitecture>wasm</TargetArchitecture>
<TargetOS>browser</TargetOS>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseMonoRuntime>true</UseMonoRuntime>
<WasmMainJSPath>main.mjs</WasmMainJSPath>
<OutputType>Exe</OutputType>
<PublishTrimmed>true</PublishTrimmed>
<WasmEmitSymbolMap Condition="'$(RunAOTCompilation)' != 'true'">true</WasmEmitSymbolMap>
</PropertyGroup>
<PropertyGroup>
<_SampleProject>console.csproj</_SampleProject>
</PropertyGroup>
<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" />
<Target Name="RunSample" DependsOnTargets="RunSampleWithNode" />
<ItemGroup>
<WasmExtraFilesToDeploy Include="app-support.mjs" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemTe="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferencutputAssembly="false" />
</ItemGroup>
</Project>
13 changes: 12 additions & 1 deletion src/mono/wasm/templates/templates/console/main.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { App } from './app-support.mjs'

App.main = async function (applicationArguments) {
await App.MONO.mono_run_main("console.0.dll", applicationArguments);

App.IMPORTS.node = {
process : {
version: () => globalThis.process.version
}
};

const exports = await App.MONO.mono_wasm_get_assembly_exports("console.dll");
const text = exports.MyClass.Greeting();
console.log(text);

await App.MONO.mono_run_main("console.dll", applicationArguments);
}