## Wrapping C++ and Python libraries for JavaScript ### The guerilla-slides-jsnation-2026
JavaScript has become the new universal language - and it happened almost by accident * because of all the R&D that went into highly efficient interpreters * because it allows to share backend and frontend code
JavaScript is notoriously difficult to interoperate with other languages. So, for the last two decades, people have been trying to rewrite all existing software in JavaScript - there was simply no other way around it. ## But is this actually feasible?
Today, one can even find a ready-to-use fully functional PNG decoder and encoder as `npm` package - entirely in JavaScript - compatible with both the browser and Node.js! However in the C++ world we have ImageMagick - 30 years of experience in implementing state of the art image manipulation algorithms.
WASM was supposed to bridge this gap between existing C/C++ software and the new software world centered around Web technologies where JavaScript was the new machine language. 10 years after its introduction, it remains a niche technology.
Everyone hates WASM: * Developers find it very cumbersome to use * Project managers see the technical risks * Product owners fear the compatibility issues All of them feel that WASM is still not ready.
Yet, in 2026, WASM is definitely mature enough for high-volume production use. It's adoption is hampered by a myriad of practical issues. This is what I call WASM's last mile.
## The Holy Grail of JavaScript/C++ interoperability What if you could simply do: ```shell git clone https://github.com/ImageMagick/ImageMagick abracadabra ImageMagick ``` then ```js import { Magick } from '@abracadabra/ImageMagick'; ``` And get it to work both in Node.js and in the browser!
Alas, this problem is still not solved in the general case when it involves a manual memory management language such as C or C++ and a garbage-collected one such as JavaScript. It is even surprising how little research work has been in this field - despite the obvious need for it.
The traditional solution for automatically generating wrappers for a high-level language by directly compiling the C/C++ headers is # SWIG It has been around for more than two decades and it is very widely used in the Python and Java world. Now, it has been enhanced with very good JavaScript support - including a WASM target.
The other solution which is also gaining lots of traction in the Python world is # pybind11 which builds upon the ground-breaking work in the `boost` C++ library. It is less versatile, but it is far easier to learn and use. Today we also have `nobind17` which does the same for Node.js.
What about Python? Python is one of the most used high level languages and has seen a tremendous amount of high quality libraries over the last few decades. Python is much closer to JavaScript and experience has shown that direct completely automatic and transparent interoperability is totally possible.
`pymport` does not require any additional work: ``` npm install pymport npx pympip3 install numpy ``` then ```js const { pymport, proxify } = require('pymport'); const np = proxify(pymport('numpy')); const a = np.arange(15).reshape(3, 5); const b = np.ones([2, 3], { dtype: np.int16 }); ```
I invite you to check four of my projects: * `GDAL`, my first project, as a co-author, was completely hand-written bindings - it costed more than 1 man-year * `ImageMagick`, the first SWIG JSE project, took about 1 man-month, 400k lines of C++ code generated from 800 lines of SWIG JSE code * `ffmpeg`, the first `nobind17` project - about 2 man-weeks to get it to mostly working status * `PROJ`, the second SWIG JSE project - about 2 man-weeks The cost savings are tremendous!
* The bindings support both synchronous and asynchronous calls - both in Node.js and in the browser *(async in the browser requires COOP/COEP)* * `import`ing is completely automatic - just as if this was JavaScript - the bundler picks up either the browser WASM version or the Node.js native version * The TypeScript types are autogenerated * The C++ STL is replaced by methods that have native JavaScript feel
Interfacing the two languages is not enough! End-users expect `npm` packages - which must be so seamless, that the developer does not need to know about the C++ *time to ditch `node-gyp`* ## Enter the `hadron` build system
# `hadron` * `meson`-based build system which is compatible with CMake and autotools * `xpm`-orchestrator for seamless integration with `conan` and a built-in C++ compiler in an `npm` package ImageMagick comes prebuilt with more than 20 libraries - on Linux, macOS and Windows, and WASM - and it can rebuild itself upon installation, pulling the libraries from `conan` and using its own bundled C++ compiler!
This is the last mile for WASM! Now you can simply use ``` npm install magickwand.js ``` and then use the C++ software as you would be using any other JavaScript library - as native code when running on the backend or as WASM when running in the browser through a web bundler!
How about doing this the other way around? Transparent interaction with JavaScript from C++? ```cpp try { Napi::Platform platform; Napi::PlatformEnv env(platform); Napi::Function require = env.Global().Get("require").As
(); Napi::Object axios = require({Napi::String::New(env, "axios")}).ToObject(); Napi::Promise r = axios.Get("get").As
() .MakeCallback(env.Global(), {Napi::String::New(env, "https://www.github.com")}) .As
(); } catch (const Napi::Error &e) { fprintf(stderr, "Caught a JS exception: %s\n", e.what()); return -1; } ```
This was one of the most requested Node API features - ability to `require` and `import` `npm` modules from C++. I created `libnode` in 2023 as Google Summer of Code project - right before the start of the open hostilities between me and Google. Alas, the PR is currently frozen as I was blocked from accessing the Node.js repositories in September 2023 after refusing to stop talking about the French police involvement in my affair. It does not work beyond Node 18.x.
The project is currently available as an Ubuntu package but has not been updated since Ubuntu 22.04. It works reasonably well and it is used by at least one other opensource project. It is targeted mostly at server-side C++ applications which must support user JavaScript plugins. It features automatic `Promise` resolution from C++ and supports loading and calling both synchronous and asynchronous JavaScript functions from CJS and ES6 modules.
### Who am I I am unemployed and homeless software engineer living on the street on social welfare and working full-time on open source in my van using solar panels. I am here to both promote my open-source software - which most of the companies try to ignore for obvious reasons - and to raise awareness of my affair.
### The affair in a nutshell * A mentally-disturbed employer tried to intervene in my sex life believing that he was going to make me work for cheap * After it didn't really work out, he got the French police involved with a series of false rape charges * After this didn't work either, he got my next employer involved trying to at least embarrass me to stop talking about the affair with various horrible sexual games
* After this didn't work out, he tried convincing me that I suffered from a psychosis * It didn't work out, so he simply reached an agreement with my lawyers, police and the judges to stop any criminal proceedings to buy more time * Then he tried extorting me to shut up - involving GAFAM companies as well as many large open-source projects * Finally, he got my evicted from my home - by now all French government institutions have been involved and everything seems to be possible
### My goal Since I have lost so much, it is unconceivable that I will ever accept any form of settlement - or that I will simply back off. By now the whole affair has a political dimension to it, and I want to use my remaining life to raise awareness of the privacy abuses in Big Tech and fight for new regulations to curb them. **If it is possible to get GAFAM to cooperate in a criminal extortion over a sexual affair, is there anything that is not?**
## The biggest threat of AI is not people losing their jobs, AI still cannot do this ## The biggest threat of AI is authoritarian government and new feudal Middle Ages because AI can totally do this
* SWIG JSE - https://github.com/mmomtchev/swig * `nobind17`- https://www.npmjs.com/package/nobind17 * `hadron` - https://github.com/mmomtchev/hadron * `magickwand.js` - https://www.npmjs.com/package/magickwand.js * `gdal-async` - https://www.npmjs.com/package/gdal-async * `node-ffmpeg` - https://www.npmjs.com/package/@mmomtchev/ffmpeg * `proj.js` - https://www.npmjs.com/package/proj.js * `libnode` - https://github.com/mmomtchev/libnode
### Short wrappers are more agile