Skip to content

EASY: Export public hermes_napi entry points with NAPI macros - #2044

Closed
tmikov wants to merge 1 commit into
meta:static_hfrom
tmikov:export-D107462337
Closed

tmikov wants to merge 1 commit into
meta:static_hfrom
tmikov:export-D107462337

Conversation

@tmikov

@tmikov tmikov commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary:
Decorate the public hermes_napi entry points (hermes_napi_create_env,
hermes_napi_get_last_registered_module, hermes_napi_load_module,
hermes_run_script, hermes_run_bytecode) with NAPI_EXTERN and NAPI_CDECL,
matching the canonical declaration style used throughout js_native_api.h.

NAPI_EXTERN expands to visibility("default") on non-Windows, so without
it these symbols could be hidden when the library is built with
-fvisibility=hidden, leaving the entry points unexported. NAPI_CDECL
fixes the calling convention on Windows. The macros are already in scope
via the existing node_api.h include, and the attribute carries to the
definitions in hermes_napi.cpp since the header is transitively included
there.

Differential Revision: D107462337

Summary:
Decorate the public hermes_napi entry points (hermes_napi_create_env,
hermes_napi_get_last_registered_module, hermes_napi_load_module,
hermes_run_script, hermes_run_bytecode) with NAPI_EXTERN and NAPI_CDECL,
matching the canonical declaration style used throughout js_native_api.h.

NAPI_EXTERN expands to visibility("default") on non-Windows, so without
it these symbols could be hidden when the library is built with
-fvisibility=hidden, leaving the entry points unexported. NAPI_CDECL
fixes the calling convention on Windows. The macros are already in scope
via the existing node_api.h include, and the attribute carries to the
definitions in hermes_napi.cpp since the header is transitively included
there.

Differential Revision: D107462337
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 4, 2026
@meta-codesync

meta-codesync Bot commented Jun 4, 2026

Copy link
Copy Markdown

@tmikov has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107462337.

@meta-codesync

meta-codesync Bot commented Jun 4, 2026

Copy link
Copy Markdown

This pull request has been merged in da69c31.

meta-codesync Bot pushed a commit that referenced this pull request Jul 16, 2026
Summary:
The public `hermes_napi_*` / `hermes_run_*` entry points in `API/napi/hermes_napi.h` are decorated with `NAPI_EXTERN NAPI_CDECL` (added in #2044), where `NAPI_EXTERN` expands to `__attribute__((visibility("default")))` on non-Windows. However, unlike the sibling headers `js_native_api.h` and `node_api.h`, `hermes_napi.h` does not wrap its declarations in `extern "C"`, so these functions get C++ linkage.

With C++ linkage the symbols are name-mangled and are not exported from a library built with `-fvisibility=hidden` (the root `CMakeLists.txt` appends this globally). Consumers linking the resulting shared library therefore hit undefined symbols such as `hermes_napi_create_env`, while the `extern "C"` symbols from `js_native_api.h` / `node_api.h` export as expected.

This wraps the declarations in `EXTERN_C_START` / `EXTERN_C_END` — the same macros used by the sibling headers, already in scope via the `node_api.h` include — so `NAPI_EXTERN`'s `visibility("default")` takes effect and the entry points are exported.

These are a C API (a Hermes extension of the C Node-API), so `extern "C"` is the correct linkage on its own merits. This is the natural follow-up to #2044, which intended to export these symbols.

Note: this changes the exported symbols from mangled C++ names to their C names (e.g. `hermes_napi_create_env`). The `= nullptr` default argument on `hermes_napi_create_env` is a call-site feature and is compatible with `extern "C"` linkage.

Pull Request resolved: #2106

Test Plan: - [ ] Build with default flags and confirm `hermes_napi_create_env` and the other entry points appear in the exported symbol table of the built shared library.

Reviewed By: tmikov

Differential Revision: D112358086

Pulled By: avp

fbshipit-source-id: 690f5e1e3ea2b4a59c478b8393f82ab138f348d9
@tmikov
tmikov deleted the export-D107462337 branch September 7, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant