Node: Node Embedder API for Rust FFI

Created on 4 Nov 2020  路  2Comments  路  Source: nodejs/node

I would like to use the Rust's FFI to "talk" to Node.js's embedder api.
Currently, Rust's FFI only support foreign C functions and I understand that Node.js's embedder api is targeted to C++.
Is there a way facilitate this from Node.js? Or am I bound to wait until Rust supports C++ FFI?

Most helpful comment

You could write a small compat api:

extern "C" int init_node(int argc, char** argv) {
  std::vector<std::string> args(argv, argv + argc);
  std::vector<std::string> exec_args;
  std::vector<std::string> errors;
  return node::InitializeNodeWithArgs(&args, &exec_args, &errors);
}

extern "C" void* create_platform(...) {
  ...
}

...

All 2 comments

You could write a small compat api:

extern "C" int init_node(int argc, char** argv) {
  std::vector<std::string> args(argv, argv + argc);
  std::vector<std::string> exec_args;
  std::vector<std::string> errors;
  return node::InitializeNodeWithArgs(&args, &exec_args, &errors);
}

extern "C" void* create_platform(...) {
  ...
}

...

Thank you @devsnek for your reply.
I used your method and was able to expose some functions to Rust.
I will love to see the entire Node.js API exposed as C out of the box. And would also be nice to have libnode.so distributed with each Node.js release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akdor1154 picture akdor1154  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

sandeepks1 picture sandeepks1  路  3Comments

addaleax picture addaleax  路  3Comments