Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Apr 26, 2023
1 parent 0c25851 commit 55edc8b
Show file tree
Hide file tree
Showing 38 changed files with 731 additions and 706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@
<PlatformManifestFileEntry Include="runtime.es6.iffe.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.pre.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.lib.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.post.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.es6.extpost.js" IsNative="true" />
<PlatformManifestFileEntry Include="corebindings.c" IsNative="true" />
<PlatformManifestFileEntry Include="driver.c" IsNative="true" />
Expand Down
33 changes: 15 additions & 18 deletions src/mono/wasm/debugger/tests/debugger-test/debugger-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@

"use strict";

import createDotnetRuntime from './dotnet.js'
import { dotnet, exit } from './dotnet.js'

try {
const runtime = await createDotnetRuntime(({ INTERNAL }) => ({
configSrc: "./mono-config.json",
onConfigLoaded: (config) => {
config.environmentVariables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug";
/* For custom logging patch the functions below
config.diagnosticTracing = true;
config.environmentVariables["MONO_LOG_LEVEL"] = "debug";
config.environmentVariables["MONO_LOG_MASK"] = "all";
INTERNAL.logging = {
trace: (domain, log_level, message, isFatal, dataPtr) => console.log({ domain, log_level, message, isFatal, dataPtr }),
debugger: (level, message) => console.log({ level, message }),
};
*/
},
}));
const runtime = await dotnet
.withEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES", "debug")
// For custom logging patch the functions below
//.withDiagnosticTracing(true)
//.withEnvironmentVariable("MONO_LOG_LEVEL", "debug")
//.withEnvironmentVariable("MONO_LOG_MASK", "all")
.create();
/*runtime.INTERNAL.logging = {
trace: (domain, log_level, message, isFatal, dataPtr) => console.log({ domain, log_level, message, isFatal, dataPtr }),
debugger: (level, message) => console.log({ level, message }),
};*/
App.runtime = runtime;
await App.init();
} catch (err) {
console.log(`WASM ERROR ${err}`);
}
catch (err) {
exit(2, err);
}
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ target_link_libraries(dotnet
${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a)

set_target_properties(dotnet PROPERTIES
LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/es6/runtime.es6.iffe.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/pal_random.lib.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.post.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js;"
LINK_FLAGS "@${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-link.rsp ${CONFIGURATION_LINK_FLAGS} --extern-pre-js ${NATIVE_BIN_DIR}/src/es6/runtime.es6.iffe.js --pre-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js --js-library ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js --js-library ${NATIVE_BIN_DIR}/src/pal_random.lib.js --post-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.post.js --extern-post-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js "
LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/es6/runtime.es6.iffe.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/pal_random.lib.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js;"
LINK_FLAGS "@${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-link.rsp ${CONFIGURATION_LINK_FLAGS} --extern-pre-js ${NATIVE_BIN_DIR}/src/es6/runtime.es6.iffe.js --pre-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js --js-library ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js --js-library ${NATIVE_BIN_DIR}/src/pal_random.lib.js --extern-post-js ${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js "
RUNTIME_OUTPUT_DIRECTORY "${NATIVE_BIN_DIR}")

set(ignoreMeWasmOptFlags "${CONFIGURATION_WASM_OPT_FLAGS}")
Expand Down
5 changes: 3 additions & 2 deletions src/mono/wasm/runtime/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
import { createPromiseController, PromiseAndController } from "./promise-controller";
import { delay } from "./promise-utils";
import { abort_startup, beforeOnRuntimeInitialized, memorySnapshotSkippedOrDone } from "./startup";
import { AssetBehaviours, AssetEntry, AssetEntryInternal, LoadingResource, mono_assert, ResourceRequest } from "./types";
import { AssetEntryInternal, mono_assert } from "./types";
import { AssetBehaviours, AssetEntry, LoadingResource, ResourceRequest } from "./types-api";
import { InstantiateWasmSuccessCallback, VoidPtr } from "./types/emscripten";

const allAssetsInMemory = createPromiseController<void>();
Expand Down Expand Up @@ -314,7 +315,7 @@ async function start_asset_download_sources(asset: AssetEntryInternal): Promise<
const loadingResource = download_resource(asset);
asset.pendingDownloadInternal = loadingResource;
response = await loadingResource.response;
if (!response.ok) {
if (!response || !response.ok) {
continue;// next source
}
return response;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/blazor/BootConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

import { Module } from "../imports";
import { WebAssemblyBootResourceType } from "./WebAssemblyStartOptions";
import { WebAssemblyBootResourceType } from "../types-api";

type LoadBootResourceCallback = (type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) => string | Promise<Response> | null | undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/blazor/WebAssemblyResourceLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { WebAssemblyBootResourceType, WebAssemblyStartOptions } from "../types-api";
import { toAbsoluteUri } from "./_Polyfill";
import { BootJsonData, ResourceList } from "./BootConfig";
import { WebAssemblyStartOptions, WebAssemblyBootResourceType } from "./WebAssemblyStartOptions";
const networkFetchCacheMode = "no-cache";

export class WebAssemblyResourceLoader {
Expand Down
30 changes: 0 additions & 30 deletions src/mono/wasm/runtime/blazor/WebAssemblyStartOptions.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/blazor/_Integration.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { INTERNAL, Module } from "../imports";
import { AssetEntry, LoadingResource, MonoConfigInternal } from "../types";
import { MonoConfigInternal } from "../types";
import { AssetEntry, LoadingResource, WebAssemblyBootResourceType } from "../types-api";
import { BootConfigResult, BootJsonData, ICUDataMode } from "./BootConfig";
import { WebAssemblyResourceLoader } from "./WebAssemblyResourceLoader";
import { WebAssemblyBootResourceType } from "./WebAssemblyStartOptions";
import { hasDebuggingEnabled } from "./_Polyfill";

export async function loadBootConfig(config: MonoConfigInternal,) {
Expand Down
28 changes: 28 additions & 0 deletions src/mono/wasm/runtime/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { DotnetModuleInternal, MonoConfigInternal } from "./types";
import { DotnetModuleConfig } from "./types-api";

export function deep_merge_config(target: MonoConfigInternal, source: MonoConfigInternal): MonoConfigInternal {
const providedConfig: MonoConfigInternal = { ...source };
if (providedConfig.assets) {
providedConfig.assets = [...(target.assets || []), ...(providedConfig.assets || [])];
}
if (providedConfig.environmentVariables) {
providedConfig.environmentVariables = { ...(target.environmentVariables || {}), ...(providedConfig.environmentVariables || {}) };
}
if (providedConfig.startupOptions) {
providedConfig.startupOptions = { ...(target.startupOptions || {}), ...(providedConfig.startupOptions || {}) };
}
if (providedConfig.runtimeOptions) {
providedConfig.runtimeOptions = [...(target.runtimeOptions || []), ...(providedConfig.runtimeOptions || [])];
}
return Object.assign(target, providedConfig);
}

export function deep_merge_module(target: DotnetModuleInternal, source: DotnetModuleConfig): DotnetModuleInternal {
const providedConfig: DotnetModuleConfig = { ...source };
if (providedConfig.config) {
if (!target.config) target.config = {};
providedConfig.config = deep_merge_config(target.config, providedConfig.config);
}
return Object.assign(target, providedConfig);
}
136 changes: 68 additions & 68 deletions src/mono/wasm/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,6 @@

//! This is not considered public API with backward compatibility guarantees.

interface BootJsonData {
readonly entryAssembly: string;
readonly resources: ResourceGroups;
/** Gets a value that determines if this boot config was produced from a non-published build (i.e. dotnet build or dotnet run) */
readonly debugBuild: boolean;
readonly linkerEnabled: boolean;
readonly cacheBootResources: boolean;
readonly config: string[];
readonly icuDataMode: ICUDataMode;
readonly startupMemoryCache: boolean | undefined;
readonly runtimeOptions: string[] | undefined;
modifiableAssemblies: string | null;
aspnetCoreBrowserTools: string | null;
}
type BootJsonDataExtension = {
[extensionName: string]: ResourceList;
};
interface ResourceGroups {
readonly assembly: ResourceList;
readonly lazyAssembly: ResourceList;
readonly pdb?: ResourceList;
readonly runtime: ResourceList;
readonly satelliteResources?: {
[cultureName: string]: ResourceList;
};
readonly libraryInitializers?: ResourceList;
readonly extensions?: BootJsonDataExtension;
readonly runtimeAssets: ExtendedResourceList;
}
type ResourceList = {
[name: string]: string;
};
type ExtendedResourceList = {
[name: string]: {
hash: string;
behavior: string;
};
};
declare enum ICUDataMode {
Sharded = 0,
All = 1,
Invariant = 2,
Custom = 3
}

interface DotnetHostBuilder {
withConfig(config: MonoConfig): DotnetHostBuilder;
withConfigSrc(configSrc: string): DotnetHostBuilder;
withApplicationArguments(...args: string[]): DotnetHostBuilder;
withEnvironmentVariable(name: string, value: string): DotnetHostBuilder;
withEnvironmentVariables(variables: {
[i: string]: string;
}): DotnetHostBuilder;
withVirtualWorkingDirectory(vfsPath: string): DotnetHostBuilder;
withDiagnosticTracing(enabled: boolean): DotnetHostBuilder;
withDebugging(level: number): DotnetHostBuilder;
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder;
withApplicationArgumentsFromQuery(): DotnetHostBuilder;
withStartupMemoryCache(value: boolean): DotnetHostBuilder;
create(): Promise<RuntimeAPI>;
run(): Promise<number>;
}

declare interface NativePointer {
__brandNativePointer: "NativePointer";
}
Expand Down Expand Up @@ -121,6 +58,22 @@ type InstantiateWasmSuccessCallback = (instance: WebAssembly.Instance, module: W
type InstantiateWasmCallBack = (imports: WebAssembly.Imports, successCallback: InstantiateWasmSuccessCallback) => any;
declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;

interface DotnetHostBuilder {
withConfig(config: MonoConfig): DotnetHostBuilder;
withConfigSrc(configSrc: string): DotnetHostBuilder;
withApplicationArguments(...args: string[]): DotnetHostBuilder;
withEnvironmentVariable(name: string, value: string): DotnetHostBuilder;
withEnvironmentVariables(variables: {
[i: string]: string;
}): DotnetHostBuilder;
withVirtualWorkingDirectory(vfsPath: string): DotnetHostBuilder;
withDiagnosticTracing(enabled: boolean): DotnetHostBuilder;
withDebugging(level: number): DotnetHostBuilder;
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder;
withApplicationArgumentsFromQuery(): DotnetHostBuilder;
create(): Promise<RuntimeAPI>;
run(): Promise<number>;
}
type MonoConfig = {
/**
* The subfolder containing managed assemblies and pdbs. This is relative to dotnet.js script.
Expand Down Expand Up @@ -297,8 +250,52 @@ type ModuleAPI = {
dotnet: DotnetHostBuilder;
exit: (code: number, reason?: any) => void;
};
declare function createDotnetRuntime(moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)): Promise<RuntimeAPI>;
type CreateDotnetRuntimeType = typeof createDotnetRuntime;
type CreateDotnetRuntimeType = (moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)) => Promise<RuntimeAPI>;

interface BootJsonData {
readonly entryAssembly: string;
readonly resources: ResourceGroups;
/** Gets a value that determines if this boot config was produced from a non-published build (i.e. dotnet build or dotnet run) */
readonly debugBuild: boolean;
readonly linkerEnabled: boolean;
readonly cacheBootResources: boolean;
readonly config: string[];
readonly icuDataMode: ICUDataMode;
readonly startupMemoryCache: boolean | undefined;
readonly runtimeOptions: string[] | undefined;
modifiableAssemblies: string | null;
aspnetCoreBrowserTools: string | null;
}
type BootJsonDataExtension = {
[extensionName: string]: ResourceList;
};
interface ResourceGroups {
readonly assembly: ResourceList;
readonly lazyAssembly: ResourceList;
readonly pdb?: ResourceList;
readonly runtime: ResourceList;
readonly satelliteResources?: {
[cultureName: string]: ResourceList;
};
readonly libraryInitializers?: ResourceList;
readonly extensions?: BootJsonDataExtension;
readonly runtimeAssets: ExtendedResourceList;
}
type ResourceList = {
[name: string]: string;
};
type ExtendedResourceList = {
[name: string]: {
hash: string;
behavior: string;
};
};
declare enum ICUDataMode {
Sharded = 0,
All = 1,
Invariant = 2,
Custom = 3
}

interface IDisposable {
dispose(): void;
Expand All @@ -324,11 +321,14 @@ interface IMemoryView extends IDisposable {
get byteLength(): number;
}

declare function mono_exit(exit_code: number, reason?: any): void;

declare const dotnet: DotnetHostBuilder;
declare const exit: typeof mono_exit;

declare global {
function getDotnetRuntime(runtimeId: number): RuntimeAPI | undefined;
}

declare const dotnet: ModuleAPI["dotnet"];
declare const exit: ModuleAPI["exit"];
declare const createDotnetRuntime: CreateDotnetRuntimeType;

export { AssetEntry, BootJsonData, CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, ICUDataMode, IMemoryView, ModuleAPI, MonoConfig, ResourceRequest, RuntimeAPI, createDotnetRuntime as default, dotnet, exit };
15 changes: 6 additions & 9 deletions src/mono/wasm/runtime/es6/dotnet.es6.extpost.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const ENVIRONMENT_IS_WEB = typeof window == "object";
const ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
const MONO = {}, BINDING = {}, INTERNAL = {}, IMPORTS = {};

var fetch = fetch || undefined; var require = require || undefined; var __dirname = __dirname || '';
__dotnet_runtime.__setEmscriptenEntrypoint(createDotnetRuntime);
const __initializeImportsAndExports = __dotnet_runtime.__initializeImportsAndExports;
const __requirePromise = ENVIRONMENT_IS_NODE ? import(/* webpackIgnore: true */'module').then(mod => mod.createRequire(import.meta.url)) : undefined;
const dotnet = __dotnet_runtime.moduleExports.dotnet;
const exit = __dotnet_runtime.moduleExports.exit;
export { dotnet, exit, INTERNAL };
var createEmscripten = createDotnetRuntime;
var unifyModuleConfig = __dotnet_runtime.unifyModuleConfig;
var earlyExports = __dotnet_runtime.earlyExports;
export const dotnet = __dotnet_runtime.dotnet;
export const exit = __dotnet_runtime.exit;
Loading

0 comments on commit 55edc8b

Please sign in to comment.