We'll be going over a few things in this talk. Of course, what are Node.js native add-ons? We're going to run into a couple of use cases. One, an ABI stable API for Hermes that is already in use. And two, a proof of concept of cross ecosystem library sharing. We'll wrap it all up afterwards.
So, what are Node.js native add-ons? Well, Node.js has its own native modules called native add-ons. For example, for Node.js to interact with SQLite3, there's an NPM package for that. And just as React native modules are written with JSI, Node.js native add-ons are written with NodeAPI, which is similarly engine agnostic. Now, to put that visually, it's like this. NodeAPI occupies the same position between native code and JavaScript engines as JSI does.
So, why should we care? We've already got JSI. What more do we need? Well, first of all, NodeAPI is incredibly popular. So, if you measure it just by the downloads per week of Node add-on API, which is commonly imported by Node.js native add-ons based on C++, there's 20 million downloads per week. Very popular. It's community driven. It's a de facto industry standard, and it's available for various languages. So, instead of writing in C++, you can write in Swift, as, you know, we can do with Expo modules and Nitro modules, but also Rust, C Sharp, Nim, Zig, Go. And it can express pretty much anything ECMAScript can. You want proxies, you can have it. You can do class extensions, static methods, all sorts of things, very idiomatically, rather than having to do lots of prototype tricks, for example. There's first class interrupt between native and JavaScript context. So, you've got lifetimes, you've got async functions, you've got threading, that sort of thing. And it's ABI stable, which we'll be getting into later.
So, is this all just theorycrafting? It's one thing to say Node API would be great, it's got all these characteristics, but what's the story about bringing it into React Native? Well, the truth is, it's already in use in React Native Windows. So, I'd like to tell a story about an ABI stable API for Hermes. But in order to explain that, first we need to be clear of what an ABI is. So, here we have a lovely image of some binary, which expresses part of this story. So, an application binary interface is the compiled version of an API. So, while you when you're dealing with APIs are dealing with human concepts, like classes and declarations and functions and that sort of thing, an ABI is a lower level. It's like it says inside this big old binary blob, where do I find the stuff that I need and what does it mean? So, it defines the set of functions and their signatures, the data structures, for example layouts of structs and enums, function calling conventions, error handling, and memory management.
Comments