Skip to content

Commit 02055e8

Browse files
carolhmjCedricGuillemetbghgary
authored
Update Node-API to latest from node.js (#70)
Co-authored-by: Cedric Guillemet <[email protected]> Co-authored-by: Gary Hsu <[email protected]>
1 parent 6191427 commit 02055e8

File tree

22 files changed

+9602
-5035
lines changed

22 files changed

+9602
-5035
lines changed

.github/azure-pipelines.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ trigger:
44
pr:
55
- main
66

7+
variables:
8+
- name: ndkVersion
9+
value: 25.2.9519653
10+
711
jobs:
812
# WIN32
913
- template: jobs/win32.yml
@@ -71,6 +75,18 @@ jobs:
7175

7276
# iOS
7377
- template: jobs/ios.yml
78+
parameters:
79+
name: 'iOS_Xcode142'
80+
vmImage: 'macOS-latest'
81+
xCodeVersion: 14.2
82+
simulator: 'iPhone 11'
83+
84+
- template: jobs/ios.yml
85+
parameters:
86+
name: 'iOS_Xcode150'
87+
vmImage: 'macOS-13'
88+
xCodeVersion: 15.0
89+
simulator: 'iPhone 14'
7490

7591
# Linux
7692
- template: jobs/linux.yml

.github/jobs/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
inputs:
3333
gradleWrapperFile: 'Tests/UnitTests/Android/gradlew'
3434
workingDirectory: 'Tests/UnitTests/Android'
35-
options: '-PabiFilters=x86_64 -PjsEngine=${{parameters.jsEngine}}'
35+
options: '-PabiFilters=x86_64 -PjsEngine=${{parameters.jsEngine}} -PndkVersion=$(ndkVersion)'
3636
tasks: 'connectedAndroidTest'
3737
jdkVersionOption: 1.11
3838
displayName: 'Run Connected Android Test'

.github/jobs/ios.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
parameters:
2+
name: ''
3+
vmImage: ''
4+
xCodeVersion: ''
5+
simulator: ''
6+
17
jobs:
2-
- job: iOS
8+
- job: ${{parameters.name}}
39
timeoutInMinutes: 15
410

511
pool:
6-
vmImage: macos-latest
12+
vmImage: ${{parameters.vmImage}}
713

814
steps:
915
- script: |
10-
sudo xcode-select --switch /Applications/Xcode_14.0.app/Contents/Developer
11-
displayName: 'Select XCode 14.0'
16+
sudo xcode-select --switch /Applications/Xcode_${{parameters.xCodeVersion}}.app/Contents/Developer
17+
displayName: 'Select XCode ${{parameters.xCodeVersion}}'
1218
1319
- script: |
1420
cmake -B Build/iOS -G Xcode -D IOS=ON
@@ -24,8 +30,8 @@ jobs:
2430
displayName: 'Build Xcode Project'
2531

2632
- script: |
27-
echo Boot iOS Simulator
28-
xcrun simctl boot "iPhone 11"
33+
echo Boot "${{parameters.simulator}}"
34+
xcrun simctl boot "${{parameters.simulator}}"
2935
echo Install UnitTests app
3036
xcrun simctl install booted "Build/iOS/Tests/UnitTests/RelWithDebInfo-iphonesimulator/UnitTests.app"
3137
echo Launch UnitTests app

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FetchContent_Declare(ios-cmake
2626
FetchContent_Declare(llhttp
2727
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
2828
FetchContent_Declare(UrlLib
29-
GIT_REPOSITORY https://github.com/bghgary/UrlLib.git
29+
GIT_REPOSITORY https://github.com/BabylonJS/UrlLib.git
3030
GIT_TAG 59917f32f6ddfa26af07dd981842c51ce02dafcd)
3131
# --------------------------------------------------
3232

Core/AppRuntime/Source/AppRuntime_V8.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Babylon
3636
~Module()
3737
{
3838
v8::V8::Dispose();
39-
v8::V8::ShutdownPlatform();
39+
v8::V8::DisposePlatform();
4040
}
4141

4242
static Module& Initialize(const char* executablePath)

Core/AppRuntime/V8Inspector/Source/V8InspectorAgent.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ namespace Babylon
234234
void connectFrontend()
235235
{
236236
session_ = inspector_->connect(
237-
1, new ChannelImpl(agent_), v8_inspector::StringView());
237+
1, new ChannelImpl(agent_), v8_inspector::StringView()
238+
// v8-android package and v8 nuget do not share the same V8 version. A change in V8_inspector API forces us to add this
239+
// ifndef check. This will be fixed in a future nuget package update.
240+
#ifndef ANDROID
241+
, v8_inspector::V8Inspector::kFullyTrusted
242+
#endif
243+
);
238244
}
239245

240246
void disconnectFrontend()
@@ -471,7 +477,7 @@ namespace Babylon
471477
v8::Local<v8::Context> context =
472478
v8::Isolate::GetCurrent()->GetCurrentContext();
473479

474-
int script_id = static_cast<int>(message->GetScriptOrigin().ScriptID()->Value());
480+
int script_id = message->GetScriptOrigin().ScriptId();
475481

476482
v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
477483

Core/AppRuntime/V8Inspector/Source/V8InspectorTCP.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// Licensed under the MIT license.
33
// This code is based on the old node inspector implementation. See NOTICE.md for Node.js' project license details
44
#pragma once
5+
6+
// 'allocator<void>' is deprecated
7+
// Android with NDK25
8+
// 23/10/04 : allocator still present in latest asio main branch
9+
#if defined(__clang__)
10+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
11+
#endif
12+
513
#ifdef WIN32
614
#include <Winsock2.h>
715
#endif

Core/Node-API/CMakeLists.txt

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ if(NAPI_BUILD_ABI)
3131
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/package-${name}.json" "${CMAKE_CURRENT_BINARY_DIR}/package.json")
3232
npm(install --no-package-lock --silent WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
3333

34-
file(GLOB_RECURSE ANDROID_ARCHIVE "${CMAKE_CURRENT_BINARY_DIR}/node_modules/${name}-android/${aar_path}/*.aar")
34+
file(GLOB_RECURSE ANDROID_ARCHIVE "${CMAKE_CURRENT_BINARY_DIR}/node_modules/${V8_PACKAGE_NAME}/${aar_path}/*.aar")
3535
file(ARCHIVE_EXTRACT INPUT ${ANDROID_ARCHIVE} DESTINATION ${output_directory} PATTERNS jni)
36-
message(STATUS "Extracting ${name}-android archive - done")
36+
message(STATUS "Extracting ${V8_PACKAGE_NAME} archive - done")
3737

38-
file(COPY "${CMAKE_CURRENT_BINARY_DIR}/node_modules/${name}-android/dist/include" DESTINATION ${output_directory})
38+
file(COPY "${CMAKE_CURRENT_BINARY_DIR}/node_modules/${V8_PACKAGE_NAME}/dist/include" DESTINATION ${output_directory})
3939
endfunction()
4040
endif()
4141

@@ -54,7 +54,8 @@ if(NAPI_BUILD_ABI)
5454
"Source/js_native_api_javascriptcore.h")
5555

5656
if(ANDROID)
57-
set(JSC_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/jsc-android")
57+
set(V8_PACKAGE_NAME "jsc-android")
58+
set(JSC_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/${V8_PACKAGE_NAME}")
5859
napi_install_android_package(jsc "dist/org/webkit/android-jsc" ${JSC_ANDROID_DIR})
5960

6061
# Add `JavaScriptCore` prefix to the include path
@@ -87,21 +88,24 @@ if(NAPI_BUILD_ABI)
8788
"Source/js_native_api_v8_internals.h")
8889

8990
if(ANDROID)
90-
set(V8_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/v8-android")
91+
set(V8_PACKAGE_NAME "v8-android-jit-nointl-nosnapshot")
92+
set(V8_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/${V8_PACKAGE_NAME}")
9193
napi_install_android_package(v8 "dist/org/chromium" ${V8_ANDROID_DIR})
9294

9395
set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES}
9496
PUBLIC "${V8_ANDROID_DIR}/include")
9597

9698
set(LINK_LIBRARIES ${LINK_LIBRARIES}
9799
PUBLIC "${V8_ANDROID_DIR}/jni/${ANDROID_ABI}/libv8android.so")
100+
101+
set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS)
98102
elseif(WIN32)
99103
set_cpu_platform_arch()
100-
set(V8_VERSION "8.4.371.15")
104+
set(V8_VERSION "11.9.169.4")
101105
download_nuget()
102-
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
103-
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
104-
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v142-${CPU_ARCH}.${V8_VERSION}")
106+
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
107+
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
108+
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v143-${CPU_ARCH}.${V8_VERSION}")
105109

106110
add_library(v8_libbase SHARED IMPORTED)
107111
set_target_properties(v8_libbase PROPERTIES IMPORTED_IMPLIB "${V8_PACKAGE_PATH}/lib/Release/v8_libbase.dll.lib")
@@ -111,15 +115,16 @@ if(NAPI_BUILD_ABI)
111115
set_target_properties(v8 PROPERTIES IMPORTED_IMPLIB "${V8_PACKAGE_PATH}/lib/Release/v8.dll.lib")
112116
target_link_libraries(v8 INTERFACE v8_libbase INTERFACE v8_libplatform)
113117
target_include_directories(v8 INTERFACE "${V8_PACKAGE_PATH}/include")
114-
118+
115119
set(V8_DIST
116120
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icudtl.dat"
117-
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icui18n.dll"
121+
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_icu_icui18n.dll"
122+
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_abseil-cpp_absl.dll"
118123
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icuuc.dll"
119124
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8.dll"
120125
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libbase.dll"
121126
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libplatform.dll"
122-
"${V8_REDIST_PACKAGE_PATH}/lib/Release/zlib.dll")
127+
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_zlib.dll")
123128

124129
# only 1 imported location per library -> Adding 1 library per file
125130
foreach(V8FILE ${V8_DIST})
@@ -132,18 +137,18 @@ if(NAPI_BUILD_ABI)
132137
set(LINK_LIBRARIES ${LINK_LIBRARIES}
133138
PUBLIC v8
134139
PRIVATE v8::icudtl
135-
PRIVATE v8::icui18n
140+
PRIVATE v8::third_party_icu_icui18n
136141
PRIVATE v8::icuuc
137142
PRIVATE v8::v8
138143
PRIVATE v8::v8_libbase
139144
PRIVATE v8::v8_libplatform
140-
PRIVATE v8::zlib)
141-
145+
PRIVATE v8::third_party_zlib)
146+
142147
if(CPU_ARCH STREQUAL "x64")
143148
# Enable V8 Pointer Compression
144149
# https://v8.dev/blog/pointer-compression
145150
# https://stackoverflow.com/q/62921373
146-
set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS)
151+
set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS V8_ENABLE_SANDBOX)
147152
endif()
148153
else()
149154
message(FATAL_ERROR "Unsupported JavaScript engine: ${NAPI_JAVASCRIPT_ENGINE}")
@@ -160,6 +165,8 @@ add_library(napi ${SOURCES})
160165
target_compile_definitions(napi
161166
PUBLIC NODE_ADDON_API_DISABLE_DEPRECATED
162167
PUBLIC NODE_ADDON_API_DISABLE_NODE_SPECIFIC
168+
PUBLIC NAPI_VERSION=5
169+
PUBLIC NAPI_HAS_THREADS=0
163170
${NAPI_DEFINITIONS})
164171

165172
target_include_directories(napi ${INCLUDE_DIRECTORIES})

0 commit comments

Comments
 (0)