Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node-API to latest from node.js #70

Merged
merged 40 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
465786a
Updating Node-API
carolhmj Dec 18, 2023
b66f12a
Additional Babylon Native methods
carolhmj Jan 5, 2024
b2c97b8
fix build errors
carolhmj Jan 8, 2024
a32b28a
fix arraybuffer implementation
carolhmj Jan 9, 2024
52af4bd
fix napi_create_external_arraybuffer
carolhmj Jan 30, 2024
8451161
up gradle, packages
CedricGuillemet Jan 31, 2024
ebaf505
Merge branch 'update_napi' of /~https://github.com/carolhmj/JsRuntimeHo…
CedricGuillemet Jan 31, 2024
58c17e4
revert fix
CedricGuillemet Jan 31, 2024
0f1aef9
build test w/o external data
CedricGuillemet Jan 31, 2024
2a1e7f4
asio
CedricGuillemet Jan 31, 2024
b4b51f4
more on android v8 inspector
CedricGuillemet Jan 31, 2024
b1378ad
v8 no sandbox
CedricGuillemet Jan 31, 2024
1e5b196
node specific
CedricGuillemet Jan 31, 2024
e478894
comment non functionning code
CedricGuillemet Feb 1, 2024
9b70af6
napi_create_external_arraybuffer
CedricGuillemet Feb 2, 2024
331c40d
Merge branch 'main' of /~https://github.com/babylonjs/JsRuntimeHost int…
CedricGuillemet Feb 2, 2024
3bc4cc4
napi_create_external_arraybuffer
CedricGuillemet Feb 2, 2024
816afb1
not there yet
CedricGuillemet Feb 2, 2024
c22ce75
iphone15
CedricGuillemet Feb 2, 2024
8e771c5
iphone simulator variable
CedricGuillemet Feb 2, 2024
8d6b7ef
some comments addressed
CedricGuillemet Feb 8, 2024
ce87f9a
move files in source folder
CedricGuillemet Feb 8, 2024
83720bb
source url for run script
CedricGuillemet Feb 8, 2024
5e35657
fix jsc
CedricGuillemet Feb 8, 2024
898d8e5
comment
CedricGuillemet Feb 8, 2024
1f0305d
Merge branch 'main' of /~https://github.com/babylonjs/JsRuntimeHost int…
CedricGuillemet Feb 8, 2024
6c16f25
spaces
CedricGuillemet Feb 8, 2024
b34c7e0
more PR feedback
CedricGuillemet Feb 12, 2024
88d56e4
Merge branch 'main' of /~https://github.com/babylonjs/JsRuntimeHost int…
CedricGuillemet Feb 12, 2024
3506856
removed comments
CedricGuillemet Feb 12, 2024
400f9a2
check for NAPI_VERSION >= 8
CedricGuillemet Feb 13, 2024
311e3ab
missing endif
CedricGuillemet Feb 13, 2024
8cd68c9
Merge branch 'main' of /~https://github.com/babylonjs/JsRuntimeHost int…
CedricGuillemet Feb 14, 2024
5850ea6
consolidate napi_add_finalizer definition
CedricGuillemet Feb 15, 2024
e45d217
napi 5 w/o threads
CedricGuillemet Feb 15, 2024
65ba105
Merge branch 'main' of /~https://github.com/babylonjs/JsRuntimeHost int…
CedricGuillemet Feb 21, 2024
e3f9b2d
RunScript url
CedricGuillemet Feb 21, 2024
e00a023
remove runscript call for napi-jsi
CedricGuillemet Feb 21, 2024
2b67aed
Increase perf by using internal field instead of private property
bghgary Feb 21, 2024
b2f8f33
Fix typo
bghgary Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ trigger:
pr:
- main

variables:
- name: ndkVersion
value: 25.2.9519653

jobs:
# WIN32
- template: jobs/win32.yml
Expand Down Expand Up @@ -71,6 +75,18 @@ jobs:

# iOS
- template: jobs/ios.yml
parameters:
name: 'iOS_Xcode142'
vmImage: 'macOS-latest'
xCodeVersion: 14.2
simulator: 'iPhone 11'

- template: jobs/ios.yml
parameters:
name: 'iOS_Xcode150'
vmImage: 'macOS-13'
xCodeVersion: 15.0
simulator: 'iPhone 14'

# Linux
- template: jobs/linux.yml
CedricGuillemet marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion .github/jobs/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
inputs:
gradleWrapperFile: 'Tests/UnitTests/Android/gradlew'
workingDirectory: 'Tests/UnitTests/Android'
options: '-PabiFilters=x86_64 -PjsEngine=${{parameters.jsEngine}}'
options: '-PabiFilters=x86_64 -PjsEngine=${{parameters.jsEngine}} -PndkVersion=$(ndkVersion)'
tasks: 'connectedAndroidTest'
jdkVersionOption: 1.11
displayName: 'Run Connected Android Test'
Expand Down
18 changes: 12 additions & 6 deletions .github/jobs/ios.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
parameters:
name: ''
vmImage: ''
xCodeVersion: ''
simulator: ''
CedricGuillemet marked this conversation as resolved.
Show resolved Hide resolved

jobs:
- job: iOS
- job: ${{parameters.name}}
timeoutInMinutes: 15

pool:
vmImage: macos-latest
vmImage: ${{parameters.vmImage}}

steps:
- script: |
sudo xcode-select --switch /Applications/Xcode_14.0.app/Contents/Developer
displayName: 'Select XCode 14.0'
sudo xcode-select --switch /Applications/Xcode_${{parameters.xCodeVersion}}.app/Contents/Developer
displayName: 'Select XCode ${{parameters.xCodeVersion}}'

- script: |
cmake -B Build/iOS -G Xcode -D IOS=ON
Expand All @@ -24,8 +30,8 @@ jobs:
displayName: 'Build Xcode Project'

- script: |
echo Boot iOS Simulator
xcrun simctl boot "iPhone 11"
echo Boot "${{parameters.simulator}}"
xcrun simctl boot "${{parameters.simulator}}"
echo Install UnitTests app
xcrun simctl install booted "Build/iOS/Tests/UnitTests/RelWithDebInfo-iphonesimulator/UnitTests.app"
echo Launch UnitTests app
Expand Down
2 changes: 1 addition & 1 deletion Core/AppRuntime/Source/AppRuntime_V8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Babylon
~Module()
{
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
v8::V8::DisposePlatform();
}

static Module& Initialize(const char* executablePath)
Expand Down
10 changes: 8 additions & 2 deletions Core/AppRuntime/V8Inspector/Source/V8InspectorAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ namespace Babylon
void connectFrontend()
{
session_ = inspector_->connect(
1, new ChannelImpl(agent_), v8_inspector::StringView());
1, new ChannelImpl(agent_), v8_inspector::StringView()
// v8-android package and v8 nuget do not share the same V8 version. A change in V8_inspector API forces us to add this
// ifndef check. This will be fixed in a future nuget package update.
#ifndef ANDROID
, v8_inspector::V8Inspector::kFullyTrusted
#endif
CedricGuillemet marked this conversation as resolved.
Show resolved Hide resolved
);
}

void disconnectFrontend()
Expand Down Expand Up @@ -471,7 +477,7 @@ namespace Babylon
v8::Local<v8::Context> context =
v8::Isolate::GetCurrent()->GetCurrentContext();

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

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

Expand Down
8 changes: 8 additions & 0 deletions Core/AppRuntime/V8Inspector/Source/V8InspectorTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
// Licensed under the MIT license.
// This code is based on the old node inspector implementation. See NOTICE.md for Node.js' project license details
#pragma once

// 'allocator<void>' is deprecated
// Android with NDK25
// 23/10/04 : allocator still present in latest asio main branch
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif

#ifdef WIN32
#include <Winsock2.h>
#endif
Expand Down
38 changes: 22 additions & 16 deletions Core/Node-API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ if(NAPI_BUILD_ABI)
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/package-${name}.json" "${CMAKE_CURRENT_BINARY_DIR}/package.json")
npm(install --no-package-lock --silent WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

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

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

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

if(ANDROID)
set(JSC_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/jsc-android")
set(V8_PACKAGE_NAME "jsc-android")
set(JSC_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/${V8_PACKAGE_NAME}")
napi_install_android_package(jsc "dist/org/webkit/android-jsc" ${JSC_ANDROID_DIR})

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

if(ANDROID)
set(V8_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/v8-android")
set(V8_PACKAGE_NAME "v8-android-jit-nointl-nosnapshot")
set(V8_ANDROID_DIR "${CMAKE_CURRENT_BINARY_DIR}/${V8_PACKAGE_NAME}")
napi_install_android_package(v8 "dist/org/chromium" ${V8_ANDROID_DIR})

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

set(LINK_LIBRARIES ${LINK_LIBRARIES}
PUBLIC "${V8_ANDROID_DIR}/jni/${ANDROID_ABI}/libv8android.so")

set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS)
elseif(WIN32)
set_cpu_platform_arch()
set(V8_VERSION "8.4.371.15")
set(V8_VERSION "11.9.169.4")
download_nuget()
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v142-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
set(V8_PACKAGE_PATH "${NUGET_PATH}/packages/v8-v143-${CPU_ARCH}.${V8_VERSION}")
set(V8_REDIST_PACKAGE_PATH "${NUGET_PATH}/packages/v8.redist-v143-${CPU_ARCH}.${V8_VERSION}")

add_library(v8_libbase SHARED IMPORTED)
set_target_properties(v8_libbase PROPERTIES IMPORTED_IMPLIB "${V8_PACKAGE_PATH}/lib/Release/v8_libbase.dll.lib")
Expand All @@ -111,15 +115,16 @@ if(NAPI_BUILD_ABI)
set_target_properties(v8 PROPERTIES IMPORTED_IMPLIB "${V8_PACKAGE_PATH}/lib/Release/v8.dll.lib")
target_link_libraries(v8 INTERFACE v8_libbase INTERFACE v8_libplatform)
target_include_directories(v8 INTERFACE "${V8_PACKAGE_PATH}/include")

set(V8_DIST
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icudtl.dat"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icui18n.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_icu_icui18n.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_abseil-cpp_absl.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/icuuc.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libbase.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/v8_libplatform.dll"
"${V8_REDIST_PACKAGE_PATH}/lib/Release/zlib.dll")
"${V8_REDIST_PACKAGE_PATH}/lib/Release/third_party_zlib.dll")

# only 1 imported location per library -> Adding 1 library per file
foreach(V8FILE ${V8_DIST})
Expand All @@ -132,18 +137,18 @@ if(NAPI_BUILD_ABI)
set(LINK_LIBRARIES ${LINK_LIBRARIES}
PUBLIC v8
PRIVATE v8::icudtl
PRIVATE v8::icui18n
PRIVATE v8::third_party_icu_icui18n
PRIVATE v8::icuuc
PRIVATE v8::v8
PRIVATE v8::v8_libbase
PRIVATE v8::v8_libplatform
PRIVATE v8::zlib)
PRIVATE v8::third_party_zlib)

if(CPU_ARCH STREQUAL "x64")
# Enable V8 Pointer Compression
# https://v8.dev/blog/pointer-compression
# https://stackoverflow.com/q/62921373
set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS)
set(NAPI_DEFINITIONS PUBLIC V8_COMPRESS_POINTERS V8_ENABLE_SANDBOX)
CedricGuillemet marked this conversation as resolved.
Show resolved Hide resolved
endif()
else()
message(FATAL_ERROR "Unsupported JavaScript engine: ${NAPI_JAVASCRIPT_ENGINE}")
Expand All @@ -160,6 +165,7 @@ add_library(napi ${SOURCES})
target_compile_definitions(napi
PUBLIC NODE_ADDON_API_DISABLE_DEPRECATED
PUBLIC NODE_ADDON_API_DISABLE_NODE_SPECIFIC
PUBLIC NAPI_VERSION=3
${NAPI_DEFINITIONS})

target_include_directories(napi ${INCLUDE_DIRECTORIES})
Expand Down
Loading