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] Node Support #54554

Closed
wants to merge 28 commits into from
Closed

[WASM] Node Support #54554

wants to merge 28 commits into from

Conversation

Daniel-Genkin
Copy link
Contributor

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

WORK IN PROGRESS

This PR adds the missing pieces for NodeJS support to MONO WASM!

How does it work

The main differences between this and running the console sample regularly for v8 is that dotnet.js is modularized so we use require to load it. We now also have a package.json and package-lock.json files as well as the node_modules folder. Besides that, most changes to the code were related to various NodeJS related nuances such as the scoping of this but are ignored by the browser.

How to run locally

  1. Build the artifacts folder to use the Node -os flag (ex: ./build.cmd mono -os Node -c Debug) (make sure to have libs already built as browser. For some reason it fails when building libs for node but I am working on it). Note however that although this will build, since the libs are built for another target, they won't be reachable while running. However, builds will still succeed so generated code inspection is possible.
  2. publish the console sample with /p:TargetOS=Node (ex: ./dotnet.cmd publish /p:TargetArchitecture=wasm /p:TargetOS=Node Wasm.Console.Sample.csproj -c Debug).
  3. Cd into the \src\mono\sample\wasm\console\bin\{CONFIGURATION}\AppBundle folder and run ./run-node.cmd or run-node.sh depending on your OS. You should see the regular console sample output. Note that you can also use the NPM test task to achieve the same result (i.e. npm test).

See the open question sections for a link to branch that successfully builds and runs in node.

TODO LIST

  • Get it to run manually by building and publishing the console sample app for the browser build target and then manually executing the output via node --trace-warnings runtime.js --run Wasm.Console.Sample.dll
  • Add a new Build target to automatically copy over the package.json file and run npm install on it
  • Make MSBuild automatically change the emcc Modularize flag based on build target
  • Add a new MSBuild TargetOS for NodeJS
  • Fix the new Node Build target in MSBuild so that it builds libs properly
  • Merge previous PRs ([WASM] Converted mono-config.js to mono-config.json #53606, [WASM] Enabled strict mode on all JS files #54011, [WASM] Normalize runtime-test.js #54281) to cleanup the code
  • Other miscellaneous clean up work
  • Double check with someone more experienced with MSBuild if there is a better way to add the Node target. It behaves the same as Browser with the only exception being modularizing the emcc output.
  • Add a CI build for Node (Should this be a separate PR?)

Open Questions

  • Should this be a new TargetOS (specified by -os Node) or should it be an additional flag/parameter that is passed while building for Browser (i.e. /p:ForNode=True)? To see a working copy of the flag option see my other branch wasm-node-via-extra-flag

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@Daniel-Genkin Daniel-Genkin changed the title Wasm node [WASM] Node Support Jun 23, 2021
@Daniel-Genkin
Copy link
Contributor Author

Closing PR as we decided to use the flag instead of $(TargetOS).
See that PR here: #54640

@ghost ghost locked as resolved and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant