Skip to content

Commit 2c9198f

Browse files
authored
[Blazor] Finalize the integration between runtime and Blazor (#49385)
* Drop extra download of boot config * Move lazy assembly loading to runtime * Move library initializers loading to runtime * Move library initializers loading to runtime
1 parent 579d547 commit 2c9198f

File tree

11 files changed

+255
-366
lines changed

11 files changed

+255
-366
lines changed

src/Components/Web.JS/@types/dotnet/dotnet.d.ts

Lines changed: 185 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,7 @@
33
//!
44
//! This is generated file, see src/mono/wasm/runtime/rollup.config.js
55

6-
//! This is not considered public API with backward compatibility guarantees.
7-
8-
interface DotnetHostBuilder {
9-
withConfig(config: MonoConfig): DotnetHostBuilder;
10-
withConfigSrc(configSrc: string): DotnetHostBuilder;
11-
withApplicationArguments(...args: string[]): DotnetHostBuilder;
12-
withEnvironmentVariable(name: string, value: string): DotnetHostBuilder;
13-
withEnvironmentVariables(variables: {
14-
[i: string]: string;
15-
}): DotnetHostBuilder;
16-
withVirtualWorkingDirectory(vfsPath: string): DotnetHostBuilder;
17-
withDiagnosticTracing(enabled: boolean): DotnetHostBuilder;
18-
withDebugging(level: number): DotnetHostBuilder;
19-
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder;
20-
withApplicationArgumentsFromQuery(): DotnetHostBuilder;
21-
create(): Promise<RuntimeAPI>;
22-
run(): Promise<number>;
23-
}
6+
//! This is not considered public API with backward compatibility guarantees.
247

258
declare interface NativePointer {
269
__brandNativePointer: "NativePointer";
@@ -35,18 +18,28 @@ declare interface Int32Ptr extends NativePointer {
3518
__brand: "Int32Ptr";
3619
}
3720
declare interface EmscriptenModule {
21+
/** @deprecated Please use growableHeapI8() instead.*/
3822
HEAP8: Int8Array;
23+
/** @deprecated Please use growableHeapI16() instead.*/
3924
HEAP16: Int16Array;
25+
/** @deprecated Please use growableHeapI32() instead. */
4026
HEAP32: Int32Array;
27+
/** @deprecated Please use growableHeapI64() instead. */
28+
HEAP64: BigInt64Array;
29+
/** @deprecated Please use growableHeapU8() instead. */
4130
HEAPU8: Uint8Array;
31+
/** @deprecated Please use growableHeapU16() instead. */
4232
HEAPU16: Uint16Array;
33+
/** @deprecated Please use growableHeapU32() instead */
4334
HEAPU32: Uint32Array;
35+
/** @deprecated Please use growableHeapF32() instead */
4436
HEAPF32: Float32Array;
37+
/** @deprecated Please use growableHeapF64() instead. */
4538
HEAPF64: Float64Array;
4639
_malloc(size: number): VoidPtr;
4740
_free(ptr: VoidPtr): void;
48-
print(message: string): void;
49-
printErr(message: string): void;
41+
out(message: string): void;
42+
err(message: string): void;
5043
ccall<T>(ident: string, returnType?: string | null, argTypes?: string[], args?: any[], opts?: any): T;
5144
cwrap<T extends Function>(ident: string, returnType: string, argTypes?: string[], opts?: any): T;
5245
cwrap<T extends Function>(ident: string, ...args: any[]): T;
@@ -55,17 +48,13 @@ declare interface EmscriptenModule {
5548
getValue(ptr: number, type: string, noSafe?: number | boolean): number;
5649
UTF8ToString(ptr: CharPtr, maxBytesToRead?: number): string;
5750
UTF8ArrayToString(u8Array: Uint8Array, idx?: number, maxBytesToRead?: number): string;
51+
stringToUTF8Array(str: string, heap: Uint8Array, outIdx: number, maxBytesToWrite: number): void;
5852
FS_createPath(parent: string, path: string, canRead?: boolean, canWrite?: boolean): string;
5953
FS_createDataFile(parent: string, name: string, data: TypedArray, canRead: boolean, canWrite: boolean, canOwn?: boolean): string;
60-
FS_readFile(filename: string, opts: any): any;
61-
removeRunDependency(id: string): void;
62-
addRunDependency(id: string): void;
6354
addFunction(fn: Function, signature: string): number;
64-
getWasmTableEntry(index: number): any;
6555
stackSave(): VoidPtr;
6656
stackRestore(stack: VoidPtr): void;
6757
stackAlloc(size: number): VoidPtr;
68-
ready: Promise<unknown>;
6958
instantiateWasm?: InstantiateWasmCallBack;
7059
preInit?: (() => any)[] | (() => any);
7160
preRun?: (() => any)[] | (() => any);
@@ -79,6 +68,29 @@ type InstantiateWasmSuccessCallback = (instance: WebAssembly.Instance, module: W
7968
type InstantiateWasmCallBack = (imports: WebAssembly.Imports, successCallback: InstantiateWasmSuccessCallback) => any;
8069
declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
8170

71+
interface DotnetHostBuilder {
72+
withConfig(config: MonoConfig): DotnetHostBuilder;
73+
withConfigSrc(configSrc: string): DotnetHostBuilder;
74+
withApplicationArguments(...args: string[]): DotnetHostBuilder;
75+
withEnvironmentVariable(name: string, value: string): DotnetHostBuilder;
76+
withEnvironmentVariables(variables: {
77+
[i: string]: string;
78+
}): DotnetHostBuilder;
79+
withVirtualWorkingDirectory(vfsPath: string): DotnetHostBuilder;
80+
withDiagnosticTracing(enabled: boolean): DotnetHostBuilder;
81+
withDebugging(level: number): DotnetHostBuilder;
82+
withMainAssembly(mainAssemblyName: string): DotnetHostBuilder;
83+
withApplicationArgumentsFromQuery(): DotnetHostBuilder;
84+
withApplicationEnvironment(applicationEnvironment?: string): DotnetHostBuilder;
85+
withApplicationCulture(applicationCulture?: string): DotnetHostBuilder;
86+
/**
87+
* Overrides the built-in boot resource loading mechanism so that boot resources can be fetched
88+
* from a custom source, such as an external CDN.
89+
*/
90+
withResourceLoader(loadBootResource?: LoadBootResourceCallback): DotnetHostBuilder;
91+
create(): Promise<RuntimeAPI>;
92+
run(): Promise<number>;
93+
}
8294
type MonoConfig = {
8395
/**
8496
* The subfolder containing managed assemblies and pdbs. This is relative to dotnet.js script.
@@ -115,7 +127,7 @@ type MonoConfig = {
115127
/**
116128
* debugLevel > 0 enables debugging and sets the debug log level to debugLevel
117129
* debugLevel == 0 disables debugging and enables interpreter optimizations
118-
* debugLevel < 0 enabled debugging and disables debug logging.
130+
* debugLevel < 0 enables debugging and disables debug logging.
119131
*/
120132
debugLevel?: number;
121133
/**
@@ -136,11 +148,63 @@ type MonoConfig = {
136148
* If true, the snapshot of runtime's memory will be stored in the browser and used for faster startup next time. Default is false.
137149
*/
138150
startupMemoryCache?: boolean;
151+
/**
152+
* hash of assets
153+
*/
154+
assetsHash?: string;
139155
/**
140156
* application environment
141157
*/
142158
applicationEnvironment?: string;
159+
/**
160+
* Gets the application culture. This is a name specified in the BCP 47 format. See https://tools.ietf.org/html/bcp47
161+
*/
162+
applicationCulture?: string;
163+
/**
164+
* definition of assets to load along with the runtime.
165+
*/
166+
resources?: ResourceGroups;
167+
/**
168+
* config extensions declared in MSBuild items @(WasmBootConfigExtension)
169+
*/
170+
extensions?: {
171+
[name: string]: any;
172+
};
173+
};
174+
type ResourceExtensions = {
175+
[extensionName: string]: ResourceList;
176+
};
177+
interface ResourceGroups {
178+
readonly hash?: string;
179+
readonly assembly?: ResourceList;
180+
readonly lazyAssembly?: ResourceList;
181+
readonly pdb?: ResourceList;
182+
readonly runtime?: ResourceList;
183+
readonly satelliteResources?: {
184+
[cultureName: string]: ResourceList;
185+
};
186+
readonly libraryInitializers?: {
187+
readonly onRuntimeConfigLoaded: ResourceList;
188+
readonly onRuntimeReady: ResourceList;
189+
};
190+
readonly extensions?: ResourceExtensions;
191+
readonly vfs?: {
192+
[virtualPath: string]: ResourceList;
193+
};
194+
}
195+
type ResourceList = {
196+
[name: string]: string;
143197
};
198+
/**
199+
* Overrides the built-in boot resource loading mechanism so that boot resources can be fetched
200+
* from a custom source, such as an external CDN.
201+
* @param type The type of the resource to be loaded.
202+
* @param name The name of the resource to be loaded.
203+
* @param defaultUri The URI from which the framework would fetch the resource by default. The URI may be relative or absolute.
204+
* @param integrity The integrity string representing the expected content in the response.
205+
* @returns A URI string or a Response promise to override the loading process, or null/undefined to allow the default loading behavior.
206+
*/
207+
type LoadBootResourceCallback = (type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) => string | Promise<Response> | null | undefined;
144208
interface ResourceRequest {
145209
name: string;
146210
behavior: AssetBehaviours;
@@ -180,15 +244,86 @@ interface AssetEntry extends ResourceRequest {
180244
*/
181245
pendingDownload?: LoadingResource;
182246
}
183-
type AssetBehaviours = "resource" | "assembly" | "pdb" | "heap" | "icu" | "vfs" | "dotnetwasm" | "js-module-threads";
184-
type GlobalizationMode = "icu" | // load ICU globalization data from any runtime assets with behavior "icu".
185-
"invariant" | // operate in invariant globalization mode.
186-
"auto";
247+
type AssetBehaviours =
248+
/**
249+
* Load asset as a managed resource assembly.
250+
*/
251+
"resource"
252+
/**
253+
* Load asset as a managed assembly.
254+
*/
255+
| "assembly"
256+
/**
257+
* Load asset as a managed debugging information.
258+
*/
259+
| "pdb"
260+
/**
261+
* Store asset into the native heap.
262+
*/
263+
| "heap"
264+
/**
265+
* Load asset as an ICU data archive.
266+
*/
267+
| "icu"
268+
/**
269+
* Load asset into the virtual filesystem (for fopen, File.Open, etc).
270+
*/
271+
| "vfs"
272+
/**
273+
* The binary of the dotnet runtime.
274+
*/
275+
| "dotnetwasm"
276+
/**
277+
* The javascript module for threads.
278+
*/
279+
| "js-module-threads"
280+
/**
281+
* The javascript module for threads.
282+
*/
283+
| "js-module-runtime"
284+
/**
285+
* The javascript module for threads.
286+
*/
287+
| "js-module-dotnet"
288+
/**
289+
* The javascript module for threads.
290+
*/
291+
| "js-module-native"
292+
/**
293+
* The javascript module that came from nuget package .
294+
*/
295+
| "js-module-library-initializer"
296+
/**
297+
* The javascript module for threads.
298+
*/
299+
| "symbols";
300+
declare const enum GlobalizationMode {
301+
/**
302+
* Load sharded ICU data.
303+
*/
304+
Sharded = "sharded",
305+
/**
306+
* Load all ICU data.
307+
*/
308+
All = "all",
309+
/**
310+
* Operate in invariant globalization mode.
311+
*/
312+
Invariant = "invariant",
313+
/**
314+
* Use user defined icu file.
315+
*/
316+
Custom = "custom",
317+
/**
318+
* Operate in hybrid globalization mode with small ICU files, using native platform functions.
319+
*/
320+
Hybrid = "hybrid"
321+
}
187322
type DotnetModuleConfig = {
188323
disableDotnet6Compatibility?: boolean;
189324
config?: MonoConfig;
190325
configSrc?: string;
191-
onConfigLoaded?: (config: MonoConfig & BootJsonData) => void | Promise<void>;
326+
onConfigLoaded?: (config: MonoConfig) => void | Promise<void>;
192327
onDotnetReady?: () => void | Promise<void>;
193328
onDownloadResourceProgress?: (resourcesLoaded: number, totalResources: number) => void;
194329
getApplicationEnvironment?: (bootConfigResponse: Response) => string | null;
@@ -203,6 +338,7 @@ type APIType = {
203338
getAssemblyExports(assemblyName: string): Promise<any>;
204339
setModuleImports(moduleName: string, moduleImports: any): void;
205340
getConfig: () => MonoConfig;
341+
invokeLibraryInitializers: (functionName: string, args: any[]) => Promise<void>;
206342
setHeapB32: (offset: NativePointer, value: number | boolean) => void;
207343
setHeapU8: (offset: NativePointer, value: number) => void;
208344
setHeapU16: (offset: NativePointer, value: number) => void;
@@ -227,6 +363,15 @@ type APIType = {
227363
getHeapI64Big: (offset: NativePointer) => bigint;
228364
getHeapF32: (offset: NativePointer) => number;
229365
getHeapF64: (offset: NativePointer) => number;
366+
localHeapViewI8: () => Int8Array;
367+
localHeapViewI16: () => Int16Array;
368+
localHeapViewI32: () => Int32Array;
369+
localHeapViewI64Big: () => BigInt64Array;
370+
localHeapViewU8: () => Uint8Array;
371+
localHeapViewU16: () => Uint16Array;
372+
localHeapViewU32: () => Uint32Array;
373+
localHeapViewF32: () => Float32Array;
374+
localHeapViewF64: () => Float64Array;
230375
};
231376
type RuntimeAPI = {
232377
/**
@@ -250,8 +395,8 @@ type ModuleAPI = {
250395
dotnet: DotnetHostBuilder;
251396
exit: (code: number, reason?: any) => void;
252397
};
253-
declare function createDotnetRuntime(moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)): Promise<RuntimeAPI>;
254-
type CreateDotnetRuntimeType = typeof createDotnetRuntime;
398+
type CreateDotnetRuntimeType = (moduleFactory: DotnetModuleConfig | ((api: RuntimeAPI) => DotnetModuleConfig)) => Promise<RuntimeAPI>;
399+
type WebAssemblyBootResourceType = "assembly" | "pdb" | "dotnetjs" | "dotnetwasm" | "globalization" | "manifest" | "configuration";
255400

256401
interface IDisposable {
257402
dispose(): void;
@@ -277,56 +422,14 @@ interface IMemoryView extends IDisposable {
277422
get byteLength(): number;
278423
}
279424

280-
declare global {
281-
function getDotnetRuntime(runtimeId: number): RuntimeAPI | undefined;
282-
}
283-
284-
declare const dotnet: ModuleAPI["dotnet"];
285-
declare const exit: ModuleAPI["exit"];
425+
declare function mono_exit(exit_code: number, reason?: any): void;
286426

287-
interface BootJsonData {
288-
readonly entryAssembly: string;
289-
readonly resources: ResourceGroups;
290-
/** Gets a value that determines if this boot config was produced from a non-published build (i.e. dotnet build or dotnet run) */
291-
readonly debugBuild: boolean;
292-
readonly linkerEnabled: boolean;
293-
readonly cacheBootResources: boolean;
294-
readonly config: string[];
295-
readonly icuDataMode: ICUDataMode;
296-
readonly startupMemoryCache: boolean | undefined;
297-
readonly runtimeOptions: string[] | undefined;
298-
299-
// These properties are tacked on, and not found in the boot.json file
300-
modifiableAssemblies: string | null;
301-
aspnetCoreBrowserTools: string | null;
302-
}
427+
declare const dotnet: DotnetHostBuilder;
428+
declare const exit: typeof mono_exit;
303429

304-
type BootJsonDataExtension = { [extensionName: string]: ResourceList };
305-
306-
interface ResourceGroups {
307-
readonly assembly: ResourceList;
308-
readonly lazyAssembly: ResourceList;
309-
readonly pdb?: ResourceList;
310-
readonly runtime: ResourceList;
311-
readonly satelliteResources?: { [cultureName: string]: ResourceList };
312-
readonly libraryInitializers?: ResourceList,
313-
readonly extensions?: BootJsonDataExtension
314-
readonly runtimeAssets: ExtendedResourceList;
315-
}
316-
317-
type ResourceList = { [name: string]: string };
318-
type ExtendedResourceList = {
319-
[name: string]: {
320-
hash: string,
321-
behavior: string
322-
}
323-
};
324-
325-
declare const enum ICUDataMode {
326-
Sharded,
327-
All,
328-
Invariant,
329-
Custom
430+
declare global {
431+
function getDotnetRuntime(runtimeId: number): RuntimeAPI | undefined;
330432
}
433+
declare const createDotnetRuntime: CreateDotnetRuntimeType;
331434

332-
export { AssetEntry, CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, IMemoryView, ModuleAPI, MonoConfig, ResourceRequest, RuntimeAPI, BootJsonData, ICUDataMode, createDotnetRuntime as default, dotnet, exit };
435+
export { AssetEntry, CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, GlobalizationMode, IMemoryView, ModuleAPI, MonoConfig, ResourceRequest, RuntimeAPI, createDotnetRuntime as default, dotnet, exit };

0 commit comments

Comments
 (0)