Re: Compile with Emscripten to bare V8 (no browser, no Node.js)

20 views
Skip to first unread message

Sam Clegg

unread,
Feb 15, 2023, 4:19:25 PM2/15/23
to emscripte...@googlegroups.com
Are you interested in running the generated wasm and JS code, or just the wasm code (in something like STANDALONE_WASM mode)?  

There are various options, but by far simplest is probably to use d8 (the v8 command line tool normally used for testing).    The easiest way to install it is via jsvu: https://github.com/GoogleChromeLabs/jsvu.  By the way you should be able to run your code under the other shells supported by jsvu too (e.g. jsc).

If you want to take it to the next level you could embed v8 an your own application using the v8 embedding API: https://github.com/GoogleChromeLabs/jsvu

It does beg the question though, why not just use node?

cheers,
sam


On Wed, Feb 15, 2023 at 11:02 AM Tudor Bosman <tud...@gmail.com> wrote:
So perhaps I'm crazy, but I'd like to run C code (compiled to WASM via Emscripten) on bare embedded V8 (without a browser, and without Node).

This would be for (headless) server-side code, so I don't care about graphics / audio / GL / etc, but ideally it would be complete enough to run Pyodide with numpy.

Obviously I'd have to implement some glue API (perhaps emulating part of the browser API would be easier than Node's). Has anyone done anything similar? Is there a minimal set of interfaces documented anywhere?

There is something called headless.js in the emscripten repository which seems to do something in this direction, but I'm not sure how far along it is and what else is needed, or even if I'm on the right path.

Thanks,
-Tudor.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/5b063948-670a-43f3-aed7-cc6ca96834b2n%40googlegroups.com.

Tudor Bosman

unread,
Feb 15, 2023, 5:16:09 PM2/15/23
to emscripten-discuss
Yes, I am interested in running this, we are embedding V8 to run plain JS already. I'm planning to test using d8 and then port the d8 API into our embedder.

We're not using Node because of security isolation -- this is a piece of a larger puzzle that includes running untrusted code.

Thanks,
-Tudor.

Sam Clegg

unread,
Feb 15, 2023, 5:28:55 PM2/15/23
to emscripte...@googlegroups.com
On Wed, Feb 15, 2023 at 2:16 PM Tudor Bosman <tud...@gmail.com> wrote:
Yes, I am interested in running this, we are embedding V8 to run plain JS already. I'm planning to test using d8 and then port the d8 API into our embedder.

If you are already embedding v8 then I don't see that there is anything you should need to do.  WebAssembly should just work in your embedded v8 environment unless you are jumping through hoops to somehow disable it.

 

Alon Zakai

unread,
Feb 15, 2023, 6:24:56 PM2/15/23
to emscripte...@googlegroups.com
To add to that, as I mentioned on Discord, Emscripten output should just work in plain V8, or at least the d8 shell, using the "shell" environment. Maybe one or two minor d8 additions like a way to load a binary file would be needed in plain V8, but that's it.

- Alon



Reply all
Reply to author
Forward
0 new messages