top | item 35816224

Running JavaScript in Rust with Deno: Experimenting with Deno's Rust Crates

136 points| a-poor | 2 years ago |austinpoor.com

19 comments

order

quentinadam|2 years ago

Being able to allow custom behaviour via JS/TS in Rust is definitely something that I wanted to explore too. If you haven’t already you should check out these two articles from the Deno blog website which go a bit further:

https://deno.com/blog/roll-your-own-javascript-runtime

https://deno.com/blog/roll-your-own-javascript-runtime-pt2

smt88|2 years ago

> Being able to allow custom behaviour via JS/TS in Rust

I understanding wanting to call out to Rust from JS/TS, but I don't think I understand wanting the reverse. Isn't a major goal of Rust not to have "custom behavior" that is invisible to the compiler?

JLCarveth|2 years ago

I wasn't aware of a pt2, thanks for the link.

rubenfiszel|2 years ago

> Data pipelines (eg Apache Airflow) where the orchestration is handled by Rust but the high-level business logic is defined using JavaScript

That is ... exactly what windmill is https://github.com/windmill-labs/windmill

The orchestrator is built from scratch in rust using postgresql to store the state. The steps when in typescript are run in deno: https://github.com/windmill-labs/windmill/blob/main/backend/... and the transforms between the steps (piping outputs of any node to the input of any node) are actually javascript expressions run by deno JsRuntimes: https://github.com/windmill-labs/windmill/blob/f3ec9ca09dc37...

Narew|2 years ago

Maybe a naive question but why using Deno instead of v8 directly for javascript interpreter/compiler/runtime, it can also be called from rust.

brabel|2 years ago

> the release build of js-in-rs is 54 MB, grep is 179 KB, and a basic hello world JS application compiled using Deno is 103 MB.

OMG. That's ridiculous.

Write the code in C or Zig, and use Lua for scripting, and you're down to under 1MB for the final binary.