Skip to content

Commit c33f9eb

Browse files
committed
Restack N-API v7 after CTS staging fix
1 parent 0140011 commit c33f9eb

31 files changed

Lines changed: 1265 additions & 150 deletions

‎.github/workflows/build-linux.yml‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,24 @@ jobs:
5454

5555
- name: Run Tests
5656
working-directory: Build/ubuntu/Tests/UnitTests
57-
run: ./UnitTests
58-
env:
59-
TSAN_OPTIONS: ${{ inputs.enable-thread-sanitizer && format('suppressions={0}/.github/tsan_suppressions.txt', github.workspace) || '' }}
57+
run: |
6058
# JSC's concurrent GC on Linux uses SIGUSR1 + sem_wait to suspend mutator
6159
# threads at safepoints. TSan's signal interception delays SIGUSR1 delivery
6260
# indefinitely, deadlocking the Collector Thread's sem_wait. Disabling the
6361
# concurrent collector removes the dedicated Collector Thread, so GC runs
6462
# on the mutator without cross-thread signals. macOS JSC uses Mach
6563
# thread_suspend() and is unaffected.
66-
JSC_useConcurrentGC: ${{ inputs.enable-thread-sanitizer && '0' || '' }}
64+
if [[ "${{ inputs.enable-thread-sanitizer }}" == "true" ]]; then
65+
export TSAN_OPTIONS="suppressions=${{ github.workspace }}/.github/tsan_suppressions.txt"
66+
export JSC_useConcurrentGC=0
67+
fi
68+
./UnitTests
6769
68-
- name: Run Node-API v5 conformance
70+
- name: Run Node-API v7 conformance
6971
working-directory: Build/ubuntu/Tests/NodeApi
70-
run: ./NodeApiTests
71-
env:
72-
TSAN_OPTIONS: ${{ inputs.enable-thread-sanitizer && format('suppressions={0}/.github/tsan_suppressions.txt', github.workspace) || '' }}
73-
JSC_useConcurrentGC: ${{ inputs.enable-thread-sanitizer && '0' || '' }}
72+
run: |
73+
if [[ "${{ inputs.enable-thread-sanitizer }}" == "true" ]]; then
74+
export TSAN_OPTIONS="suppressions=${{ github.workspace }}/.github/tsan_suppressions.txt"
75+
export JSC_useConcurrentGC=0
76+
fi
77+
./NodeApiTests

‎.github/workflows/build-macos.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
env:
5050
TSAN_OPTIONS: ${{ inputs.enable-thread-sanitizer && format('suppressions={0}/.github/tsan_suppressions.txt', github.workspace) || '' }}
5151

52-
- name: Run Node-API v5 conformance
52+
- name: Run Node-API v7 conformance
5353
working-directory: Build/macOS/Tests/NodeApi/RelWithDebInfo
5454
run: ./NodeApiTests
5555
env:

‎CMakeLists.txt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ FetchContent_Declare(quickjs-ng
5555
GIT_REPOSITORY https://github.com/quickjs-ng/quickjs.git
5656
GIT_TAG 93d3f7df465027f487ed37e175a0bc3012fee79e
5757
EXCLUDE_FROM_ALL)
58-
58+
5959
# --------------------------------------------------
6060

6161
FetchContent_MakeAvailable(CMakeExtensions)
@@ -75,6 +75,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
7575
set(CMAKE_CXX_STANDARD 20)
7676
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7777

78+
# A newer MSVC (windows-latest) emits C4875 ("a non-string literal argument to [[gsl::suppress]] is
79+
# deprecated") from the vendored GSL headers, which several targets compile with warnings-as-error.
80+
# Suppress this dependency-side deprecation so the Windows build isn't broken by toolchain drift. Must
81+
# be set before arcana.cpp / Core / Polyfills are added below so they inherit it.
82+
if(MSVC)
83+
add_compile_options(/wd4875)
84+
endif()
85+
7886
# --------------------------------------------------
7987
# Options
8088
# --------------------------------------------------

‎Core/Node-API-JSI/CMakeLists.txt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ if(NOT TARGET jsi)
5757
endif()
5858

5959
target_include_directories(napi
60-
PUBLIC "include")
60+
PUBLIC "include"
61+
# napi.h pulls in the shared <napi/js_native_api_types.h>, which lives in
62+
# Core/Node-API/Include/Shared. That sibling isn't built when the engine is JSI
63+
# (Core/CMakeLists.txt selects Node-API-JSI instead of Node-API), so reference the shared
64+
# headers directly here -- otherwise the JSI napi fails to compile with C1083.
65+
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Node-API/Include/Shared")
6166

6267
target_link_libraries(napi
6368
PUBLIC jsi)

‎Core/Node-API/CMakeLists.txt‎

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
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")
1017
find_library(JAVASCRIPTCORE_LIBRARY javascriptcoregtk-4.1)
1118
if(NOT JAVASCRIPTCORE_LIBRARY)
1219
message(FATAL_ERROR "JavaScriptCore library not found. Please install libwebkit2gtk-4.1-dev")
1320
endif()
14-
else()
15-
message(FATAL_ERROR "Unable to select Node-API JavaScript engine for platform")
1621
endif()
1722

1823
set(SOURCES
@@ -97,6 +102,13 @@ if(NAPI_BUILD_ABI)
97102
else()
98103
message(FATAL_ERROR "Unsupported JavaScript engine: ${NAPI_JAVASCRIPT_ENGINE}")
99104
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()
100112
elseif(NAPI_JAVASCRIPT_ENGINE STREQUAL "V8")
101113
set(SOURCES ${SOURCES}
102114
"Source/env_v8.cc"
@@ -190,9 +202,9 @@ Make sure Hermes was fetched at the top-level CMakeLists.txt and NAPI_JAVASCRIPT
190202
# (bigint::exponentiate, regex::parseRegex, hbc::compileEvalModule,
191203
# llvh::raw_ostream, platform_unicode::normalize, ...) which
192204
# `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)
196208

197209
# `hermes_napi.h` lives in Hermes's `API/napi/` source directory and
198210
# is NOT installed alongside the other `include/hermes/napi/`
@@ -286,6 +298,39 @@ endif()
286298
target_include_directories(napi ${INCLUDE_DIRECTORIES})
287299
target_link_libraries(napi ${LINK_LIBRARIES})
288300

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+
289334
if(NAPI_JAVASCRIPT_ENGINE STREQUAL "Hermes")
290335
# Apply Hermes-specific warning suppressions ONLY to env_hermes.cc so
291336
# they don't relax the rules for the rest of the napi sources.

‎Core/Node-API/Include/Engine/Hermes/napi/env.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ namespace Napi
3030
// top-level dispatch. Equivalent engines (V8, Chakra) auto-drain
3131
// microtasks at scope exit; Hermes requires an explicit drainJobs().
3232
void DrainJobs(Napi::Env env);
33+
34+
// Force a collection for conformance tests that expose global.gc().
35+
void CollectGarbage(Napi::Env env);
3336
}

‎Core/Node-API/Include/Shared/napi/js_native_api.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// [BABYLON-NATIVE-ADDITION]
55
#ifndef NAPI_VERSION
6-
#define NAPI_VERSION 5
6+
#define NAPI_VERSION 7
77
#endif
88

99
// This file needs to be compatible with C compilers.

‎Core/Node-API/Include/Shared/napi/js_native_api_types.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// [BABYLON-NATIVE-ADDITION]
55
#ifndef NAPI_VERSION
6-
#define NAPI_VERSION 5
6+
#define NAPI_VERSION 7
77
#endif
88

99
// This file needs to be compatible with C compilers.

‎Core/Node-API/Include/Shared/napi/napi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define NODE_ADDON_API_DISABLE_NODE_SPECIFIC
1010
#endif
1111
#ifndef NAPI_VERSION
12-
#define NAPI_VERSION 5
12+
#define NAPI_VERSION 7
1313
#endif
1414
#ifndef NAPI_HAS_THREADS
1515
#define NAPI_HAS_THREADS 0

‎Core/Node-API/Source/env_hermes.cc‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// `hermes_run_script` directly — so the linker is never asked to find
2727
// the 4-arg symbol).
2828
//
29-
// We keep `NAPI_VERSION` at the shared default (5) so the inline wrappers
29+
// We keep `NAPI_VERSION` at the shared default (7) so the inline wrappers
3030
// in napi-inl.h that target newer NAPI revisions (e.g.
3131
// `Env::GetModuleFileName` which calls `node_api_get_module_file_name`)
3232
// aren't pulled in — they would reference symbols absent from our shared
@@ -166,6 +166,15 @@ namespace Napi
166166
(void)runtime->drainJobs();
167167
}
168168

169+
void CollectGarbage(Napi::Env env)
170+
{
171+
hermes::vm::Runtime* runtime = LookupRuntime(env);
172+
if (runtime != nullptr)
173+
{
174+
runtime->collect("node_lite explicit collection");
175+
}
176+
}
177+
169178
Napi::Value Eval(Napi::Env env, const char* source, const char* sourceUrl)
170179
{
171180
napi_env env_ptr{env};

0 commit comments

Comments
 (0)