Skip to content

Commit 6ba858e

Browse files
committed
- use import to load dotnet.js instead of html tag
- updated createEmscriptenModuleInstance to use the new createDotnetRuntime() API - removed @types/emscripten type definitions - added src/Components/Web.JS/@types/dotnet temporarily, until we figure out how to pull this out of Microsoft.NETCore.App.Runtime.Mono.browser-wasm.7.0.0-dev.nupkg - fixed usages of addRunDependency, removeRunDependency - mapped System_Object and other types to MonoObject etc - global Module is no longer needed by runtime - therefore removed __wasmmodulecallback__ - removed few cwrap calls and replaced them with API usage
1 parent 5ebacff commit 6ba858e

File tree

11 files changed

+626
-286
lines changed

11 files changed

+626
-286
lines changed
Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
//! Licensed to the .NET Foundation under one or more agreements.
2+
//! The .NET Foundation licenses this file to you under the MIT license.
3+
//!
4+
//! This is generated file, see src/mono/wasm/runtime/rollup.config.js
5+
6+
declare interface ManagedPointer {
7+
__brandManagedPointer: "ManagedPointer";
8+
}
9+
declare interface NativePointer {
10+
__brandNativePointer: "NativePointer";
11+
}
12+
declare interface VoidPtr extends NativePointer {
13+
__brand: "VoidPtr";
14+
}
15+
declare interface CharPtr extends NativePointer {
16+
__brand: "CharPtr";
17+
}
18+
declare interface Int32Ptr extends NativePointer {
19+
__brand: "Int32Ptr";
20+
}
21+
declare interface EmscriptenModule {
22+
HEAP8: Int8Array;
23+
HEAP16: Int16Array;
24+
HEAP32: Int32Array;
25+
HEAPU8: Uint8Array;
26+
HEAPU16: Uint16Array;
27+
HEAPU32: Uint32Array;
28+
HEAPF32: Float32Array;
29+
HEAPF64: Float64Array;
30+
_malloc(size: number): VoidPtr;
31+
_free(ptr: VoidPtr): void;
32+
print(message: string): void;
33+
printErr(message: string): void;
34+
ccall<T>(ident: string, returnType?: string | null, argTypes?: string[], args?: any[], opts?: any): T;
35+
cwrap<T extends Function>(ident: string, returnType: string, argTypes?: string[], opts?: any): T;
36+
cwrap<T extends Function>(ident: string, ...args: any[]): T;
37+
setValue(ptr: VoidPtr, value: number, type: string, noSafe?: number | boolean): void;
38+
setValue(ptr: Int32Ptr, value: number, type: string, noSafe?: number | boolean): void;
39+
getValue(ptr: number, type: string, noSafe?: number | boolean): number;
40+
UTF8ToString(ptr: CharPtr, maxBytesToRead?: number): string;
41+
UTF8ArrayToString(u8Array: Uint8Array, idx?: number, maxBytesToRead?: number): string;
42+
FS_createPath(parent: string, path: string, canRead?: boolean, canWrite?: boolean): string;
43+
FS_createDataFile(parent: string, name: string, data: TypedArray, canRead: boolean, canWrite: boolean, canOwn?: boolean): string;
44+
removeRunDependency(id: string): void;
45+
addRunDependency(id: string): void;
46+
ready: Promise<unknown>;
47+
preInit?: (() => any)[];
48+
preRun?: (() => any)[];
49+
postRun?: (() => any)[];
50+
onAbort?: {
51+
(error: any): void;
52+
};
53+
onRuntimeInitialized?: () => any;
54+
instantiateWasm: (imports: any, successCallback: Function) => any;
55+
}
56+
declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
57+
58+
/**
59+
* Allocates a block of memory that can safely contain pointers into the managed heap.
60+
* The result object has get(index) and set(index, value) methods that can be used to retrieve and store managed pointers.
61+
* Once you are done using the root buffer, you must call its release() method.
62+
* For small numbers of roots, it is preferable to use the mono_wasm_new_root and mono_wasm_new_roots APIs instead.
63+
*/
64+
declare function mono_wasm_new_root_buffer(capacity: number, name?: string): WasmRootBuffer;
65+
/**
66+
* Allocates temporary storage for a pointer into the managed heap.
67+
* Pointers stored here will be visible to the GC, ensuring that the object they point to aren't moved or collected.
68+
* If you already have a managed pointer you can pass it as an argument to initialize the temporary storage.
69+
* The result object has get() and set(value) methods, along with a .value property.
70+
* When you are done using the root you must call its .release() method.
71+
*/
72+
declare function mono_wasm_new_root<T extends ManagedPointer | NativePointer>(value?: T | undefined): WasmRoot<T>;
73+
/**
74+
* Releases 1 or more root or root buffer objects.
75+
* Multiple objects may be passed on the argument list.
76+
* 'undefined' may be passed as an argument so it is safe to call this method from finally blocks
77+
* even if you are not sure all of your roots have been created yet.
78+
* @param {... WasmRoot} roots
79+
*/
80+
declare function mono_wasm_release_roots(...args: WasmRoot<any>[]): void;
81+
declare class WasmRootBuffer {
82+
private __count;
83+
private length;
84+
private __offset;
85+
private __offset32;
86+
private __handle;
87+
private __ownsAllocation;
88+
constructor(offset: VoidPtr, capacity: number, ownsAllocation: boolean, name?: string);
89+
_throw_index_out_of_range(): void;
90+
_check_in_range(index: number): void;
91+
get_address(index: number): NativePointer;
92+
get_address_32(index: number): number;
93+
get(index: number): ManagedPointer;
94+
set(index: number, value: ManagedPointer): ManagedPointer;
95+
_unsafe_get(index: number): number;
96+
_unsafe_set(index: number, value: ManagedPointer | NativePointer): void;
97+
clear(): void;
98+
release(): void;
99+
toString(): string;
100+
}
101+
declare class WasmRoot<T extends ManagedPointer | NativePointer> {
102+
private __buffer;
103+
private __index;
104+
constructor(buffer: WasmRootBuffer, index: number);
105+
get_address(): NativePointer;
106+
get_address_32(): number;
107+
get(): T;
108+
set(value: T): T;
109+
get value(): T;
110+
set value(value: T);
111+
valueOf(): T;
112+
clear(): void;
113+
release(): void;
114+
toString(): string;
115+
}
116+
117+
interface MonoObject extends ManagedPointer {
118+
__brandMonoObject: "MonoObject";
119+
}
120+
interface MonoString extends MonoObject {
121+
__brand: "MonoString";
122+
}
123+
interface MonoArray extends MonoObject {
124+
__brand: "MonoArray";
125+
}
126+
declare type MonoConfig = {
127+
isError: false;
128+
assembly_root: string;
129+
assets: AllAssetEntryTypes[];
130+
debug_level?: number;
131+
enable_debugging?: number;
132+
globalization_mode: GlobalizationMode;
133+
diagnostic_tracing?: boolean;
134+
remote_sources?: string[];
135+
environment_variables?: {
136+
[i: string]: string;
137+
};
138+
runtime_options?: string[];
139+
aot_profiler_options?: AOTProfilerOptions;
140+
coverage_profiler_options?: CoverageProfilerOptions;
141+
ignore_pdb_load_errors?: boolean;
142+
};
143+
declare type MonoConfigError = {
144+
isError: true;
145+
message: string;
146+
error: any;
147+
};
148+
declare type AllAssetEntryTypes = AssetEntry | AssemblyEntry | SatelliteAssemblyEntry | VfsEntry | IcuData;
149+
declare type AssetEntry = {
150+
name: string;
151+
behavior: AssetBehaviours;
152+
virtual_path?: string;
153+
culture?: string;
154+
load_remote?: boolean;
155+
is_optional?: boolean;
156+
};
157+
interface AssemblyEntry extends AssetEntry {
158+
name: "assembly";
159+
}
160+
interface SatelliteAssemblyEntry extends AssetEntry {
161+
name: "resource";
162+
culture: string;
163+
}
164+
interface VfsEntry extends AssetEntry {
165+
name: "vfs";
166+
virtual_path: string;
167+
}
168+
interface IcuData extends AssetEntry {
169+
name: "icu";
170+
load_remote: boolean;
171+
}
172+
declare const enum AssetBehaviours {
173+
Resource = "resource",
174+
Assembly = "assembly",
175+
Heap = "heap",
176+
ICU = "icu",
177+
VFS = "vfs"
178+
}
179+
declare const enum GlobalizationMode {
180+
ICU = "icu",
181+
INVARIANT = "invariant",
182+
AUTO = "auto"
183+
}
184+
declare type AOTProfilerOptions = {
185+
write_at?: string;
186+
send_to?: string;
187+
};
188+
declare type CoverageProfilerOptions = {
189+
write_at?: string;
190+
send_to?: string;
191+
};
192+
declare type DotnetModuleConfig = {
193+
disableDotnet6Compatibility?: boolean;
194+
config?: MonoConfig | MonoConfigError;
195+
configSrc?: string;
196+
scriptDirectory?: string;
197+
onConfigLoaded?: () => void;
198+
onDotnetReady?: () => void;
199+
imports?: DotnetModuleConfigImports;
200+
} & EmscriptenModule;
201+
declare type DotnetModuleConfigImports = {
202+
require?: (name: string) => any;
203+
fetch?: (url: string) => Promise<Response>;
204+
fs?: {
205+
promises?: {
206+
readFile?: (path: string) => Promise<string | Buffer>;
207+
};
208+
readFileSync?: (path: string, options: any | undefined) => string;
209+
};
210+
crypto?: {
211+
randomBytes?: (size: number) => Buffer;
212+
};
213+
ws?: WebSocket & {
214+
Server: any;
215+
};
216+
path?: {
217+
normalize?: (path: string) => string;
218+
dirname?: (path: string) => string;
219+
};
220+
url?: any;
221+
};
222+
223+
declare function mono_wasm_runtime_ready(): void;
224+
225+
declare function mono_wasm_setenv(name: string, value: string): void;
226+
declare function mono_load_runtime_and_bcl_args(config: MonoConfig | MonoConfigError | undefined): Promise<void>;
227+
declare function mono_wasm_load_data_archive(data: Uint8Array, prefix: string): boolean;
228+
/**
229+
* Loads the mono config file (typically called mono-config.json) asynchroniously
230+
* Note: the run dependencies are so emsdk actually awaits it in order.
231+
*
232+
* @param {string} configFilePath - relative path to the config file
233+
* @throws Will throw an error if the config file loading fails
234+
*/
235+
declare function mono_wasm_load_config(configFilePath: string): Promise<void>;
236+
237+
declare function mono_wasm_load_icu_data(offset: VoidPtr): boolean;
238+
239+
declare function conv_string(mono_obj: MonoString): string | null;
240+
declare function js_string_to_mono_string(string: string): MonoString;
241+
242+
declare function js_to_mono_obj(js_obj: any): MonoObject;
243+
declare function js_typed_array_to_array(js_obj: any): MonoArray;
244+
245+
declare function unbox_mono_obj(mono_obj: MonoObject): any;
246+
declare function mono_array_to_js_array(mono_array: MonoArray): any[] | null;
247+
248+
declare function mono_bind_static_method(fqn: string, signature?: string): Function;
249+
declare function mono_call_assembly_entry_point(assembly: string, args?: any[], signature?: string): number;
250+
251+
declare function mono_wasm_load_bytes_into_heap(bytes: Uint8Array): VoidPtr;
252+
253+
declare type _MemOffset = number | VoidPtr | NativePointer;
254+
declare function setU8(offset: _MemOffset, value: number): void;
255+
declare function setU16(offset: _MemOffset, value: number): void;
256+
declare function setU32(offset: _MemOffset, value: number): void;
257+
declare function setI8(offset: _MemOffset, value: number): void;
258+
declare function setI16(offset: _MemOffset, value: number): void;
259+
declare function setI32(offset: _MemOffset, value: number): void;
260+
declare function setI64(offset: _MemOffset, value: number): void;
261+
declare function setF32(offset: _MemOffset, value: number): void;
262+
declare function setF64(offset: _MemOffset, value: number): void;
263+
declare function getU8(offset: _MemOffset): number;
264+
declare function getU16(offset: _MemOffset): number;
265+
declare function getU32(offset: _MemOffset): number;
266+
declare function getI8(offset: _MemOffset): number;
267+
declare function getI16(offset: _MemOffset): number;
268+
declare function getI32(offset: _MemOffset): number;
269+
declare function getI64(offset: _MemOffset): number;
270+
declare function getF32(offset: _MemOffset): number;
271+
declare function getF64(offset: _MemOffset): number;
272+
273+
declare function mono_run_main_and_exit(main_assembly_name: string, args: string[]): Promise<void>;
274+
declare function mono_run_main(main_assembly_name: string, args: string[]): Promise<number>;
275+
276+
declare const MONO: {
277+
mono_wasm_setenv: typeof mono_wasm_setenv;
278+
mono_wasm_load_bytes_into_heap: typeof mono_wasm_load_bytes_into_heap;
279+
mono_wasm_load_icu_data: typeof mono_wasm_load_icu_data;
280+
mono_wasm_runtime_ready: typeof mono_wasm_runtime_ready;
281+
mono_wasm_load_data_archive: typeof mono_wasm_load_data_archive;
282+
mono_wasm_load_config: typeof mono_wasm_load_config;
283+
mono_load_runtime_and_bcl_args: typeof mono_load_runtime_and_bcl_args;
284+
mono_wasm_new_root_buffer: typeof mono_wasm_new_root_buffer;
285+
mono_wasm_new_root: typeof mono_wasm_new_root;
286+
mono_wasm_release_roots: typeof mono_wasm_release_roots;
287+
mono_run_main: typeof mono_run_main;
288+
mono_run_main_and_exit: typeof mono_run_main_and_exit;
289+
mono_wasm_add_assembly: (name: string, data: VoidPtr, size: number) => number;
290+
mono_wasm_load_runtime: (unused: string, debug_level: number) => void;
291+
config: MonoConfig | MonoConfigError;
292+
loaded_files: string[];
293+
setI8: typeof setI8;
294+
setI16: typeof setI16;
295+
setI32: typeof setI32;
296+
setI64: typeof setI64;
297+
setU8: typeof setU8;
298+
setU16: typeof setU16;
299+
setU32: typeof setU32;
300+
setF32: typeof setF32;
301+
setF64: typeof setF64;
302+
getI8: typeof getI8;
303+
getI16: typeof getI16;
304+
getI32: typeof getI32;
305+
getI64: typeof getI64;
306+
getU8: typeof getU8;
307+
getU16: typeof getU16;
308+
getU32: typeof getU32;
309+
getF32: typeof getF32;
310+
getF64: typeof getF64;
311+
};
312+
declare type MONOType = typeof MONO;
313+
declare const BINDING: {
314+
mono_obj_array_new: (size: number) => MonoArray;
315+
mono_obj_array_set: (array: MonoArray, idx: number, obj: MonoObject) => void;
316+
js_string_to_mono_string: typeof js_string_to_mono_string;
317+
js_typed_array_to_array: typeof js_typed_array_to_array;
318+
js_to_mono_obj: typeof js_to_mono_obj;
319+
mono_array_to_js_array: typeof mono_array_to_js_array;
320+
conv_string: typeof conv_string;
321+
bind_static_method: typeof mono_bind_static_method;
322+
call_assembly_entry_point: typeof mono_call_assembly_entry_point;
323+
unbox_mono_obj: typeof unbox_mono_obj;
324+
};
325+
declare type BINDINGType = typeof BINDING;
326+
interface DotnetPublicAPI {
327+
MONO: typeof MONO;
328+
BINDING: typeof BINDING;
329+
INTERNAL: any;
330+
Module: EmscriptenModule;
331+
RuntimeId: number;
332+
RuntimeBuildInfo: {
333+
ProductVersion: string;
334+
Configuration: string;
335+
};
336+
}
337+
338+
declare function createDotnetRuntime(moduleFactory: DotnetModuleConfig | ((api: DotnetPublicAPI) => DotnetModuleConfig)): Promise<DotnetPublicAPI>;
339+
declare type CreateDotnetRuntimeType = typeof createDotnetRuntime;
340+
declare global {
341+
function getDotnetRuntime(runtimeId: number): DotnetPublicAPI | undefined;
342+
}
343+
344+
export { BINDINGType, CreateDotnetRuntimeType, DotnetModuleConfig, DotnetPublicAPI, EmscriptenModule, MONOType, MonoArray, MonoObject, MonoString, VoidPtr, createDotnetRuntime as default };
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "dotnet-runtime",
3+
"description": ".NET is a developer platform with tools and libraries for building any type of app, including web, mobile, desktop, games, IoT, cloud, and microservices.",
4+
"repository": {
5+
"type": "git",
6+
"url": "[email protected]:dotnet/runtime.git"
7+
},
8+
"version": "1.0.0",
9+
"main": "dotnet.js",
10+
"types": "dotnet.d.ts",
11+
"scripts": {
12+
"rollup": "rollup -c",
13+
"lint": "eslint --no-color --max-warnings=0 ./**/*.ts ./*.js"
14+
},
15+
"keywords": [
16+
"dotnet",
17+
"runtime",
18+
"wasm"
19+
],
20+
"author": "Microsoft",
21+
"license": "MIT",
22+
"devDependencies": {
23+
"@rollup/plugin-typescript": "8.2.5",
24+
"@typescript-eslint/eslint-plugin": "4.31.2",
25+
"@typescript-eslint/parser": "4.31.2",
26+
"eslint": "7.32.0",
27+
"rollup": "2.56.3",
28+
"rollup-plugin-consts": "1.0.2",
29+
"rollup-plugin-dts": "4.0.0",
30+
"rollup-plugin-terser": "7.0.2",
31+
"tslib": "2.3.1",
32+
"typescript": "4.4.3"
33+
}
34+
}

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@microsoft/dotnet-js-interop": "link:../../JSInterop/Microsoft.JSInterop.JS/src",
2424
"@microsoft/signalr": "link:../../SignalR/clients/ts/signalr",
2525
"@microsoft/signalr-protocol-msgpack": "link:../../SignalR/clients/ts/signalr-protocol-msgpack",
26-
"@types/emscripten": "^1.39.5",
26+
"@types/dotnet": "./@types/dotnet",
2727
"@types/jest": "^27.0.1",
2828
"@types/jsdom": "^16.2.13",
2929
"@typescript-eslint/eslint-plugin": "^4.29.3",

0 commit comments

Comments
 (0)