Bromeon / js-sandbox

Securely embed JavaScript code into a Rust application
zlib License
267 stars 17 forks source link

Request to discuss your sandbox via talk or messaging? #32

Closed anonhostpi closed 1 month ago

anonhostpi commented 1 month ago

I am a novice Rust developer, and I am looking to discuss some things about this library.

@Bromeon May I take some of your time to talk with you? Do you have some time? If so, what is the best platform to reach you?

Discord: anonhostpi

Bromeon commented 1 month ago

Hi, what is the discussion about? In general I prefer using GitHub (even for help requests), as that can benefit other people in the future, as well :slightly_smiling_face: Also note that lately, I haven't been able to devote as much time to js-sandbox as I would have liked.

anonhostpi commented 1 month ago

I totally understand, I have the same feeling towards my projects.

I have some experience with Rust, but mostly in reviewing Rust source code from the perspective of a non-rust developer (reading over the source code for several Linux utilities for a few years as a sys eng/net eng)

I want to try to do the same thing Python.NET has done for C# and Python, but for Deno instead of Python. I know that in theory all I need to do is write Rust FFIs to expose deno_core to C. After that, all I need to do is write a similar set of C# bindings.

I'm comfortable with writing C# bindings, but Rust FFIs is a new area for me.

I imagine that the process for writing Rust FFIs (for an existing library - deno_core or this one) wouldn't very different than writing the C# bindings themselves, but I do think I would need guidance.

anonhostpi commented 1 month ago

The original idea was discussed here for Microsoft.ClearScript, which is the current solution for implementing a JS engine in C#:

I wanted to explore the idea of integrating deno_core and deno's other libraries so that node-like APIs could also be used instead of just V8's

anonhostpi commented 1 month ago

I figured since you have experience with deno_core as a third-party, you would be the best person to ask

Bromeon commented 1 month ago

There seems to be ffi_api, but it looks like it's mostly for the other way (calling native libraries from JavaScript).

Without having attempted anything of the sort, I can imagine there are multiple ways to communicate from your C# host application with the Deno runtime:

  1. Going through FFI: C# -> C -> Rust
  2. Invoking the Deno executable as a new process (limited to the commands the CLI exposes)
  3. Opening a TCP/Websocket/... connection inside a Deno script and connecting to it from C#.
    • also requires loading the Deno runtime first
  4. HTTP/REST API in Deno, if you mostly need request-response.

I'm not sure how concretely you would implement such steps, but I hope this can serve as a starting point.

Since you mentioned Discord, Deno also has a server: https://discord.gg/deno I'm sure there have been people attempting similar tasks, so maybe you can also ask there? They might know better than me what the best approach could look like. Hope that helps! :slightly_smiling_face:

anonhostpi commented 1 month ago

I would like to take the same approach that Python.NET has, which would be the FFI/Binding path.

I know that I am taking up your free time.

Is this the most I can ask from you?

Bromeon commented 1 month ago

What do you mean? I can gladly answer some questions, but I can't guide you through setting up the project, you'll have to do (and learn) that yourself :wink:

anonhostpi commented 1 month ago

What do you mean?

Well, I don't want to be overbearing as the guy that's new to Rust with too much ambition.

This would be my first set of Rust FFIs and my first time working with deno_core.

I can gladly answer some questions, but I can't guide you through setting up the project, you'll have to do (and learn) that yourself

Thank you. My next question was going to be, "how would you approach writing FFIs for deno_core or where would you start, if you were in my shoes?"

Bromeon commented 1 month ago

This is something I don't know, since I haven't done it. I've only used the deno_core library as a dependency.

Hence my advice:

Since you mentioned Discord, Deno also has a server: https://discord.gg/deno I'm sure there have been people attempting similar tasks, so maybe you can also ask there? They might know better than me what the best approach could look like. Hope that helps! 🙂

For a more general approach to FFI, also check out https://doc.rust-lang.org/nomicon/ffi.html and the bindgen crate.

anonhostpi commented 1 month ago

Thank you! Best help so far!

anonhostpi commented 1 month ago

I write weekly updates about my progress on this project of mine on Reddit. Can I mention you in my next post?

Bromeon commented 1 month ago

Sure! :slightly_smiling_face: