Repository navigation
Conversation
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
|
@tmikov has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107462337. |
|
This pull request has been merged in da69c31. |
This was referenced Jul 13, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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