|
1 | | -# Set per-platform defaults if unspecified. |
2 | | -if(WIN32) |
3 | | - set(NAPI_JAVASCRIPT_ENGINE "Chakra" CACHE STRING "JavaScript engine for Node-API") |
4 | | -elseif(APPLE) |
5 | | - set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for Node-API") |
6 | | -elseif(ANDROID) |
7 | | - set(NAPI_JAVASCRIPT_ENGINE "V8" CACHE STRING "JavaScript engine for Node-API") |
8 | | -elseif(UNIX) |
9 | | - set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for Node-API") |
| 1 | +# Set per-platform defaults only when the caller did not select an engine. |
| 2 | +if(NOT NAPI_JAVASCRIPT_ENGINE) |
| 3 | + if(WIN32) |
| 4 | + set(NAPI_JAVASCRIPT_ENGINE "Chakra" CACHE STRING "JavaScript engine for Node-API") |
| 5 | + elseif(APPLE) |
| 6 | + set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for Node-API") |
| 7 | + elseif(ANDROID) |
| 8 | + set(NAPI_JAVASCRIPT_ENGINE "V8" CACHE STRING "JavaScript engine for Node-API") |
| 9 | + elseif(UNIX) |
| 10 | + set(NAPI_JAVASCRIPT_ENGINE "JavaScriptCore" CACHE STRING "JavaScript engine for Node-API") |
| 11 | + else() |
| 12 | + message(FATAL_ERROR "Unable to select Node-API JavaScript engine for platform") |
| 13 | + endif() |
| 14 | +endif() |
| 15 | + |
| 16 | +if(UNIX AND NOT APPLE AND NOT ANDROID AND NAPI_JAVASCRIPT_ENGINE STREQUAL "JavaScriptCore") |
10 | 17 | find_library(JAVASCRIPTCORE_LIBRARY javascriptcoregtk-4.1) |
11 | 18 | if(NOT JAVASCRIPTCORE_LIBRARY) |
12 | 19 | message(FATAL_ERROR "JavaScriptCore library not found. Please install libwebkit2gtk-4.1-dev") |
13 | 20 | endif() |
14 | | -else() |
15 | | - message(FATAL_ERROR "Unable to select Node-API JavaScript engine for platform") |
16 | 21 | endif() |
17 | 22 |
|
18 | 23 | set(SOURCES |
@@ -97,6 +102,13 @@ if(NAPI_BUILD_ABI) |
97 | 102 | else() |
98 | 103 | message(FATAL_ERROR "Unsupported JavaScript engine: ${NAPI_JAVASCRIPT_ENGINE}") |
99 | 104 | endif() |
| 105 | + |
| 106 | + # The maintained Apple and WebKitGTK headers/runtimes expose the |
| 107 | + # BigInt typed-array enum values. The frozen jsc-android package does |
| 108 | + # not, so keep its capability-gated build on the older enum surface. |
| 109 | + if(NOT ANDROID) |
| 110 | + set(JSR_JSC_HAS_BIGINT_TYPED_ARRAYS ON) |
| 111 | + endif() |
100 | 112 | elseif(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8") |
101 | 113 | set(SOURCES ${SOURCES} |
102 | 114 | "Source/env_v8.cc" |
@@ -190,9 +202,9 @@ Make sure Hermes was fetched at the top-level CMakeLists.txt and NAPI_JAVASCRIPT |
190 | 202 | # (bigint::exponentiate, regex::parseRegex, hbc::compileEvalModule, |
191 | 203 | # llvh::raw_ostream, platform_unicode::normalize, ...) which |
192 | 204 | # `hermesvm_a` bundles together for us. |
193 | | - set(LINK_LIBRARIES ${LINK_LIBRARIES} |
194 | | - PRIVATE hermesNapi |
195 | | - PRIVATE hermesvm_a) |
| 205 | + set(NAPI_HERMES_LINK_LIBRARIES |
| 206 | + hermesNapi |
| 207 | + hermesvm_a) |
196 | 208 |
|
197 | 209 | # `hermes_napi.h` lives in Hermes's `API/napi/` source directory and |
198 | 210 | # is NOT installed alongside the other `include/hermes/napi/` |
@@ -286,6 +298,39 @@ endif() |
286 | 298 | target_include_directories(napi ${INCLUDE_DIRECTORIES}) |
287 | 299 | target_link_libraries(napi ${LINK_LIBRARIES}) |
288 | 300 |
|
| 301 | +if(NAPI_JAVASCRIPT_ENGINE STREQUAL "Hermes") |
| 302 | + if(JSR_NAPI_SHARED) |
| 303 | + # hermesNapi is a static archive. When it is folded into libnapi.so, |
| 304 | + # the linker would normally extract only the objects referenced by |
| 305 | + # env_hermes.cc, leaving most exported napi_* entry points out of the |
| 306 | + # shared library. Android addons then fail to resolve even core APIs |
| 307 | + # such as napi_create_arraybuffer and napi_wrap. Include the complete |
| 308 | + # archive so the shared library provides the full Node-API surface. |
| 309 | + if(MSVC) |
| 310 | + target_link_libraries(napi PRIVATE ${NAPI_HERMES_LINK_LIBRARIES}) |
| 311 | + target_link_options(napi PRIVATE "/WHOLEARCHIVE:$<TARGET_FILE:hermesNapi>") |
| 312 | + else() |
| 313 | + target_link_libraries(napi PRIVATE |
| 314 | + "-Wl,--whole-archive" |
| 315 | + hermesNapi |
| 316 | + "-Wl,--no-whole-archive" |
| 317 | + hermesvm_a) |
| 318 | + endif() |
| 319 | + else() |
| 320 | + target_link_libraries(napi PRIVATE ${NAPI_HERMES_LINK_LIBRARIES}) |
| 321 | + endif() |
| 322 | +endif() |
| 323 | + |
| 324 | +if(JSR_JSC_HAS_BIGINT_TYPED_ARRAYS) |
| 325 | + target_compile_definitions(napi PRIVATE JSR_JSC_HAS_BIGINT_TYPED_ARRAYS=1) |
| 326 | +endif() |
| 327 | + |
| 328 | +# Expose the selected engine as a compile definition so engine-agnostic consumers (the node_lite test |
| 329 | +# harness) can branch on engine capability instead of guessing from the platform |
| 330 | +# (__APPLE__ == JSC / __ANDROID__ == V8 breaks Android-JSC, Linux-V8, Windows-Chakra, ...). |
| 331 | +string(TOUPPER "${NAPI_JAVASCRIPT_ENGINE}" NAPI_ENGINE_UPPER) |
| 332 | +target_compile_definitions(napi PUBLIC JSR_NAPI_ENGINE_${NAPI_ENGINE_UPPER}) |
| 333 | + |
289 | 334 | if(NAPI_JAVASCRIPT_ENGINE STREQUAL "Hermes") |
290 | 335 | # Apply Hermes-specific warning suppressions ONLY to env_hermes.cc so |
291 | 336 | # they don't relax the rules for the rest of the napi sources. |
|
0 commit comments