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] Converted mono-config.js to mono-config.json #53606

Merged
merged 19 commits into from
Jun 21, 2021

Conversation

Daniel-Genkin
Copy link
Contributor

@Daniel-Genkin Daniel-Genkin commented Jun 2, 2021

This PR renames the mono-config.js file to mono-config.json, updates the contents accordingly and moves it's loading from the DOM to JS.

Why is this needed?
This change is step 0 before adding NodeJS support to the wasm runtime. As NodeJS doesn't have a DOM, we need to load the config file from JS. Moreover, by moving the variable declaration out of the file, we can reduce ambiguity as to what the config variable is. This will also have the added benefit of being able to rename the variable if needed.

What's changed

  • mono-config.js has been renamed to mono-config.json and the config variable declaration has been removed.
  • there is now a new function MONO.mono_wasm_load_config(configFilePath) which loads the config file via promises.
  • the wasm and debugger samples have been updated to work with this change.

How it works
The user adds the snippet listed below to their Module object. Then emsdk will call it after loading the runtime but before the runtime is started. Then, when the user wants to start the runtime, they can pass the Module.config object to the MONO.mono_load_runtime_and_bcl_args function. This approach also allows the user to make runtime modifications to the config prior to passing it to the runtime by editing the Module.config object.

    config: null,
    preInit: async function() {
        Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
    },

Also, note that I am new to this project (I am an intern) so please let me know if there is anything else that should be improved including coding style, better techniques for loading the files and/or anything else.

@ghost
Copy link

ghost commented Jun 2, 2021

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

Issue Details

WORK IN PROGRESS

This PR renames the mono-config.js file to mono-config.json, updates the contents accordingly and moves it's loading from the DOM to JS.

Why is this needed?
This change is step 0 before adding NodeJS support to the wasm runtime. As NodeJS doesn't have a DOM, we need to load the config file from JS. Moreover, by moving the variable declaration out of the file, we can reduce ambiguity as to what the config variable is. This will also have the added benefit of being able to rename the variable if needed.

What's changed

  • mono-config.js has been renamed to mono-config.json and the config variable declaration has been removed.
  • there is now a new js_support.js file that is copied directly (via emssdk pre-js flag) to dotnet.js. This file loads the config file and then fires a callback (onConfigLoaded(config)) once it is loaded with the contents of the config file in the config parameter.
  • the wasm and debugger samples have been updated to work with this change.

How it works
Since I use the --pre-js flag, the load_config() is the first function to execute in dotnet.js (even before the emsdk runtime is initialized). Then the emsdk runtime initializes as normal. Lastly the mono runtime is initialized (load config -> runtime initialized -> load mono runtime with args). This solves the previous open question and a few of the comments. Plus it involves minimal changes to other projects that use wasm as they simply just need to add the snippet below to their existing code to make it work.

    config: null,
    onConfigLoaded: function (config) {
        if (!config || config.error){
            console.log("An error occured while loading the config file");
            return;
        }
        Module.config = config;
    },

Also, note that I am very new to this project (I am an intern) so please let me know if there is anything else that should be improved including coding style, better techniques for loading the files and/or anything else.

Author: Daniel-Genkin
Assignees: -
Labels:

area-VM-meta-mono

Milestone: -

@Daniel-Genkin Daniel-Genkin changed the title converted mono-config.js to mono-config.json [WASM] Converted mono-config.js to mono-config.json Jun 2, 2021
@marek-safar marek-safar added arch-wasm WebAssembly architecture area-Build-mono and removed area-VM-meta-mono labels Jun 2, 2021
@ghost
Copy link

ghost commented Jun 2, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR renames the mono-config.js file to mono-config.json, updates the contents accordingly and moves it's loading from the DOM to JS.

Why is this needed?
This change is step 0 before adding NodeJS support to the wasm runtime. As NodeJS doesn't have a DOM, we need to load the config file from JS. Moreover, by moving the variable declaration out of the file, we can reduce ambiguity as to what the config variable is. This will also have the added benefit of being able to rename the variable if needed.

What's changed

  • mono-config.js has been renamed to mono-config.json and the config variable declaration has been removed.
  • there is now a new js_support.js file that is copied directly (via emssdk pre-js flag) to dotnet.js. This file loads the config file and then fires a callback (onConfigLoaded(config)) once it is loaded with the contents of the config file in the config parameter.
  • the wasm and debugger samples have been updated to work with this change.

How it works
Since I use the --pre-js flag, the load_config() is the first function to execute in dotnet.js (even before the emsdk runtime is initialized). Then the emsdk runtime initializes as normal. Lastly the mono runtime is initialized (load config -> runtime initialized -> load mono runtime with args). This solves the previous open question and a few of the comments. Plus it involves minimal changes to other projects that use wasm as they simply just need to add the snippet below to their existing code to make it work.

    config: null,
    onConfigLoaded: function (config) {
        if (!config || config.error){
            console.log("An error occured while loading the config file");
            return;
        }
        Module.config = config;
    },

Also, note that I am very new to this project (I am an intern) so please let me know if there is anything else that should be improved including coding style, better techniques for loading the files and/or anything else.

Author: Daniel-Genkin
Assignees: -
Labels:

arch-wasm, area-Build-mono

Milestone: -

src/mono/sample/mbr/browser/runtime.js Outdated Show resolved Hide resolved
src/mono/sample/wasm/browser-bench/runtime.js Show resolved Hide resolved
src/mono/wasm/runtime/js_support.js Outdated Show resolved Hide resolved
@Daniel-Genkin
Copy link
Contributor Author

As an update, turns out that that js_support.js file is actually unnecessary. So I moved the load config function (now known as mono_wasm_load_config) to library_mono.js. The reasoning is that it is loading the mono config file, so it should probably be in the mono namespace. This also, removes the redundant js_support.js file and keeps everything more consistent. Plus it helps with trimming tests by removing the need for the pre-js all together

@kg
Copy link
Member

kg commented Jun 14, 2021

As an update, turns out that that js_support.js file is actually unnecessary. So I moved the load config function (now known as mono_wasm_load_config) to library_mono.js. The reasoning is that it is loading the mono config file, so it should probably be in the mono namespace. This also, removes the redundant js_support.js file and keeps everything more consistent. Plus it helps with trimming tests by removing the need for the pre-js all together

Make sure it isn't used by blazor

@Daniel-Genkin
Copy link
Contributor Author

@kg that shouldn't be an issue because this is a file that I added in a previous commit for this PR :)

@kg
Copy link
Member

kg commented Jun 14, 2021

@kg that shouldn't be an issue because this is a file that I added in a previous commit for this PR :)

Ah, confused it with dotnet_support :)

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small nits but looking good!

src/mono/sample/mbr/browser/runtime.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime/library_mono.js Outdated Show resolved Hide resolved
@thaystg thaystg merged commit a3f0e2b into dotnet:main Jun 21, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants