Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create js bindings #124

Open
1a1a11a opened this issue Feb 6, 2025 · 3 comments
Open

create js bindings #124

1a1a11a opened this issue Feb 6, 2025 · 3 comments
Labels
help wanted Extra attention is needed new function

Comments

@1a1a11a
Copy link
Owner

1a1a11a commented Feb 6, 2025

No description provided.

@1a1a11a 1a1a11a added help wanted Extra attention is needed new function labels Feb 23, 2025
@realtmxi
Copy link

realtmxi commented Feb 26, 2025

Hi, before implementing this, I have a few questions to clarify.
Is the goal to maintain the existing C/C++ code and create bindings for JavaScript, rather than re-implementing the algorithms in a new language?

I don’t have prior experience with programming language bindings, but I am familiar with C/C++, Python, and JavaScript.

In my previous experience, Python libraries like NumPy provide precompiled wheels, allowing users to install them easily via pip install numpy. I was wondering if the equivalent approach for JavaScript would be distributing libCacheSim as an npm package, where users could simply run npm install libcachesim. Is npm the binding solution you're looking for?

Since I'm more familiar with Python, I’d like to use issue #123 (#123) as an example. In Python, common binding methods include:

  • Pybind11
  • CFFI
  • CPython

These allow us to write a Python extension, build precompiled wheels for different platforms, and publish the package on PyPI so users can pip install libcachesim without compiling from source.

For JavaScript, I’m less certain about the best approach. I did some research but I’m not fully confident if I’m on the right track. Some potential options I found include:

  • SWIG with Node-API
  • Node FFI (ffi-napi)
  • WebAssembly

Could you clarify which approach you prefer, or if there's another recommended method for JS bindings? Thanks!

@1a1a11a
Copy link
Owner Author

1a1a11a commented Feb 26, 2025

Thank you for looking into it! I agree that distributing pre-compiled library is a good idea.

I am also less familiar with Javascript. Here are some thoughts after searching around.

  1. Node.js Native Addons is a good solution because it provides native integration with node js.
  2. SWIG is also a good option because we can generate multiple bindings.
  3. Emscripten (WASM) is better if we want to run it in the browser although I do not see an immediate use case. More specifically, it is unlikely we will run large traces in browsers, and we can use exist js library for small trace.
  4. Node FFI is less ideal here due to the amount of work needed, the maintenance overhead, and compatibility issues.

IMHO, Native Addons and SWIG are better options, but I am open to other solutions.

@realtmxi
Copy link

realtmxi commented Mar 3, 2025

After searching around Node.js Native Addons vs SWIG. I'd like to start with Node.js C++Addons.
Since they have native support for js developers, using N-API is stable across NodeJS versions and a much easier learning curve compared with SWIG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new function
Projects
None yet
Development

No branches or pull requests

2 participants