Skip to content

Commit e94c72e

Browse files
committed
Sync napi shared-lib change with PR #183 (gate behind JSR_NAPI_SHARED option)
1 parent d225e74 commit e94c72e

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Core/Node-API/CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,20 @@ if(NAPI_BUILD_ABI)
155155
message(STATUS "Selected ${NAPI_JAVASCRIPT_ENGINE}")
156156
endif()
157157

158-
# On Android the Node-API conformance addons are dlopen'd as standalone SHARED .node modules (matching
159-
# nodejs/node-api-cts's add_node_api_cts_addon model). For an addon's napi_* imports to bind at load,
160-
# napi must be a shared library that both the host and the addons depend on via a real DT_NEEDED
161-
# (libnapi.so) -- bionic will not surface a statically-linked host's napi to a dlopen'd module. There
162-
# is a single napi instance (one libnapi.so) shared by the host and every addon. Elsewhere (the
163-
# child-process desktop runner) napi stays a static library.
158+
# On Android, native addons are dlopen'd as standalone .node modules and resolve their napi_* imports
159+
# from a shared napi at load time -- bionic will not surface a statically-linked host's napi to a
160+
# dlopen'd module, so the host and every addon must share a single libnapi.so. Default napi to a
161+
# shared library on Android so that model works out of the box; an integrator who wants a static napi
162+
# (e.g. for size/packaging) can override with -DJSR_NAPI_SHARED=OFF. The option defaults OFF on other
163+
# platforms, where napi keeps following the project's default library type (i.e. honors
164+
# BUILD_SHARED_LIBS).
165+
set(JSR_NAPI_SHARED_DEFAULT OFF)
164166
if(ANDROID)
167+
set(JSR_NAPI_SHARED_DEFAULT ON)
168+
endif()
169+
option(JSR_NAPI_SHARED "Build napi as a shared library (libnapi.so)" ${JSR_NAPI_SHARED_DEFAULT})
170+
171+
if(JSR_NAPI_SHARED)
165172
add_library(napi SHARED ${SOURCES})
166173
else()
167174
add_library(napi ${SOURCES})

0 commit comments

Comments
 (0)