Skip to content

Commit 98869f5

Browse files
kraenhansenclaude
andcommitted
Phase 2: bump Node-API to v10, drop engine/runtime split
All Node-API symbols are now sourced from Hermes' hermesNapi, so the old engine (js_native_api → libhermes.so) / runtime (node_api → libnode-api-host.so) distinction and the hand-maintained IMPLEMENTED_RUNTIME_FUNCTIONS allow-list are obsolete. - weak-node-api: getNodeApiFunctions defaults to v10 and no longer computes the dead `kind`/`libraryPath` fields; CMake compiles the generated weak_node_api.cpp at NAPI_VERSION=10 (145 → 155 symbols, adding the v9/v10 node_api_* surface). - generate-injector.mts: bind every symbol (no filter) and emit `#include <Versions.hpp>` first so the injector TU also compiles at v10. - Versions.hpp: guarded bump to NAPI_VERSION 10. Regenerated (gitignored) WeakNodeApiInjector.cpp + weak-node-api/generated now expose all 155 symbols incl. TSFN and napi_make_callback. Verified: build, prettier, lint, workspace unit tests, and the weak-node-api native build + ctest all pass. iOS e2e pending (rides the cold re-vendor). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 54b46c9 commit 98869f5

4 files changed

Lines changed: 18 additions & 37 deletions

File tree

packages/host/cpp/Versions.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#pragma once
22

3-
#define NAPI_VERSION 8
3+
// Must be defined before any <node_api.h> include so the header exposes the
4+
// full v10 surface (js_native_api.h otherwise defaults this to 8).
5+
#ifndef NAPI_VERSION
6+
#define NAPI_VERSION 10
7+
#endif

packages/host/scripts/generate-injector.mts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,22 @@ import { type FunctionDecl, getNodeApiFunctions } from "weak-node-api";
66

77
export const CPP_SOURCE_PATH = path.join(import.meta.dirname, "../cpp");
88

9-
// TODO: Remove when all runtime Node API functions are implemented
10-
const IMPLEMENTED_RUNTIME_FUNCTIONS = [
11-
"napi_create_buffer",
12-
"napi_create_buffer_copy",
13-
"napi_is_buffer",
14-
"napi_get_buffer_info",
15-
"napi_create_external_buffer",
16-
"napi_create_async_work",
17-
"napi_queue_async_work",
18-
"napi_delete_async_work",
19-
"napi_cancel_async_work",
20-
"napi_fatal_error",
21-
"napi_get_node_version",
22-
"napi_get_version",
23-
];
24-
259
/**
2610
* Generates source code which injects the Node API functions from the host.
2711
*/
2812
export function generateSource(functions: FunctionDecl[]) {
2913
return `
3014
// This file is generated by react-native-node-api
15+
// Versions.hpp must come first so <node_api.h> exposes the full v10 surface.
16+
#include <Versions.hpp>
17+
3118
#include <dlfcn.h>
3219
#include <weak_node_api.hpp>
3320
3421
#include <Logger.hpp>
3522
#include <RuntimeNodeApi.hpp>
3623
#include <RuntimeNodeApiAsync.hpp>
37-
24+
3825
#if defined(__APPLE__)
3926
#define WEAK_NODE_API_LIBRARY_NAME "@rpath/weak-node-api.framework/weak-node-api"
4027
#elif defined(__ANDROID__)
@@ -61,13 +48,7 @@ export function generateSource(functions: FunctionDecl[]) {
6148
6249
log_debug("Injecting NodeApiHost");
6350
inject_weak_node_api_host(NodeApiHost {
64-
${functions
65-
.filter(
66-
({ kind, name }) =>
67-
kind === "engine" || IMPLEMENTED_RUNTIME_FUNCTIONS.includes(name),
68-
)
69-
.flatMap(({ name }) => `.${name} = ${name},`)
70-
.join("\n")}
51+
${functions.flatMap(({ name }) => `.${name} = ${name},`).join("\n")}
7152
});
7253
}
7354
} // namespace callstack::react_native_node_api

packages/weak-node-api/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ endif()
5656

5757
# C++20 is needed to use designated initializers
5858
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
59-
target_compile_definitions(${PROJECT_NAME} PRIVATE NAPI_VERSION=8)
59+
target_compile_definitions(${PROJECT_NAME} PRIVATE NAPI_VERSION=10)
6060

6161
target_compile_options(${PROJECT_NAME} PRIVATE
6262
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>

packages/weak-node-api/src/node-api-functions.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,25 @@ export function getNodeApiHeaderAST(version: NodeApiVersion) {
7878

7979
export type FunctionDecl = {
8080
name: string;
81-
kind: "engine" | "runtime";
8281
returnType: string;
8382
noReturn: boolean;
8483
argumentTypes: string[];
85-
libraryPath: string;
8684
fallbackReturnStatement: string;
8785
};
8886

89-
export function getNodeApiFunctions(version: NodeApiVersion = "v8") {
87+
export function getNodeApiFunctions(version: NodeApiVersion = "v10") {
9088
const root = getNodeApiHeaderAST(version);
9189
assert.equal(root.kind, "TranslationUnitDecl");
9290
assert(Array.isArray(root.inner));
9391
const foundSymbols = new Set();
9492

93+
// Both interfaces are now sourced from the same host (hermesNapi provides
94+
// every symbol), so there is no engine/runtime distinction to preserve.
9595
const symbolsPerInterface = nodeApiHeaders.symbols[version];
96-
const engineSymbols = new Set(symbolsPerInterface.js_native_api_symbols);
97-
const runtimeSymbols = new Set(symbolsPerInterface.node_api_symbols);
98-
const allSymbols = new Set([...engineSymbols, ...runtimeSymbols]);
96+
const allSymbols = new Set([
97+
...symbolsPerInterface.js_native_api_symbols,
98+
...symbolsPerInterface.node_api_symbols,
99+
]);
99100

100101
const nodeApiFunctions: FunctionDecl[] = [];
101102

@@ -131,14 +132,9 @@ export function getNodeApiFunctions(version: NodeApiVersion = "v8") {
131132
name,
132133
returnType,
133134
noReturn: node.type.qualType.includes("__attribute__((noreturn))"),
134-
kind: engineSymbols.has(name) ? "engine" : "runtime",
135135
argumentTypes: argumentTypes
136136
.split(",")
137137
.map((arg) => arg.trim().replace("_Bool", "bool")),
138-
// Defer to the right library
139-
libraryPath: engineSymbols.has(name)
140-
? "libhermes.so"
141-
: "libnode-api-host.so",
142138
fallbackReturnStatement:
143139
returnType === "void"
144140
? "abort();"

0 commit comments

Comments
 (0)