Skip to content

Commit

Permalink
Use boot config as default and explicitly swtich back with withMonoCo…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
maraf committed Apr 30, 2023
1 parent 28ea09f commit 0521238
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-advanced/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let testError = true;

try {
const { runtimeBuildInfo, setModuleImports, getAssemblyExports, runMain, getConfig, Module } = await dotnet
.withMonoConfig()
.withElementOnExit()
// 'withModuleConfig' is internal lower level API
// here we show how emscripten could be further configured
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-bench/frame-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ try {
}

const runtime = await dotnet
.withMonoConfig()
.withModuleConfig({
printErr: () => undefined,
print: () => undefined,
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-bench/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ try {
globalThis.mainApp.PageShow = globalThis.mainApp.pageShow.bind(globalThis.mainApp);

const runtime = await dotnet
.withMonoConfig()
.withRuntimeOptions(["--jiterpreter-stats-enabled"])
.withElementOnExit()
.withExitCodeLogging()
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-eventpipe/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function runTest({ StartAsyncWork, StopWork, GetIterationsDone }) {

async function main() {
const { INTERNAL, MONO, Module, getAssemblyExports, getConfig } = await dotnet
.withMonoConfig()
.withElementOnExit()
.withExitCodeLogging()
.withDiagnosticTracing(false)
Expand Down
5 changes: 3 additions & 2 deletions src/mono/sample/wasm/browser-nextjs/components/deepThought.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ let dotnetRuntimePromise = undefined;

async function createRuntime() {
try {
return dotnet.
withModuleConfig({
return dotnet
.withMonoConfig()
.withModuleConfig({
locateFile: (path, prefix) => {
return '/' + path;
}
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-profile/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function saveProfile(aotProfileData) {
}
try {
const { INTERNAL, getAssemblyExports: getAssemblyExports } = await dotnet
.withMonoConfig()
.withElementOnExit()
.withExitCodeLogging()
.withConfig({
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-threads-minimal/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const assemblyName = "Wasm.Browser.Threads.Minimal.Sample.dll";

try {
const { setModuleImports, getAssemblyExports, runMain } = await dotnet
.withMonoConfig()
.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
.withElementOnExit()
.withExitCodeLogging()
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser-threads/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function onInputValueChanged(exports, inputElement) {
try {
const inputElement = document.getElementById("inputN");
const { setModuleImports, getAssemblyExports, runMain } = await dotnet
.withMonoConfig()
.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
.withElementOnExit()
.withExitCodeLogging()
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-webpack/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from 'underscore'

async function dotnetMeaning() {
try {
const { getAssemblyExports } = await dotnet.create();
const { getAssemblyExports } = await dotnet.withMonoConfig().create();

const exports = await getAssemblyExports("Wasm.Browser.WebPack.Sample");
const meaningFunction = exports.Sample.Test.Main;
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function displayMeaning(meaning) {

try {
const { setModuleImports } = await dotnet
.withMonoConfig()
.withElementOnExit()
.create();

Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/console-node-ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// The .NET Foundation licenses this file to you under the MIT license.

import { dotnet } from '@microsoft/dotnet-runtime'
await dotnet.run();
await dotnet.withMonoConfig().run();
1 change: 1 addition & 0 deletions src/mono/sample/wasm/console-node/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { dotnet } from './dotnet.js'

dotnet
.withMonoConfig()
.withDiagnosticTracing(false)
.withApplicationArguments("dotnet", "is", "great!")
.run()
1 change: 1 addition & 0 deletions src/mono/sample/wasm/console-v8/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { dotnet } from './dotnet.js'

dotnet
.withMonoConfig()
.withDiagnosticTracing(false)
.withApplicationArguments(...arguments)
.run()
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/node-webpack/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { color } from 'console-log-colors'

async function dotnetMeaning() {
try {
const { getAssemblyExports } = await dotnet.create();
const { getAssemblyExports } = await dotnet.withMonoConfig().create();
const exports = await getAssemblyExports("Wasm.Node.WebPack.Sample");
const meaningFunction = exports.Sample.Test.Main;
return meaningFunction();
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/simple-raytracer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function renderCanvas(rgbaView) {
canvas.style = "";
}

const { setModuleImports, getAssemblyExports, getConfig } = await dotnet.create();
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet.withMonoConfig().create();
setModuleImports("main.js", { renderCanvas });
const config = getConfig();
const exports = await getAssemblyExports(config.mainAssemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { dotnet, exit } from './dotnet.js'

try {
const runtime = await dotnet
.withMonoConfig()
.withEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES", "debug")
// For custom logging patch the functions below
//.withDiagnosticTracing(true)
Expand Down
10 changes: 10 additions & 0 deletions src/mono/wasm/runtime/run-outer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class HostBuilder implements DotnetHostBuilder {
private instance?: RuntimeAPI;
private applicationArguments?: string[];
private virtualWorkingDirectory?: string;
private useMonoConfig = false;

// internal
withModuleConfig(moduleConfig: DotnetModuleConfig): DotnetHostBuilder {
Expand Down Expand Up @@ -290,9 +291,18 @@ export class HostBuilder implements DotnetHostBuilder {
return this.withConfigSrc("blazor.boot.json");
}

withMonoConfig(): DotnetHostBuilder {
this.useMonoConfig = true;
return this;
}

async create(): Promise<RuntimeAPI> {
try {
if (!this.instance) {
if (!this.useMonoConfig) {
this.withStartupOptions({});
}

if (ENVIRONMENT_IS_WEB && (module.config! as MonoConfigInternal).forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
setup_proxy_console("main", globalThis.console, globalThis.location.origin);
}
Expand Down
1 change: 0 additions & 1 deletion src/mono/wasm/templates/templates/browser/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { dotnet } from './_framework/dotnet.js'

const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withStartupOptions({})
.withDiagnosticTracing(false)
.withApplicationArgumentsFromQuery()
.create();
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/templates/templates/console/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { dotnet } from './dotnet.js'

const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withMonoConfg() // This will go away in later previews/RC
.withDiagnosticTracing(false)
.create();

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ globalThis.App = App; // Necessary as System.Runtime.InteropServices.JavaScript.

function configureRuntime(dotnet, runArgs) {
dotnet
.withMonoOptions()
.withVirtualWorkingDirectory(runArgs.workingDirectory)
.withEnvironmentVariables(runArgs.environmentVariables)
.withDiagnosticTracing(runArgs.diagnosticTracing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function wasm_exit(exit_code) {

try {
const { getAssemblyExports } = await dotnet
.withMonoConfig()
.withElementOnExit()
.withEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES", "debug")
.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function wasm_exit(exit_code) {
}

try {
const { getAssemblyExports, INTERNAL } = await dotnet.withRuntimeOptions(["--jiterpreter-stats-enabled"]).create();
const { getAssemblyExports, INTERNAL } = await dotnet.withMonoConfig().withRuntimeOptions(["--jiterpreter-stats-enabled"]).create();
const exports = await getAssemblyExports("WebAssembly.Browser.RuntimeConfig.Test.dll");
const testMeaning = exports.Sample.Test.TestMeaning;
const ret = testMeaning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function wasm_exit(exit_code) {
}

try {
const { getAssemblyExports } = await dotnet.create();
const { getAssemblyExports } = await dotnet.withMonoConfig().create();
const exports = await getAssemblyExports("WebAssembly.Browser.StartupHook.Test.dll");
const testMeaning = exports.Sample.Test.TestMeaning;
const ret = testMeaning();
Expand Down

0 comments on commit 0521238

Please sign in to comment.