Embedding all of deno in Rust?
So, I know that you can use deno_core to roll a javascript runtime in Rust and use that, and use it with your own api and whatnot.
But what if you want to be able to leverage already created deno libraries, but in your Rust program? Think of it as a sort of plugin system in your Rust app that can leverage all of deno's api (including packages)
11 Replies
I guess, after a bit of reading, what I'm asking for is how to embed the deno runtime (not just the deno_core) into a Rust app, such that regular deno packages should work (if this is even possible)
the deno cli itself does not have a rust crate, and a bunch of functionality (including typescript typechecking, and other aspects) would need to be implemented manually ontop of the
deno_runtime
crateSo far I've partially gotten a runtime working (along with a custom module loader which transpiles as well, and can do network requests; one library example I tested worked verbatim)
But when it comes to async await it crashes with
Any ideas how I could solve this?
hmm not sure. cc @mmastrac since
deno_unsync
error@Cherry 🍒 make sure that you are using tokio's
current_thread
executor -- Deno only supports that particular threading model because of threading limitations in deno_core/v8.
Can you share your tokio runtime builder expression?My code is pretty much verbatim from the examples (other than a custom module loader). I'll try out the current thread executor then!
Interesting. We should add tokio::main to those examples -- you'll need to use this:
That should Just Work
Hey, nice. It worked as you said, thanks a lot!
@Cherry 🍒 this is something I tried a while ago but ended up stopping short.
if you have a repo with an example setup I'd love to check it out!
You can follow the official deno example, but with current_thread runtime
https://github.com/denoland/deno/blob/main/runtime/examples/extension_with_ops/main.rs
It'll work out of the box
Oh cool! Thanks!