Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.5k
[Wasm] JS modularization#61313
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
Uh oh!
There was an error while loading. Please reload this page.
[Wasm] JS modularization #61313
Changes from all commits
291c70a5c3a3138399876e25050d457456c5a3f6b1171ec60864073e593831d6514dd84c4c5023c38597da4391242634da0678e48d3b168850ac595c506fd2ec1c39d802a45915b416f324efda61dc62ff3edf8b0807f1b911bb5b072568dc3df6fd49fcd8400d784dff39ea58ddc710File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,7 @@ var Module = { | ||
| onConfigLoaded: function () { | ||
| MONO.config.environment_variables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug"; | ||
| }, | ||
| onDotNetReady: function () { | ||
| onDotnetReady: function () { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the change? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my quick survey told me Dotnet is more common, but I don't have strong opinion. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will eventually rename it in next PR | ||
| App.init(); | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| namespace Sample | ||
| { | ||
| public class Test | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine ("Hello, World!"); | ||
| } | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static int TestMeaning() | ||
| { | ||
| return 42; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Configuration>Debug</Configuration> | ||
| <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir> | ||
| <WasmMainJSPath>main.js</WasmMainJSPath> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>embedded</DebugType> | ||
| <WasmDebugLevel>1</WasmDebugLevel> | ||
| <WasmEnableES6>true</WasmEnableES6> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <WasmExtraFilesToDeploy Include="index.html" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <_SampleProject>Wasm.Browser.ES6.Sample.csproj</_SampleProject> | ||
| </PropertyGroup> | ||
| <Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" /> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!DOCTYPE html> | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
| <!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
| <html> | ||
| <head> | ||
| <title>Sample ES6</title> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <link rel="modulepreload" href="main.js" /> | ||
| <link rel="modulepreload" href="dotnet.js" /> | ||
| </head> | ||
| <body> | ||
| <h3 id="header">Wasm Browser ES6 Sample</h3> | ||
| Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span> | ||
| <script type='module' src="./main.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import createDotnetRuntime from './dotnet.js' | ||
| const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime((api) => ({ | ||
| disableDotnet6Compatibility: true, | ||
| configSrc: "./mono-config.json", | ||
| onAbort: () => { | ||
| wasm_exit(1); | ||
| }, | ||
| })); | ||
| function wasm_exit(exit_code) { | ||
| console.log(`WASM EXIT ${exit_code}`); | ||
| } | ||
| const testMeaning = BINDING.bind_static_method("[Wasm.Browser.ES6.Sample] Sample.Test:TestMeaning"); | ||
| const ret = testMeaning(); | ||
| document.getElementById("out").innerHTML = `${ret} as computed on dotnet ver ${RuntimeBuildInfo.ProductVersion}`; | ||
| console.debug(`ret: ${ret}`); | ||
| let exit_code = ret == 42 ? 0 : 1; | ||
| wasm_exit(exit_code); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| namespace Sample | ||
| { | ||
| public class Test | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine ("Hello, World!"); | ||
| } | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static int TestMeaning() | ||
| { | ||
| return 42; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
pavelsavara marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <PropertyGroup> | ||
| <Configuration>Debug</Configuration> | ||
| <WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir> | ||
| <WasmMainJSPath>main.js</WasmMainJSPath> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>embedded</DebugType> | ||
| <WasmDebugLevel>1</WasmDebugLevel> | ||
| <WasmBuildNative>true</WasmBuildNative> | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need relinking? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not, right now. This was just easy way how to test re-link of CJS. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove it for this PR, then. And reverse the property setting here, and in the es6 sample, when es6 becomes default. | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <WasmExtraFilesToDeploy Include="index.html" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <_SampleProject>Wasm.Browser.LegacySample.csproj</_SampleProject> | ||
| </PropertyGroup> | ||
| <Target Name="RunSample" DependsOnTargets="RunSampleWithBrowser" /> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <!DOCTYPE html> | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
| <!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
| <html> | ||
| <head> | ||
| <title>Legacy global module sample</title> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| </head> | ||
| <body> | ||
| <h3 id="header">Wasm Browser Legacy Sample</h3> | ||
| Result from Sample.Test.TestMeaning: <span id="out"></span> | ||
| <script type='text/javascript'> | ||
| function set_exit_code(exit_code, reason) { | ||
| /* Set result in a tests_done element, to be read by xharness */ | ||
| const 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}`); | ||
| }; | ||
| const App = { | ||
| init: function () { | ||
| const testMeaning = BINDING.bind_static_method("[Wasm.Browser.LegacySample] Sample.Test:TestMeaning"); | ||
| const ret = testMeaning(); | ||
| document.getElementById("out").innerHTML = ret; | ||
| console.debug(`ret: ${ret}`); | ||
| let exit_code = ret == 42 ? 0 : 1; | ||
| set_exit_code(exit_code); | ||
| }, | ||
| }; | ||
| </script> | ||
| <script type="text/javascript" src="main.js"></script> | ||
| <script defer src="dotnet.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| "use strict"; | ||
| var Module = { | ||
| configSrc: "./mono-config.json", | ||
| onDotnetReady: () => { | ||
| try { | ||
| App.init(); | ||
| } catch (error) { | ||
| set_exit_code(1, error); | ||
| throw (error); | ||
| } | ||
| }, | ||
| onAbort: (error) => { | ||
| set_exit_code(1, error); | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,7 +12,7 @@ var Module = { | ||
| } | ||
| } | ||
| }, | ||
| onDotNetReady: () => { | ||
| onDotnetReady: () => { | ||
| try { | ||
| Module.init(); | ||
| } catch (error) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -93,7 +93,7 @@ $(NATIVE_BIN_DIR)/include/wasm: | ||
| $(BUILDS_OBJ_DIR): | ||
| mkdir -p $$@ | ||
| $(NATIVE_BIN_DIR)/dotnet.js: runtime/driver.c runtime/pinvoke.c runtime/pinvoke.h runtime/corebindings.c $(NATIVE_BIN_DIR)/src/runtime.iffe.js runtime/library-dotnet.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(MONO_LIBS) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) | ||
| $(NATIVE_BIN_DIR)/dotnet.js: runtime/driver.c runtime/pinvoke.c runtime/pinvoke.h runtime/corebindings.c $(NATIVE_BIN_DIR)/src/cjs/runtime.cjs.iffe.js runtime/cjs/dotnet.cjs.lib.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.lib.js $(MONO_LIBS) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependencies list should be moved to a variable, since this is getting pretty long. Doesn't have to be in this PR though. | ||
| $(DOTNET) build $(CURDIR)/wasm.proj $(_MSBUILD_WASM_BUILD_ARGS) /t:BuildWasmRuntimes $(MSBUILD_ARGS) | ||
| $(EMCC_DEFAULT_RSP): $(CURDIR)/wasm.proj | $(NATIVE_BIN_DIR)/src Makefile | ||
| @@ -113,7 +113,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/library-dotnet.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src | ||
| source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/cjs/dotnet.cjs.lib.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.lib.js | $(NATIVE_BIN_DIR)/src | ||
| cp $^ $(NATIVE_BIN_DIR)/src | ||
| header-files: runtime/pinvoke.h | $(NATIVE_BIN_DIR)/include/wasm | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.