Skip to content

Spike: move the napi host and addon loading into React Native core #495

Open

Description

@kraenhansen

Prove the RFC in #447: an app with no react-native-node-api native host can load an addon linked against the Hermes stub from #494, with core providing the napi host and addon loading.

Steps

  • On a branch of a react/react-native fork, move the napi host and addon loading into core. Android first.
  • Build an app from that source, without our native host, with an addon linked against the stub.
  • Check that the addon loads, its calls land in Hermes, and the relevant tests pass.
  • Publish the branch as a draft PR on the fork, so the RFC has a concrete diff to point at.

What this should settle

  • What has to move. Something must load the addon as well as host it. Today that path is require("./addon.node") → Babel transform → requireNodeAddon(). Core needs one primitive for this, while the Babel plugin, link and the naming scheme may be able to stay here.
  • Whether hermes_napi.h can stay internal. It declares embedder API such as hermes_napi_create_env and hermes_run_script, so it should be a private dependency of core's napi host, not a public header. Addons use node-api-headers.

What the RFC asks for

  1. Hermes builds used by React Native export Node-API (Remove Hermes vendoring once React Native ships a Hermes with Node-API #412). static_h already has API/napi, but it isn't on main or in any release. This spike builds on our vendored Hermes in the meantime.
  2. The library exporting it keeps a stable name, or React Native declares a supported one. 0.82 renamed libhermes.so to libhermesvm.so, and another rename would break published addons.

node-api-headers defines the interface, so a mismatch with it is a Hermes bug and needs no separate ask.

Depends on the first step of #494.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Host 🏡Our `react-native-node-api-modules` packageLinking 🔗Discovering and copying prebuilds from packages into the hostenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions