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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<PlatformManifestFileEntry Include="binding_support.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet_support.js" IsNative="true" />
<PlatformManifestFileEntry Include="library_mono.js" IsNative="true" />
<PlatformManifestFileEntry Include="js_support.js" IsNative="false" />
<PlatformManifestFileEntry Include="pal_random.js" IsNative="true" />
<PlatformManifestFileEntry Include="corebindings.c" IsNative="true" />
<PlatformManifestFileEntry Include="driver.c" IsNative="true" />
Expand Down
1 change: 0 additions & 1 deletion src/mono/sample/mbr/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ <h3 id="header">Wasm Browser Sample</h3>
},
};
</script>
<script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>

<script defer src="dotnet.js"></script>
Expand Down
27 changes: 23 additions & 4 deletions src/mono/sample/mbr/browser/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@
// The .NET Foundation licenses this file to you under the MIT license.

var Module = {
config: null,

// Called once the config file is loaded. The contents of the config file
// are passed as a JS object within the config parameter
onConfigLoaded: function (config) {
if (!config || config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config = config;
Daniel-Genkin marked this conversation as resolved.
Show resolved Hide resolved
},

// Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
config.loaded_cb = function () {
if (!Module.config || Module.config.error){
Daniel-Genkin marked this conversation as resolved.
Show resolved Hide resolved
console.log("An error occured while loading the config file");
return;
}

Module.config.loaded_cb = function () {
App.init ();
};
config.environment_variables = {
Module.config.environment_variables = {
"DOTNET_MODIFIABLE_ASSEMBLIES": "debug"
};
config.fetch_file_cb = function (asset) {
Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}

MONO.mono_load_runtime_and_bcl_args (config);
MONO.mono_load_runtime_and_bcl_args (Module.config);
},
};
1 change: 0 additions & 1 deletion src/mono/sample/wasm/browser-bench/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ <h3 id="header">Wasm Browser Sample - Simple Benchmark</h3>
}
};
</script>
<script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>

<script defer src="dotnet.js"></script>
Expand Down
34 changes: 30 additions & 4 deletions src/mono/sample/wasm/browser-bench/runtime.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

var Module = {
config: null,
Daniel-Genkin marked this conversation as resolved.
Show resolved Hide resolved

// Called once the config file is loaded. The contents of the config file
// are passed as a JS object within the config parameter
onConfigLoaded: function (config) {
if (!config || config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config = config;
},

// Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
config.loaded_cb = function () {
if (!Module.config || Module.config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
test_exit(1);
throw (error);
}
};
config.fetch_file_cb = function (asset) {
Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}

if (Module.config.enable_profiler)
{
Module.config.aot_profiler_options = {
write_at:"Sample.Test::StopProfile",
send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
}
}

try
{
MONO.mono_load_runtime_and_bcl_args (config);
MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);
Expand Down
59 changes: 0 additions & 59 deletions src/mono/sample/wasm/browser-profile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,8 @@
<body>
<h3 id="header">Wasm Browser Sample</h3>
Result from Sample.Test.TestMeaning: <span id="out"></span>
<script type='text/javascript'>
var is_testing = false;
var onLoad = function() {
var url = new URL(decodeURI(window.location));
let args = url.searchParams.getAll('arg');
is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined);
};

var test_exit = function(exit_code)
{
if (!is_testing) {
console.log(`test_exit: ${exit_code}`);
return;
}

/* Set result in a tests_done element, to be read by xharness */
var tests_done_elem = document.createElement("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString();
document.body.appendChild(tests_done_elem);

console.log(`WASM EXIT ${exit_code}`);
};

var App = {
init: function () {
var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []);
document.getElementById("out").innerHTML = ret;
console.log ("ready");

if (is_testing)
{
console.debug(`ret: ${ret}`);
let exit_code = ret == 42 ? 0 : 1;
test_exit(exit_code);
}

if (config.enable_profiler) {
BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:StopProfile", []);
saveProfile();
}
},
};

function saveProfile() {
var a = document.createElement('a');
var blob = new Blob([Module.aot_profile_data]);
a.href = URL.createObjectURL(blob);
a.download = "data.aotprofile";
// Append anchor to body.
document.body.appendChild(a);
a.click();

// Remove anchor from body
document.body.removeChild(a);
}

</script>
<script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>

<script defer src="dotnet.js"></script>

</body>
Expand Down
93 changes: 83 additions & 10 deletions src/mono/sample/wasm/browser-profile/runtime.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,106 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
var Module = {
is_testing: false,
config: null,

// Called once the config file is loaded. The contents of the config file
// are passed as a JS object within the config parameter
onConfigLoaded: function (config) {
if (!config || config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config = config;
},

// Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
config.loaded_cb = function () {
if (!Module.config || Module.config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config.loaded_cb = function () {
try {
App.init ();
Module.init();
} catch (error) {
test_exit(1);
Module.test_exit(1);
throw (error);
}
};
config.fetch_file_cb = function (asset) {
Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}

if (config.enable_profiler)
if (Module.config.enable_profiler)
{
config.aot_profiler_options = {
Module.config.aot_profiler_options = {
write_at:"Sample.Test::StopProfile",
send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
}
}

try
{
MONO.mono_load_runtime_and_bcl_args (config);
MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
Module.test_exit(1);
throw(error);
}
},

init: function () {
console.log("not ready yet")
var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []);
document.getElementById("out").innerHTML = ret;
console.log ("ready");

if (Module.is_testing)
{
console.debug(`ret: ${ret}`);
let exit_code = ret == 42 ? 0 : 1;
Module.test_exit(exit_code);
}

if (Module.config.enable_profiler) {
BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:StopProfile", []);
Module.saveProfile();
}
},

onLoad: function() {
var url = new URL(decodeURI(window.location));
let args = url.searchParams.getAll('arg');
Module.is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined);
},

test_exit: function(exit_code) {
if (!Module.is_testing) {
console.log(`test_exit: ${exit_code}`);
return;
}

/* Set result in a tests_done element, to be read by xharness */
var tests_done_elem = document.createElement("label");
tests_done_elem.id = "tests_done";
tests_done_elem.innerHTML = exit_code.toString();
document.body.appendChild(tests_done_elem);

console.log(`WASM EXIT ${exit_code}`);
},

saveProfile: function () {
var a = document.createElement('a');
var blob = new Blob([Module.aot_profile_data]);
a.href = URL.createObjectURL(blob);
a.download = "data.aotprofile";
// Append anchor to body.
document.body.appendChild(a);
a.click();

// Remove anchor from body
document.body.removeChild(a);
}
};
};
1 change: 0 additions & 1 deletion src/mono/sample/wasm/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ <h3 id="header">Wasm Browser Sample</h3>
},
};
</script>
<script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>

<script defer src="dotnet.js"></script>
Expand Down
26 changes: 23 additions & 3 deletions src/mono/sample/wasm/browser/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,42 @@
// The .NET Foundation licenses this file to you under the MIT license.

var Module = {

config: null,

// Called once the config file is loaded. The contents of the config file
// are passed as a JS object within the config parameter
onConfigLoaded: function (config) {
if (!config || config.error){
console.log("An error occured while loading the config file");
return;
}

Module.config = config;
},

// Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
config.loaded_cb = function () {
if (!Module.config || Module.config.error){
console.log("No config found");
return;
}

Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
test_exit(1);
throw (error);
}
};
config.fetch_file_cb = function (asset) {
Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}

try
{
MONO.mono_load_runtime_and_bcl_args (config);
MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);
Expand Down
6 changes: 3 additions & 3 deletions src/mono/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ $(NATIVE_BIN_DIR)/include/wasm:
$(BUILDS_OBJ_DIR):
mkdir -p $$@

$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR)
$(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3)
$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js runtime/js_support.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR)
$(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js --pre-js runtime/js_support.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3)

$(BUILDS_OBJ_DIR)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR)
if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi
Expand Down Expand Up @@ -132,7 +132,7 @@ clean:
icu-files: $(wildcard $(ICU_LIBDIR)/*.dat) $(ICU_LIBDIR)/libicuuc.a $(ICU_LIBDIR)/libicui18n.a | $(NATIVE_BIN_DIR)
cp $^ $(NATIVE_BIN_DIR)

source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src
source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js runtime/js_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src
cp $^ $(NATIVE_BIN_DIR)/src

header-files: runtime/pinvoke.h | $(NATIVE_BIN_DIR)/include/wasm
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
- @(WasmFilesToIncludeInFileSystem) - Files to include in the vfs
- @(WasmNativeAsset) - Native files to be added to `NativeAssets` in the bundle.

- @(WasmExtraConfig) - json elements to add to `mono-config.js`
- @(WasmExtraConfig) - json elements to add to `mono-config.json`
Eg. <WasmExtraConfig Include="enable_profiler" Value="true" />

- Value attribute can have a number, bool, quoted string, or json string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
return App.int_add (a, b);
}
</script>
<script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime-debugger.js"></script>
<script type="text/javascript" src="other.js"></script>
<script async type="text/javascript" src="dotnet.js"></script>
Expand Down
Loading