Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
291c70a
- modularized `dotnet.js`
pavelsavara Nov 17, 2021
5c3a313
return back the hack for _MonoSelectRuntimeComponents
pavelsavara Nov 24, 2021
8399876
folders in nupkg are hard
pavelsavara Nov 24, 2021
e25050d
feedback
pavelsavara Nov 25, 2021
457456c
Merge branch 'main' into wasm_modularization7
pavelsavara Nov 25, 2021
5a3f6b1
minor fixes
pavelsavara Nov 25, 2021
171ec60
Merge branch 'main' into wasm_modularization7
pavelsavara Nov 25, 2021
864073e
- move dotnet.d.ts one level up
pavelsavara Nov 25, 2021
593831d
fix merge
pavelsavara Nov 25, 2021
6514dd8
NodeJS work in progress
pavelsavara Nov 26, 2021
4c4c502
move files
pavelsavara Nov 26, 2021
3c38597
fix
pavelsavara Nov 26, 2021
da43912
fix build
pavelsavara Nov 26, 2021
42634da
simplify TS Sample
pavelsavara Nov 26, 2021
0678e48
improve exports, reduce console noise, fix build
pavelsavara Nov 26, 2021
d3b1688
flat sample
pavelsavara Nov 26, 2021
50ac595
fix test
pavelsavara Nov 26, 2021
c506fd2
Merge branch 'main' into wasm_modularization7
pavelsavara Nov 28, 2021
ec1c39d
try without dealing with eventPipe issue
pavelsavara Nov 30, 2021
802a459
type exports for Blazor
pavelsavara Nov 30, 2021
15b416f
keep sha local
pavelsavara Nov 30, 2021
324efda
types
pavelsavara Nov 30, 2021
61dc62f
move type definitions
pavelsavara Dec 1, 2021
f3edf8b
remove typescript sample
pavelsavara Dec 1, 2021
0807f1b
Merge branch 'main' into wasm_modularization7
pavelsavara Dec 1, 2021
911bb5b
Update src/mono/wasm/runtime/modularize-dotnet.md
pavelsavara Dec 1, 2021
072568d
Update eng/liveBuilds.targets
pavelsavara Dec 1, 2021
c3df6fd
feedback from @radical
pavelsavara Dec 1, 2021
49fcd84
@maraf's feedback
pavelsavara Dec 1, 2021
00d784d
tweaks
pavelsavara Dec 1, 2021
ff39ea5
fix variables
pavelsavara Dec 1, 2021
8ddc710
fix exports, fix early malloc
pavelsavara Dec 1, 2021
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
Prev Previous commit
Next Next commit
improve exports, reduce console noise, fix build
  • Loading branch information
pavelsavara committed Nov 26, 2021
commit 0678e4888214da8249915b255c3b6f255cb3698d
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<PropertyGroup>
<WasmMainJSPath>bin/main.js</WasmMainJSPath>
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
<Configuration>Debug</Configuration>
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
<Configuration>Release</Configuration>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<WasmDebugLevel>1</WasmDebugLevel>
<!-- TODO solve the location of re-linked js file relative to package.json
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
<WasmEnableES6>true</WasmEnableES6>
-->
<WasmBuildAppDependsOn>
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/console-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"scripts": {
"build": "tsc -p .",
"start": "node bin/Debug/AppBundle/main.js"
"start": "node bin/Release/AppBundle/main.js"
},
"author": "Microsoft",
"license": "MIT",
"dependencies": {
"dotnet": "file://../../../../../artifacts/bin/native/net7.0-Browser-Debug-wasm/"
"dotnet": "file://../../../../../artifacts/bin/native/net7.0-Browser-Release-wasm/"
},
"devDependencies": {
"@types/node": "16.11.10",
Expand Down
80 changes: 58 additions & 22 deletions src/mono/wasm/runtime/dist-types/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ declare class WasmRoot<T extends ManagedPointer | NativePointer> {
toString(): string;
}

declare function mono_wasm_runtime_ready(): void;

declare const enum ArgsMarshal {
Int32 = "i",
Int32Enum = "j",
Expand Down Expand Up @@ -164,6 +162,15 @@ declare type CoverageProfilerOptions = {
write_at?: string;
send_to?: string;
};
declare type DotnetModuleConfig = {
disableDotnet6Compatibility?: boolean;
config?: MonoConfig | MonoConfigError;
configSrc?: string;
scriptDirectory?: string;
onConfigLoaded?: () => void;
onDotnetReady?: () => void;
imports?: DotnetModuleConfigImports;
};
declare type DotnetModuleConfigImports = {
require?: (name: string) => any;
fetch?: (url: string) => Promise<Response>;
Expand All @@ -185,15 +192,8 @@ declare type DotnetModuleConfigImports = {
};
url?: any;
};
declare type DotnetModuleConfig = {
disableDotnet6Compatibility?: boolean;
config?: MonoConfig | MonoConfigError;
configSrc?: string;
scriptDirectory?: string;
onConfigLoaded?: () => void;
onDotnetReady?: () => void;
imports?: DotnetModuleConfigImports;
};

declare function mono_wasm_runtime_ready(): void;

declare function mono_wasm_setenv(name: string, value: string): void;
declare function mono_load_runtime_and_bcl_args(args: MonoConfig): Promise<void>;
Expand Down Expand Up @@ -223,25 +223,61 @@ declare function mono_call_assembly_entry_point(assembly: string, args: any[], s

declare function mono_wasm_load_bytes_into_heap(bytes: Uint8Array): VoidPtr;

declare const MONO: MONO;
interface MONO {
mono_wasm_runtime_ready: typeof mono_wasm_runtime_ready;
declare type _MemOffset = number | VoidPtr | NativePointer;
declare function setU8(offset: _MemOffset, value: number): void;
declare function setU16(offset: _MemOffset, value: number): void;
declare function setU32(offset: _MemOffset, value: number): void;
declare function setI8(offset: _MemOffset, value: number): void;
declare function setI16(offset: _MemOffset, value: number): void;
declare function setI32(offset: _MemOffset, value: number): void;
declare function setI64(offset: _MemOffset, value: number): void;
declare function setF32(offset: _MemOffset, value: number): void;
declare function setF64(offset: _MemOffset, value: number): void;
declare function getU8(offset: _MemOffset): number;
declare function getU16(offset: _MemOffset): number;
declare function getU32(offset: _MemOffset): number;
declare function getI8(offset: _MemOffset): number;
declare function getI16(offset: _MemOffset): number;
declare function getI32(offset: _MemOffset): number;
declare function getI64(offset: _MemOffset): number;
declare function getF32(offset: _MemOffset): number;
declare function getF64(offset: _MemOffset): number;

declare const MONO: {
mono_wasm_setenv: typeof mono_wasm_setenv;
mono_wasm_load_data_archive: typeof mono_wasm_load_data_archive;
mono_wasm_load_bytes_into_heap: typeof mono_wasm_load_bytes_into_heap;
mono_wasm_load_icu_data: typeof mono_wasm_load_icu_data;
mono_wasm_runtime_ready: typeof mono_wasm_runtime_ready;
mono_wasm_load_data_archive: typeof mono_wasm_load_data_archive;
mono_wasm_load_config: typeof mono_wasm_load_config;
mono_load_runtime_and_bcl_args: typeof mono_load_runtime_and_bcl_args;
mono_wasm_new_root_buffer: typeof mono_wasm_new_root_buffer;
mono_wasm_new_root: typeof mono_wasm_new_root;
mono_wasm_release_roots: typeof mono_wasm_release_roots;
mono_wasm_add_assembly: (name: string, data: VoidPtr, size: number) => number;
mono_wasm_load_runtime: (unused: string, debug_level: number) => void;
loaded_files: string[];
config: MonoConfig | MonoConfigError;
}
declare const BINDING: BINDING;
interface BINDING {
loaded_files: never[];
setI8: typeof setI8;
setI16: typeof setI16;
setI32: typeof setI32;
setI64: typeof setI64;
setU8: typeof setU8;
setU16: typeof setU16;
setU32: typeof setU32;
setF32: typeof setF32;
setF64: typeof setF64;
getI8: typeof getI8;
getI16: typeof getI16;
getI32: typeof getI32;
getI64: typeof getI64;
getU8: typeof getU8;
getU16: typeof getU16;
getU32: typeof getU32;
getF32: typeof getF32;
getF64: typeof getF64;
};
declare const BINDING: {
mono_obj_array_new: (size: number) => MonoArray;
mono_obj_array_set: (array: MonoArray, idx: number, obj: MonoObject) => void;
js_string_to_mono_string: typeof js_string_to_mono_string;
Expand All @@ -252,10 +288,10 @@ interface BINDING {
bind_static_method: typeof mono_bind_static_method;
call_assembly_entry_point: typeof mono_call_assembly_entry_point;
unbox_mono_obj: typeof unbox_mono_obj;
}
};
interface DotnetPublicAPI {
MONO: MONO;
BINDING: BINDING;
MONO: typeof MONO;
BINDING: typeof BINDING;
INTERNAL: any;
Module: any;
RuntimeId: number;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/dist-types/dotnet.d.ts.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
78af21a88e11709faf2e97c7f4eab76ef277d0262af881eb3001b8d2f385ebdd
106d742df347b40bda6ab3de800fcfa1ebad4f1d93a1c6a78c0bcd627e17a8a2
119 changes: 32 additions & 87 deletions src/mono/wasm/runtime/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import ProductVersion from "consts:productVersion";
import Configuration from "consts:configuration";

import {
mono_wasm_new_root, mono_wasm_new_roots, mono_wasm_release_roots,
mono_wasm_new_root_buffer, mono_wasm_new_root_buffer_from_pointer
mono_wasm_new_root, mono_wasm_release_roots,
mono_wasm_new_root_buffer
} from "./roots";
import {
mono_wasm_send_dbg_command_with_parms,
Expand All @@ -26,7 +26,7 @@ import {
mono_wasm_add_dbg_command_received,
} from "./debug";
import { runtimeHelpers, setImportsAndExports } from "./imports";
import { DotnetModuleConfigImports, DotnetModuleMono, MonoArray, MonoConfig, MonoConfigError, MonoObject } from "./types";
import { DotnetModuleConfigImports, DotnetModule } from "./types";
import {
mono_load_runtime_and_bcl_args, mono_wasm_load_config,
mono_wasm_setenv, mono_wasm_set_runtime_options,
Expand All @@ -41,8 +41,7 @@ import { mono_wasm_load_icu_data, mono_wasm_get_icudt_name } from "./icu";
import { conv_string, js_string_to_mono_string, mono_intern_string } from "./strings";
import { js_to_mono_obj, js_typed_array_to_array, mono_wasm_typed_array_to_array } from "./js-to-cs";
import {
mono_array_to_js_array, mono_wasm_create_cs_owned_object, unbox_mono_obj,
_unbox_mono_obj_root_with_known_nonprimitive_type
mono_array_to_js_array, mono_wasm_create_cs_owned_object, unbox_mono_obj
} from "./cs-to-js";
import {
call_static_method, mono_bind_static_method, mono_call_assembly_entry_point,
Expand All @@ -51,9 +50,7 @@ import {
mono_wasm_get_by_index, mono_wasm_get_global_object, mono_wasm_get_object_property,
mono_wasm_invoke_js,
mono_wasm_invoke_js_blazor,
mono_wasm_invoke_js_with_args, mono_wasm_set_by_index, mono_wasm_set_object_property,
_get_args_root_buffer_for_method_call, _get_buffer_for_method_call,
_handle_exception_for_call, _teardown_after_call
mono_wasm_invoke_js_with_args, mono_wasm_set_by_index, mono_wasm_set_object_property
} from "./method-calls";
import { mono_wasm_typed_array_copy_to, mono_wasm_typed_array_from, mono_wasm_typed_array_copy_from, mono_wasm_load_bytes_into_heap } from "./buffers";
import { mono_wasm_cancel_promise } from "./cancelable-promise";
Expand All @@ -69,10 +66,9 @@ import {
getU8, getU16, getU32, getF32, getF64,
} from "./memory";
import { create_weak_ref } from "./weak-ref";
import { VoidPtr } from "./types/emscripten";
import { fetch_like, readAsync_like } from "./polyfills";

const MONO: MONO = <any>{
const MONO = {
// current "public" MONO API
mono_wasm_setenv,
mono_wasm_load_bytes_into_heap,
Expand All @@ -92,12 +88,28 @@ const MONO: MONO = <any>{
config: runtimeHelpers.config,
loaded_files: [],

// generated bindings closure `library_mono`
mono_wasm_new_root_buffer_from_pointer,
mono_wasm_new_roots,
// memory accessors
setI8,
setI16,
setI32,
setI64,
setU8,
setU16,
setU32,
setF32,
setF64,
getI8,
getI16,
getI32,
getI64,
getU8,
getU16,
getU32,
getF32,
getF64,
};

const BINDING: BINDING = <any>{
const BINDING = {
//current "public" BINDING API
mono_obj_array_new: cwraps.mono_wasm_obj_array_new,
mono_obj_array_set: cwraps.mono_wasm_obj_array_set,
Expand All @@ -109,16 +121,6 @@ const BINDING: BINDING = <any>{
bind_static_method: mono_bind_static_method,
call_assembly_entry_point: mono_call_assembly_entry_point,
unbox_mono_obj,

// generated bindings closure `binding_support`
// todo use the methods directly in the closure, not via BINDING
_get_args_root_buffer_for_method_call,
_get_buffer_for_method_call,
invoke_method: cwraps.mono_wasm_invoke_method,
_handle_exception_for_call,
mono_wasm_try_unbox_primitive_and_get_type: cwraps.mono_wasm_try_unbox_primitive_and_get_type,
_unbox_mono_obj_root_with_known_nonprimitive_type,
_teardown_after_call,
};

let exportedAPI: DotnetPublicAPI;
Expand All @@ -131,12 +133,8 @@ function initializeImportsAndExports(
exports: { mono: any, binding: any, internal: any, module: any },
replacements: { scriptDirectory: any, fetch: any, readAsync: any },
): DotnetPublicAPI {
const module = exports.module as DotnetModuleMono;
const module = exports.module as DotnetModule;
const globalThisAny = globalThis as any;
if (module.scriptDirectory) {
replacements.scriptDirectory = module.scriptDirectory;
}


// we want to have same instance of MONO, BINDING and Module in dotnet iffe
setImportsAndExports(imports, exports);
Expand Down Expand Up @@ -194,12 +192,13 @@ function initializeImportsAndExports(

if (module.imports.fetch) {
runtimeHelpers.fetch = module.imports.fetch;
} else if (globalThisAny.fetch) {
runtimeHelpers.fetch = globalThisAny.fetch;
}
else {
runtimeHelpers.fetch = fetch_like;
}
if (module.scriptDirectory) {
replacements.scriptDirectory = module.scriptDirectory;
}
replacements.fetch = runtimeHelpers.fetch;
replacements.readAsync = readAsync_like;

Expand Down Expand Up @@ -339,68 +338,14 @@ const INTERNAL: any = {
mono_wasm_detach_debugger,
mono_wasm_raise_debug_event,
mono_wasm_runtime_is_ready: runtimeHelpers.mono_wasm_runtime_is_ready,

// memory accessors
setI8,
setI16,
setI32,
setI64,
setU8,
setU16,
setU32,
setF32,
setF64,
getI8,
getI16,
getI32,
getI64,
getU8,
getU16,
getU32,
getF32,
getF64,
};

// this represents visibility in the javascript
// like https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web.JS/src/Platform/Mono/MonoTypes.ts
interface MONO {
mono_wasm_runtime_ready: typeof mono_wasm_runtime_ready
mono_wasm_setenv: typeof mono_wasm_setenv
mono_wasm_load_data_archive: typeof mono_wasm_load_data_archive;
mono_wasm_load_bytes_into_heap: typeof mono_wasm_load_bytes_into_heap;
mono_wasm_load_icu_data: typeof mono_wasm_load_icu_data;
mono_wasm_load_config: typeof mono_wasm_load_config;
mono_load_runtime_and_bcl_args: typeof mono_load_runtime_and_bcl_args;
mono_wasm_new_root_buffer: typeof mono_wasm_new_root_buffer;
mono_wasm_new_root: typeof mono_wasm_new_root;
mono_wasm_release_roots: typeof mono_wasm_release_roots;

// for Blazor's future!
mono_wasm_add_assembly: (name: string, data: VoidPtr, size: number) => number,
mono_wasm_load_runtime: (unused: string, debug_level: number) => void,

loaded_files: string[];
config: MonoConfig | MonoConfigError,
}

// this represents visibility in the javascript
// like https://github.com/dotnet/aspnetcore/blob/main/src/Components/Web.JS/src/Platform/Mono/MonoTypes.ts
interface BINDING {
mono_obj_array_new: (size: number) => MonoArray,
mono_obj_array_set: (array: MonoArray, idx: number, obj: MonoObject) => void,
js_string_to_mono_string: typeof js_string_to_mono_string,
js_typed_array_to_array: typeof js_typed_array_to_array,
js_to_mono_obj: typeof js_to_mono_obj,
mono_array_to_js_array: typeof mono_array_to_js_array,
conv_string: typeof conv_string,
bind_static_method: typeof mono_bind_static_method,
call_assembly_entry_point: typeof mono_call_assembly_entry_point,
unbox_mono_obj: typeof unbox_mono_obj
}

export interface DotnetPublicAPI {
MONO: MONO,
BINDING: BINDING,
MONO: typeof MONO,
BINDING: typeof BINDING,
INTERNAL: any,
Module: any,
RuntimeId: number,
Expand Down
11 changes: 8 additions & 3 deletions src/mono/wasm/runtime/icu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

import cwraps from "./cwraps";
import { MonoInitContext } from "./startup";
import { GlobalizationMode } from "./types";
import { VoidPtr } from "./types/emscripten";

Expand All @@ -28,17 +29,21 @@ export function mono_wasm_get_icudt_name(culture: string): string {
// @globalization_mode is one of "icu", "invariant", or "auto".
// "auto" will use "icu" if any ICU data archives have been loaded,
// otherwise "invariant".
export function mono_wasm_globalization_init(globalization_mode: GlobalizationMode): void {
export function mono_wasm_globalization_init(globalization_mode: GlobalizationMode, ctx: MonoInitContext): void {
let invariantMode = false;

if (globalization_mode === "invariant")
invariantMode = true;

if (!invariantMode) {
if (num_icu_assets_loaded_successfully > 0) {
console.debug("MONO_WASM: ICU data archive(s) loaded, disabling invariant mode");
if (ctx.tracing) {
console.debug("MONO_WASM: ICU data archive(s) loaded, disabling invariant mode");
}
} else if (globalization_mode !== "icu") {
console.debug("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode");
if (ctx.tracing) {
console.debug("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode");
}
invariantMode = true;
} else {
const msg = "invariant globalization mode is inactive and no ICU data archives were loaded";
Expand Down
Loading