-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[dart2wasm] Support non-JS wasm runtimes #53884
Comments
Can existing JS solutions for those environments help here? That is, Javy and spidermonkey.wasm and similar projects compile a JS VM into wasm, so it can run in a non-JS wasm environment. If that JS happens to use wasm, it seems like that wasm could be bundled alongside the compiled JS VM, and "just work" with some glue (e.g. spidermonkey already has wasm support; it would just need to be "pointed" to the bundled wasm rather than to interpret it). The wasm would run at full speed, and the JS is apparently fast enough for those environments, so this seems viable. Perhaps someone has already done it? If that existed, then dart2wasm and other toolchains would not need to do any special work to port to non-JS environments (no more than people wanting to run JS there, which is considered a solved problem). edit: stack traces would not fully work, but all the other bullet points above should be fine (math, regexes, etc., are all in the compiled JS VM). |
Yeah I contemplated something like the spidermonkey.wasm might be an interesting idea. Off-hand, it might be even more effective for WasmGC modules with a thin JS support runtime attached, rather than a large blob of JS. I don't know what kind of optimizations are done for the JS VM snapshot build, but a "whole world analysis" on the JS support runtime could probably lead to pruning a lot of code out of the JS VM. |
|
Stack traces could be a good candidate for (5), since it will be difficult to do without support from the engine. |
@yjbanov does this remark mean that Dart will support WASI as a compilation target? |
This would be amazing to support better serverless, and general flexible compute, using Dart. Being able to easily deploy dart applications that are a collection of WASM modules would be revolutionary. Dart is a great language for glueing together libraries quickly, and leveraging existing libraries across languages (esp. rust) that can be compiled to WASM would expand the ecosystem so tremendously. While this is already possible with https://pub.dev/packages/wasm_run, it would be great to further the interoperability and deployment process. This would be especially useful when trying to deploy cross platform applications that currently use FFI and native compiled libraries for each supported platform. In the highest performance applications, FFI and native code may still be desirable, but for a vast majority of applications, the ease of quickly composing applications and innovating has huge value. Advantages
Implementation:
-- Regardless of approach taken, facilitating the deployment of applications that are collections of Wasm modules seems like the natural evolution of docker containerization, with even greater platform flexibility, and a higher degree of composability into ever larger applications or pipelines (eg. langchains, llms, sandboxed user code, etc) |
I saw some mention of SpiderMonkey from @yjbanov and others. I was wondering if this offshoot helps move things any closer as a possibility at all.
|
is there a way to use dart2JS to compile a non-web target? |
Yes 💯 @iapicca I have just run into an almost identical use case myself. For my product, I need to compile Dart to JS to run in a embedded JS engine, initially I'm targeting Duktape. I was actually trying to use the DDC for this but the removal of the ability to use it directly via the dart cli command in favour of webserve is very annoying and the best I've found so far is to use --no-release with the build command. I'm very open to even some pointers from the Dart team about where to go look for underlying Dart compiler APIs thar could used as ideally I want to be able to just compile sets of stand alone functions from one or several Dart libraries (ie. files) and not use a main() entry point at all. |
Yes, Dart supports running the JS generated from Dart in JavaScript engines outside browsers. We use this for testing, some teams use it to run Dart applications in node.js too. Some details: compiler preambles For that purpose we require a "preamble" file that is customized for the engine that you will be using. We already provide preambles in the Dart SDK for two common engines js-shell and d8. The community currently maintains a preamble for node.js in examples Our team wrote the generator of |
Thanks so much for all that information @sigmundch ! 👍🏻 to say that it is super useful is an understatement! I didn't know about |
We need to run Flutter/Dart code directly on WASI, this is the future. It has broad application scenarios in the blockchain field. We use wasmer as the smart contract engine of the blockchain. Currently, the assets it manages are billions of dollars. Once Flutter supports compilation to WASI, we can develop a unified front-end on any device, and the underlying layer is your assets protected by the blockchain. Can we implement this feature as soon as possible? |
We eventually may want dart2wasm to actually work in non-JavaScript environments (wasmtime, wasmer, etc). @askeksa had mentioned a list of a few things that would definitly need to be addressed in order to remove the dependency on a JS/browser environment:
The text was updated successfully, but these errors were encountered: