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] updated samples for ES6 and CJS #62292

Merged
merged 7 commits into from
Dec 21, 2021

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Dec 2, 2021

Modularized API and ES6

Reworked samples which demonstrate how to use modularized API and ES6

<PropertyGroup>
  <WasmEnableES6>true</WasmEnableES6>
</PropertyGroup>

To generate ES6 or CommonJS version of dotnet.js

  • for V8 we need few more polyfills and also we need shim to import es6 script
  • for NodeJs we need package.json with "type":"module" to import es6 script with '.js' extension
  • for NodeJs + CommonJS works as is

In-tree relink of ES6 version implemented as MsBuild hack right now and would be fixed as part of #61294

ES6 Samples

Samples demonstrate the new API createDotnetRuntime()

Minimal browser sample

<script type='module' src="./main.mjs"></script>
import createDotnetRuntime from './dotnet.js'
const { MONO } = await createDotnetRuntime();
await MONO.mono_run_main_and_exit("Wasm.Console.V8.CJS.Sample.dll", []);

Still trivial sample

const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime(() => ({
    disableDotnet6Compatibility: true,
    configSrc: "./mono-config.json",
    onAbort: (err) => {
        console.log(`WASM ERROR ${err}`);
    },
}));

const testMeaning = BINDING.bind_static_method("[Wasm.Browser.Sample] Sample.Test:TestMeaning");
const ret = testMeaning();

CommonJS

NodeJS Sample

const createDotnetRuntime = require("./dotnet.js");

async function main() {
    const { MONO } = await createDotnetRuntime();
    const app_args = process.argv.slice(2);
    await MONO.mono_run_main_and_exit("Wasm.Console.CJS.Sample.dll", app_args);
};
main();

Contributes to #47336
Contributes to #41861
Fixes #61083

@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Dec 2, 2021
@pavelsavara pavelsavara added this to the 7.0.0 milestone Dec 2, 2021
@ghost
Copy link

ghost commented Dec 2, 2021

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

Issue Details

work in progress

Author: pavelsavara
Assignees: -
Labels:

arch-wasm

Milestone: 7.0.0

@pavelsavara

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@pavelsavara pavelsavara marked this pull request as ready for review December 18, 2021 09:23
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

Failures are unrelated #62964

@pavelsavara pavelsavara requested review from kg and maraf December 20, 2021 12:11
Copy link
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

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

LGTM

or(
eq(variables['librariesContainsChange'], true),
eq(variables['monoContainsChange'], true),
eq(variables['isFullMatrix'], true))
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we want these conditions anymore?

Copy link
Member Author

@pavelsavara pavelsavara Dec 20, 2021

Choose a reason for hiding this comment

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

In my opinion, there is no other place which would run on NodeJS platform every time. Also this is runtime-manual pipeline. So it's already run with intention of getting more. I'm prepared to change it if it doesn't make sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

We agreed with Radek to put it back and make it consistent with other ones in the same file.
@steveisok eq(variables['isManualOrIsNotPR'], true), is this always true in this file ? Was is the idea behind it ? Or is that just copy&paste like in my case ?

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-manual

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

How to use dotnet.js outside of browser?
5 participants