Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wasm] JS modularization #61313

Merged
merged 32 commits into from
Dec 2, 2021
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
fix exports, fix early malloc
  • Loading branch information
pavelsavara committed Dec 1, 2021
commit 8ddc7102a142d16d1afd8fc28ad34f160394df1b
25 changes: 8 additions & 17 deletions src/mono/wasm/runtime/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
mono_wasm_set_main_args,
mono_wasm_pre_init,
mono_wasm_runtime_is_initialized,
finalize_startup
mono_wasm_on_runtime_initialized
} from "./startup";
import { mono_set_timeout, schedule_background_exec } from "./scheduling";
import { mono_wasm_load_icu_data, mono_wasm_get_icudt_name } from "./icu";
Expand Down Expand Up @@ -169,11 +169,6 @@ function initializeImportsAndExports(
} else if (typeof module.preRun === "function") {
module.preRun = [module.preRun];
}
if (!module.postRun) {
module.postRun = [];
} else if (typeof module.postRun === "function") {
module.postRun = [module.postRun];
}

if (!module.print) {
module.print = console.log;
Expand Down Expand Up @@ -261,21 +256,17 @@ function initializeImportsAndExports(

// if onRuntimeInitialized is set it's probably Blazor, we let them to do their own init sequence
if (!module.onRuntimeInitialized) {
// this is registration of the runtime initialisation, it's async and uses fetch
module.preRun.push(async () => {
// execution order == [1] ==
module.addRunDependency("mono_load_runtime_and_bcl_args");
await mono_load_runtime_and_bcl_args(module.config);
module.removeRunDependency("mono_load_runtime_and_bcl_args");
});
// this is synchronous method, which needs that emscripten is already initialized
// execution order == [2] ==
module.onRuntimeInitialized = () => finalize_startup(module.config);
// note this would keep running in async-parallel with emscripten's `run()` and `postRun()`
// because it's loading files asynchronously and the emscripten is not awaiting onRuntimeInitialized
// execution order == [1] ==
module.onRuntimeInitialized = () => mono_wasm_on_runtime_initialized();

module.ready = module.ready.then(async () => {
// mono_wasm_runtime_is_initialized is set when finalize_startup is done
await mono_wasm_runtime_is_initialized;
// execution order == [3] ==
// TODO we could take over Module.postRun and call it from here if necessary

// execution order == [2] ==
return exportedAPI;
});
}
Expand Down
15 changes: 12 additions & 3 deletions src/mono/wasm/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export async function mono_wasm_pre_init(): Promise<void> {

}

export async function mono_wasm_on_runtime_initialized(): Promise<void> {
if (!Module.config || Module.config.isError) {
return;
}
await mono_load_runtime_and_bcl_args(Module.config);
finalize_startup(Module.config);
}


// Set environment variable NAME to VALUE
// Should be called before mono_load_runtime_and_bcl () in most cases
export function mono_wasm_setenv(name: string, value: string): void {
Expand Down Expand Up @@ -154,7 +163,7 @@ function _apply_configuration_from_args(config: MonoConfig) {
mono_wasm_init_coverage_profiler(config.coverage_profiler_options);
}

export function finalize_startup(config: MonoConfig | MonoConfigError | undefined): void {
function finalize_startup(config: MonoConfig | MonoConfigError | undefined): void {
try {
if (!config || config.isError) {
return;
Expand Down Expand Up @@ -319,7 +328,7 @@ export async function mono_load_runtime_and_bcl_args(config: MonoConfig | MonoCo
}

const load_asset = async (config: MonoConfig, asset: AllAssetEntryTypes): Promise<void> => {
Module.addRunDependency(asset.name);
// TODO Module.addRunDependency(asset.name);

const sourcesList = asset.load_remote ? config.remote_sources! : [""];
let error = undefined;
Expand Down Expand Up @@ -374,7 +383,7 @@ export async function mono_load_runtime_and_bcl_args(config: MonoConfig | MonoCo
if (!isOkToFail)
throw error;
}
Module.removeRunDependency(asset.name);
// TODO Module.removeRunDependency(asset.name);
};
const fetch_promises: Promise<void>[] = [];
// start fetching all assets in parallel
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<_EmccCommonFlags Include="-s ALLOW_MEMORY_GROWTH=1" />
<_EmccCommonFlags Include="-s NO_EXIT_RUNTIME=1" />
<_EmccCommonFlags Include="-s FORCE_FILESYSTEM=1" />
<_EmccCommonFlags Include="-s EXPORTED_RUNTIME_METHODS=&quot;['DOTNET','MONO','BINDING','INTERNAL','FS','print','ccall','cwrap','setValue','getValue','UTF8ToString','UTF8ArrayToString','FS_createPath','FS_createDataFile','removeRunDependency','addRunDependency']&quot;" />
<_EmccCommonFlags Include="-s EXPORTED_RUNTIME_METHODS=&quot;['FS','print','ccall','cwrap','setValue','getValue','UTF8ToString','UTF8ArrayToString','FS_createPath','FS_createDataFile','removeRunDependency','addRunDependency']&quot;" />
<_EmccCommonFlags Include="-s EXPORTED_FUNCTIONS=&quot;['_free','_malloc']&quot;" />
<_EmccCommonFlags Include="--source-map-base http://example.com" />

Expand Down