Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ SwiftBindgen

# Generated Objective-C/C dispatch wrappers
NativeScript/ffi/GeneratedSignatureDispatch.inc
NativeScript/ffi/GeneratedSignatureDispatch.inc.stamp

# React Native TurboModule package staging
packages/react-native/dist/
packages/react-native/ios/vendor/
packages/react-native/metadata/
packages/react-native/native-api-jsi/
78 changes: 78 additions & 0 deletions NativeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
# Arguments
set(TARGET_PLATFORM "macos" CACHE STRING "Target platform for the Objective-C bridge")
set(TARGET_ENGINE "v8" CACHE STRING "Target JS engine for the NativeScript runtime")
set(NS_GSD_BACKEND "auto" CACHE STRING "Generated signature dispatch backend: auto, v8, jsc, quickjs, hermes, napi, or none")
set(METADATA_SIZE 0 CACHE STRING "Size of embedded metadata in bytes")
set(BUILD_CLI_BINARY OFF CACHE BOOL "Build the NativeScript CLI binary")
set(BUILD_MACOS_NODE_API OFF CACHE BOOL "Build the NativeScript macOS Node API dylib")
set_property(CACHE NS_GSD_BACKEND PROPERTY STRINGS auto v8 jsc quickjs hermes napi none)

if (BUILD_MACOS_NODE_API)
set(BUILD_FRAMEWORK OFF)
Expand Down Expand Up @@ -132,6 +134,44 @@ message(STATUS "TARGET_ENGINE = ${TARGET_ENGINE}")
message(STATUS "ENABLE_JS_RUNTIME = ${ENABLE_JS_RUNTIME}")
message(STATUS "GENERIC_NAPI = ${GENERIC_NAPI}")

if(NS_GSD_BACKEND STREQUAL "auto")
if(TARGET_ENGINE_V8)
set(NS_EFFECTIVE_GSD_BACKEND "v8")
elseif(TARGET_ENGINE_JSC)
set(NS_EFFECTIVE_GSD_BACKEND "jsc")
elseif(TARGET_ENGINE_QUICKJS)
set(NS_EFFECTIVE_GSD_BACKEND "quickjs")
elseif(TARGET_ENGINE_HERMES)
set(NS_EFFECTIVE_GSD_BACKEND "hermes")
else()
set(NS_EFFECTIVE_GSD_BACKEND "napi")
endif()
elseif(NS_GSD_BACKEND STREQUAL "v8" OR
NS_GSD_BACKEND STREQUAL "jsc" OR
NS_GSD_BACKEND STREQUAL "quickjs" OR
NS_GSD_BACKEND STREQUAL "hermes" OR
NS_GSD_BACKEND STREQUAL "napi" OR
NS_GSD_BACKEND STREQUAL "none")
set(NS_EFFECTIVE_GSD_BACKEND "${NS_GSD_BACKEND}")
else()
message(FATAL_ERROR "Unknown NS_GSD_BACKEND: ${NS_GSD_BACKEND}")
endif()

if(NS_EFFECTIVE_GSD_BACKEND STREQUAL "v8" AND NOT TARGET_ENGINE_V8)
message(FATAL_ERROR "NS_GSD_BACKEND=v8 requires TARGET_ENGINE=v8")
endif()
if(NS_EFFECTIVE_GSD_BACKEND STREQUAL "jsc" AND NOT TARGET_ENGINE_JSC)
message(FATAL_ERROR "NS_GSD_BACKEND=jsc requires TARGET_ENGINE=jsc")
endif()
if(NS_EFFECTIVE_GSD_BACKEND STREQUAL "quickjs" AND NOT TARGET_ENGINE_QUICKJS)
message(FATAL_ERROR "NS_GSD_BACKEND=quickjs requires TARGET_ENGINE=quickjs")
endif()
if(NS_EFFECTIVE_GSD_BACKEND STREQUAL "hermes" AND NOT TARGET_ENGINE_HERMES)
message(FATAL_ERROR "NS_GSD_BACKEND=hermes requires TARGET_ENGINE=hermes")
endif()

message(STATUS "NS_GSD_BACKEND = ${NS_GSD_BACKEND} (${NS_EFFECTIVE_GSD_BACKEND})")

# Set up sources
include_directories(
./
Expand All @@ -158,6 +198,7 @@ set(SOURCE_FILES
ffi/Variable.mm
ffi/Object.mm
ffi/CFunction.mm
ffi/EngineDirectCall.mm
ffi/Interop.mm
ffi/InlineFunctions.mm
ffi/ClassBuilder.mm
Expand Down Expand Up @@ -207,6 +248,7 @@ if(ENABLE_JS_RUNTIME)
napi/v8/v8-module-loader.cpp
napi/v8/jsr.cpp
napi/v8/SimpleAllocator.cpp
ffi/V8FastNativeApi.mm
)

elseif(TARGET_ENGINE_HERMES)
Expand All @@ -231,6 +273,8 @@ if(ENABLE_JS_RUNTIME)
set(SOURCE_FILES
${SOURCE_FILES}
napi/hermes/jsr.cpp
ffi/jsi/NativeApiJsi.mm
ffi/HermesFastNativeApi.mm
)

elseif(TARGET_ENGINE_QUICKJS)
Expand Down Expand Up @@ -263,6 +307,7 @@ if(ENABLE_JS_RUNTIME)
# napi
napi/quickjs/quickjs-api.c
napi/quickjs/jsr.cpp
ffi/QuickJSFastNativeApi.mm
)

elseif(TARGET_ENGINE_JSC)
Expand All @@ -275,6 +320,7 @@ if(ENABLE_JS_RUNTIME)
set(SOURCE_FILES ${SOURCE_FILES}
napi/jsc/jsc-api.cpp
napi/jsc/jsr.cpp
ffi/JSCFastNativeApi.mm
)
endif()
else()
Expand Down Expand Up @@ -345,6 +391,38 @@ if(TARGET_ENGINE_V8 AND TARGET_PLATFORM_IOS)
)
endif()

if(ENABLE_JS_RUNTIME)
target_compile_definitions(${NAME} PRIVATE ENABLE_JS_RUNTIME)
endif()

if(TARGET_PLATFORM_MACOS)
target_compile_definitions(${NAME} PRIVATE TARGET_PLATFORM_MACOS)
endif()

if(TARGET_ENGINE_HERMES)
target_compile_definitions(${NAME} PRIVATE TARGET_ENGINE_HERMES)
elseif(TARGET_ENGINE_V8)
target_compile_definitions(${NAME} PRIVATE TARGET_ENGINE_V8)
elseif(TARGET_ENGINE_QUICKJS)
target_compile_definitions(${NAME} PRIVATE TARGET_ENGINE_QUICKJS)
elseif(TARGET_ENGINE_JSC)
target_compile_definitions(${NAME} PRIVATE TARGET_ENGINE_JSC)
endif()

if(NS_EFFECTIVE_GSD_BACKEND STREQUAL "v8")
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=1 NS_GSD_BACKEND_JSC=0 NS_GSD_BACKEND_QUICKJS=0 NS_GSD_BACKEND_HERMES=0 NS_GSD_BACKEND_NAPI=0)
elseif(NS_EFFECTIVE_GSD_BACKEND STREQUAL "jsc")
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=0 NS_GSD_BACKEND_JSC=1 NS_GSD_BACKEND_QUICKJS=0 NS_GSD_BACKEND_HERMES=0 NS_GSD_BACKEND_NAPI=0)
elseif(NS_EFFECTIVE_GSD_BACKEND STREQUAL "quickjs")
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=0 NS_GSD_BACKEND_JSC=0 NS_GSD_BACKEND_QUICKJS=1 NS_GSD_BACKEND_HERMES=0 NS_GSD_BACKEND_NAPI=0)
elseif(NS_EFFECTIVE_GSD_BACKEND STREQUAL "hermes")
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=0 NS_GSD_BACKEND_JSC=0 NS_GSD_BACKEND_QUICKJS=0 NS_GSD_BACKEND_HERMES=1 NS_GSD_BACKEND_NAPI=0)
elseif(NS_EFFECTIVE_GSD_BACKEND STREQUAL "napi")
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=0 NS_GSD_BACKEND_JSC=0 NS_GSD_BACKEND_QUICKJS=0 NS_GSD_BACKEND_HERMES=0 NS_GSD_BACKEND_NAPI=1)
else()
target_compile_definitions(${NAME} PRIVATE NS_GSD_BACKEND_V8=0 NS_GSD_BACKEND_JSC=0 NS_GSD_BACKEND_QUICKJS=0 NS_GSD_BACKEND_HERMES=0 NS_GSD_BACKEND_NAPI=0)
endif()

set(FRAMEWORK_VERSION_VALUE "${VERSION}")
if(TARGET_PLATFORM_MACOS)
# macOS framework consumers (including Xcode's copy/sign phases) expect
Expand Down
2 changes: 1 addition & 1 deletion NativeScript/NativeScript-Prefix.pch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef NativeScript_Prefix_pch
#define NativeScript_Prefix_pch

#define NATIVESCRIPT_VERSION "9.0.0-napi-v8.0"
#define NATIVESCRIPT_VERSION "0.0.1"

#endif /* NativeScript_Prefix_pch */
6 changes: 6 additions & 0 deletions NativeScript/ffi/Block.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BLOCK_H
#define BLOCK_H

#include <cstdint>
#include <cstdlib>

#include "Cif.h"
Expand All @@ -15,6 +16,11 @@ class FunctionPointer {
metagen::MDSectionOffset offset;
Cif* cif;
bool ownsCif = false;
bool dispatchLookupCached = false;
uint64_t dispatchLookupSignatureHash = 0;
uint64_t dispatchId = 0;
void* preparedInvoker = nullptr;
void* hermesFrameDirectReturnInvoker = nullptr;

static napi_value wrap(napi_env env, void* function,
metagen::MDSectionOffset offset, bool isBlock);
Expand Down
Loading
Loading