Skip to content

Commit 822c0b9

Browse files
authored
feat: full test coverage on macos & ios, v8 14 (#28)
- Adds full test coverage 100% success for iOS, and introduces macOS test support too - Introduces some built-in Node.js APIs like node:path, etc. A process global is also added with minimal API surface - Bunch of fixes in the FFI layer, related to correctness & performance - Introduces Generated Signature Dispatch: compile time generated trampolines that boost performance of native calls by 20% on average through eliminating libffi layer - Improved memory management, less leaks. Introduces tests for reliable memory management - Removes types, build artifacts and metadata binaries from the repo - Cleans up old runtime related stuff - Fetches prebuilt V8 binaries now. To be added for Hermes soon.
1 parent 99bc1d4 commit 822c0b9

File tree

1,519 files changed

+24767
-1622773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,519 files changed

+24767
-1622773
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: CI
22
on:
33
push:
4-
branches: '*'
4+
branches: [main]
55
pull_request:
66

77
jobs:
88
build:
9-
runs-on: macos-latest
9+
runs-on: macos-26
1010
steps:
1111
- uses: actions/checkout@v5
1212
with:
@@ -20,6 +20,9 @@ jobs:
2020
- name: Install Dependencies
2121
run: npm install
2222

23+
- name: Download V8
24+
run: ./download_v8.sh
25+
2326
- name: Install libffi build tools
2427
run: brew install autoconf automake libtool texinfo
2528

@@ -28,6 +31,22 @@ jobs:
2831

2932
- name: Build metadata generator
3033
run: npm run build-metagen
34+
35+
- name: Generate macOS metadata
36+
run: npm run metagen macos
3137

3238
- name: Build NativeScript
33-
run: npm run build --quickjs
39+
run: npm run build
40+
41+
- name: Build CLI
42+
run: npm run build:macos-cli
43+
44+
- name: Run Tests on macOS
45+
run: npm run test:macos
46+
47+
- name: Run Tests on iOS
48+
env:
49+
IOS_BUILD_TIMEOUT_MS: "600000"
50+
IOS_TEST_TIMEOUT_MS: "600000"
51+
IOS_TEST_INACTIVITY_TIMEOUT_MS: "180000"
52+
run: npm run test:ios

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ v8_build
5959

6060
.cache/
6161

62+
dist
63+
packages/*/types
64+
6265
SwiftBindgen
66+
67+
# Generated Objective-C/C dispatch wrappers
68+
NativeScript/ffi/GeneratedSignatureDispatch.inc

NativeScript/CMakeLists.txt

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ elseif(TARGET_ENGINE STREQUAL "hermes")
7878
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++20 -DTARGET_ENGINE_HERMES")
7979
elseif(TARGET_ENGINE STREQUAL "v8")
8080
set(TARGET_ENGINE_V8 TRUE)
81-
add_link_options("-fuse-ld=lld")
8281
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -stdlib=libc++ -std=c++20 -DTARGET_ENGINE_V8")
8382
elseif(TARGET_ENGINE STREQUAL "quickjs")
8483
set(TARGET_ENGINE_QUICKJS TRUE)
@@ -152,10 +151,16 @@ if(ENABLE_JS_RUNTIME)
152151
runtime/modules/worker/WorkerImpl.mm
153152
runtime/modules/worker/WorkerImpl.mm
154153
runtime/modules/module/ModuleInternal.cpp
154+
runtime/modules/node/Node.cpp
155+
runtime/modules/node/FS.cpp
156+
runtime/modules/node/Path.cpp
157+
runtime/modules/node/Process.cpp
155158
runtime/modules/performance/Performance.cpp
159+
runtime/ThreadSafeFunction.mm
156160
runtime/Bundle.mm
157161
runtime/modules/timers/Timers.mm
158162
runtime/modules/app/App.mm
163+
runtime/modules/web/Web.mm
159164
runtime/NativeScript.mm
160165
runtime/RuntimeConfig.cpp
161166
runtime/modules/url/ada/ada.cpp
@@ -166,7 +171,6 @@ if(ENABLE_JS_RUNTIME)
166171
if(TARGET_ENGINE_V8)
167172
include_directories(
168173
napi/v8
169-
napi/v8/include
170174
napi/v8/v8_inspector
171175
)
172176

@@ -292,6 +296,17 @@ target_sources(
292296
"NativeScript.h"
293297
)
294298

299+
if(TARGET_ENGINE_V8 AND TARGET_PLATFORM_IOS)
300+
# iOS V8 slices are built with pointer compression enabled. Keep embedder
301+
# build flags in sync to satisfy V8::Initialize() build config checks.
302+
target_compile_definitions(
303+
${NAME}
304+
PRIVATE
305+
V8_COMPRESS_POINTERS
306+
V8_31BIT_SMIS_ON_64BIT_ARCH
307+
)
308+
endif()
309+
295310
set(FRAMEWORK_VERSION_VALUE "${VERSION}")
296311
if(TARGET_PLATFORM_MACOS)
297312
# macOS framework consumers (including Xcode's copy/sign phases) expect
@@ -392,27 +407,42 @@ if(TARGET_ENGINE_JSC)
392407
endif()
393408

394409
if(TARGET_ENGINE_V8)
395-
if(TARGET_PLATFORM_MACOS)
396-
target_link_directories(
397-
${NAME}
398-
PRIVATE
399-
${CMAKE_CURRENT_SOURCE_DIR}/../Frameworks/v8_macos
400-
)
410+
add_library(v8::monolith STATIC IMPORTED GLOBAL)
411+
412+
set(V8_XCFRAMEWORK "${CMAKE_SOURCE_DIR}/../Frameworks/libv8_monolith.xcframework")
413+
414+
# Decide platform + slice
415+
if(APPLE)
416+
if(TARGET_PLATFORM STREQUAL "ios-sim")
417+
# Prefer universal sim slice if present
418+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/ios-arm64-simulator/libv8_monolith.framework")
419+
if(NOT EXISTS "${V8_SLICE_DIR}")
420+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/ios-arm64-simulator/libv8_monolith.framework") # fallback
421+
endif()
422+
elseif(TARGET_PLATFORM STREQUAL "ios")
423+
# Prefer universal sim slice if present
424+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/ios-arm64/libv8_monolith.framework")
425+
if(NOT EXISTS "${V8_SLICE_DIR}")
426+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/ios-arm64/libv8_monolith.framework") # fallback
427+
endif()
428+
else()
429+
# macOS
430+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/macos-arm64/libv8_monolith.framework")
431+
if(NOT EXISTS "${V8_SLICE_DIR}")
432+
set(V8_SLICE_DIR "${V8_XCFRAMEWORK}/macos-arm64/libv8_monolith.framework") # keep same, just explicit
433+
endif()
434+
endif()
401435
else()
402-
target_link_directories(
403-
${NAME}
404-
PRIVATE
405-
${CMAKE_CURRENT_SOURCE_DIR}/../Frameworks/v8_ios
406-
)
436+
message(FATAL_ERROR "This example is for Apple platforms only.")
407437
endif()
408438

409-
target_link_libraries(
410-
${NAME}
411-
PRIVATE
412-
"v8_monolith"
413-
"v8_libbase"
414-
"v8_libplatform"
439+
# Point imported lib at the slice
440+
set_target_properties(v8::monolith PROPERTIES
441+
IMPORTED_LOCATION "${V8_SLICE_DIR}/libv8_monolith"
442+
INTERFACE_INCLUDE_DIRECTORIES "${V8_SLICE_DIR}/Headers"
415443
)
444+
445+
target_link_libraries(${NAME} PRIVATE v8::monolith)
416446
endif()
417447

418448
target_link_libraries(

NativeScript/cli/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ void bootFromModuleSpec(std::string baseDir, std::string spec) {
6161

6262
int main(int argc, char** argv) {
6363
RuntimeConfig.LogToSystemConsole = true;
64+
RuntimeConfig.Arguments.clear();
65+
if (argv != nullptr && argc > 0) {
66+
RuntimeConfig.Arguments.reserve(static_cast<size_t>(argc));
67+
for (int i = 0; i < argc; i++) {
68+
RuntimeConfig.Arguments.emplace_back(argv[i] != nullptr ? argv[i] : "");
69+
}
70+
}
6471

6572
#ifdef __APPLE__
6673
std::string bytecodePath = getBytecodePathFromBundle();

NativeScript/ffi/Block.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ class FunctionPointer {
1414
void* function;
1515
metagen::MDSectionOffset offset;
1616
Cif* cif;
17+
bool ownsCif = false;
1718

1819
static napi_value wrap(napi_env env, void* function,
1920
metagen::MDSectionOffset offset, bool isBlock);
21+
static napi_value wrapWithEncoding(napi_env env, void* function,
22+
const char* encoding, bool isBlock);
2023
static void finalize(napi_env env, void* finalize_data, void* finalize_hint);
2124

2225
static napi_value jsCallAsCFunction(napi_env env, napi_callback_info cbinfo);
2326
static napi_value jsCallAsBlock(napi_env env, napi_callback_info cbinfo);
2427
};
2528

2629
id registerBlock(napi_env env, Closure* closure, napi_value callback);
30+
napi_value getCachedBlockCallback(napi_env env, void* blockPtr);
31+
bool isObjCBlockObject(id obj);
32+
const char* getObjCBlockSignature(void* blockPtr);
2733

2834
NAPI_FUNCTION(registerBlock);
2935

0 commit comments

Comments
 (0)