RFC: Added libdeno package that compiles deno to a static C library #32076
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: This is a rough POC that aims to demonstrate a statically linkable "batteries included" Deno library. The intention is to get the team's thoughts and if it's a direction you like, I'm happy to take on the development
What is this?
This PR adds two crates to the Deno project
libdenolibdeno_bindingslibdeno_sysandlibdeno_embededfor C FFI and high level bindings respectivelyclito re-export initialization circuitsWhy?
Deno is a phenomenal JavaScript runtime and many projects would like to embed Deno functionality into their applications. Use cases for this are;
Admittedly these are mostly my own personal and professional use cases, haha - but the point still stands
Current State
Deno currently exposes several crates, such as
deno_runtimedeno_coreetc. These crates can be composed by the consumer to build a custom runtime for their use case.The challenge is that these crates do not contain the standard library, resolution logic, or Nodejs compatibility.
An approximation of Deno can be built by manually stitching together crates like
deno_nodedeno_webandoxc_resolver, however the maintenance burden is high and there are often versioning clashes (in the case of bundlers, swc indeno_ast).What this aims to solve
The idea with this PR is to offer a "batteries included" static C library that can be embedded within a consumer's binary and called to execute JavaScript as needed.
This is language independent, but with a focus on Rust consumers.
A static C library eliminates clashes of crate dependency versions.
This can also be distributed as a dynamic C library (
.so.dylib.dll)What about customization / ops / snapshots?
Snapshots can be loaded using v8 args.
Deno's ops API might be portable to a C FFI.
Deno supports Node.js's napi - which allows the reuse of the work done on the napi-rs project by a useland library (not self promotion, but I achieved a similar outcome by combining libnode and napi-rs - which I'd love to replace with an embedded Deno library)
Demo
Example consumer:
The idea is to provide the
evalandruncommands via an FFI. The API would be expanded to include permissions and flags. This, combined with native extensions via n-api, solves most use cases.This can later be expanded to allow the direct creation of "Workers" and ideally v8 contexts on a Worker.
Currently the POC only implements
evalwithout flags or permissions, but you get the idea.