Skip to content

Commit 8549a7a

Browse files
committed
✨ feat: Add android node to cmake
1 parent 4269f2a commit 8549a7a

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

cpp/CMakeLists.txt

+36-14
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,35 @@ if(DEFINED NODE_DIR)
117117
list(APPEND importLibraries
118118
ada base64 brotli cares histogram llhttp nghttp2 nghttp3 ngtcp2 openssl simdutf torque_base uvwasi
119119
v8_base_without_compiler v8_compiler v8_init v8_initializers
120-
v8_libbase v8_libplatform v8_snapshot v8_turboshaft v8_zlib zlib zlib_adler32_simd zlib_inflate_chunk_simd)
121-
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|aarch64)")
120+
v8_libbase v8_libplatform v8_snapshot v8_turboshaft v8_zlib zlib)
121+
# base64
122+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|aarch64)" OR CMAKE_ANDROID_ARCH STREQUAL "arm64")
122123
list(APPEND importLibraries base64_neon64)
123-
else()
124+
elseif(NOT CMAKE_ANDROID_ARCH STREQUAL "arm")
124125
list(APPEND importLibraries base64_avx base64_avx2 base64_avx512 base64_sse41 base64_sse42 base64_ssse3)
125126
endif()
127+
# node, uv
126128
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
127129
list(APPEND importLibraries libnode libuv)
128-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|aarch64)")
129-
list(APPEND importLibraries node uv)
130-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
131-
list(APPEND importLibraries node node_text_start uv)
132-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
130+
else()
133131
list(APPEND importLibraries node uv)
134132
endif()
135-
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
136-
list(APPEND importLibraries zlib_arm_crc32)
137-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|aarch64)")
138-
list(APPEND importLibraries zlib_arm_crc32)
139-
# else()
140-
# list(APPEND importLibraries zlib_crc32_simd)
133+
# node_text_start
134+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
135+
list(APPEND importLibraries node_text_start)
136+
endif()
137+
# zlib
138+
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
139+
if(CMAKE_ANDROID_ARCH STREQUAL "arm64")
140+
list(APPEND importLibraries zlib_adler32_simd zlib_arm_crc32)
141+
elseif(CMAKE_ANDROID_ARCH MATCHES "(x86|x86_64)")
142+
list(APPEND importLibraries zlib_adler32_simd zlib_inflate_chunk_simd)
143+
endif()
144+
else()
145+
list(APPEND importLibraries zlib_adler32_simd zlib_inflate_chunk_simd)
146+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|aarch64)")
147+
list(APPEND importLibraries zlib_arm_crc32)
148+
endif()
141149
endif()
142150
add_definitions(-DENABLE_NODE)
143151
set(JAVET_LIB_TYPE "node")
@@ -247,6 +255,20 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android
247255
target_link_libraries(JavetStatic PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive
248256
-llog -static-libgcc -static-libstdc++ "${libgcc}")
249257
endif()
258+
if(DEFINED NODE_DIR)
259+
list(APPEND includeDirs
260+
${NODE_DIR}/out.${CMAKE_ANDROID_ARCH}/Release/obj/gen/generate-bytecode-output-root
261+
${NODE_DIR}/out.${CMAKE_ANDROID_ARCH}/Release/obj/gen/inspector-generated-output-root
262+
${NODE_DIR}/out.${CMAKE_ANDROID_ARCH}/Release/obj/gen)
263+
foreach(importLibrary ${importLibraries})
264+
set_target_properties(${importLibrary} PROPERTIES IMPORTED_LOCATION ${NODE_DIR}/out.${CMAKE_ANDROID_ARCH}/Release/lib${importLibrary}.a)
265+
endforeach(importLibrary)
266+
list(REMOVE_ITEM importLibraries v8_init)
267+
target_link_libraries(Javet PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive
268+
v8_init -llog -static-libgcc -static-libstdc++ "${libgcc}")
269+
target_link_libraries(JavetStatic PUBLIC -Wl,--whole-archive ${importLibraries} -Wl,--no-whole-archive
270+
v8_init -llog -static-libgcc -static-libstdc++ "${libgcc}")
271+
endif()
250272
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(arm64|x86_64)")
251273
set(JAVET_LIB_SYSTEM "macos")
252274
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-ambiguous-reversed-operator ")

cpp/jni/javet_v8_runtime.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ namespace Javet {
169169
virtual ~V8Runtime();
170170

171171
private:
172-
std::unique_ptr<v8::SnapshotCreator> v8SnapshotCreator;
173-
std::unique_ptr<v8::StartupData, std::function<void(v8::StartupData*)>> v8StartupData;
174-
std::shared_ptr<v8::Locker> v8Locker;
175-
V8PersistentContext v8PersistentContext;
176172
#ifdef ENABLE_NODE
177173
// The following Node objects must be live as long as V8 context lives.
178174
std::shared_ptr<node::ArrayBufferAllocator> nodeArrayBufferAllocator;
@@ -182,6 +178,10 @@ namespace Javet {
182178
#else
183179
std::shared_ptr<V8ArrayBufferAllocator> v8ArrayBufferAllocator;
184180
#endif
181+
std::unique_ptr<v8::SnapshotCreator> v8SnapshotCreator;
182+
std::unique_ptr<v8::StartupData, std::function<void(v8::StartupData*)>> v8StartupData;
183+
std::shared_ptr<v8::Locker> v8Locker;
184+
V8PersistentContext v8PersistentContext;
185185
};
186186
}
187187

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
diff --git a/deps/v8/src/codegen/arm/constants-arm.h b/deps/v8/src/codegen/arm/constants-arm.h
2+
index 5b8636d3b9..ff6dea9a58 100644
3+
--- a/deps/v8/src/codegen/arm/constants-arm.h
4+
+++ b/deps/v8/src/codegen/arm/constants-arm.h
5+
@@ -179,7 +179,13 @@ constexpr int U = 1 << 23; // Positive (or negative) offset/index.
6+
constexpr int P =
7+
1 << 24; // Offset/pre-indexed addressing (or post-indexed addressing).
8+
constexpr int I = 1 << 25; // Immediate shifter operand (or not).
9+
+#ifdef B0
10+
+#undef B0
11+
+// ensure safe undef
12+
+#define B0 undefined
13+
+#else
14+
constexpr int B0 = 1 << 0;
15+
+#endif
16+
constexpr int B4 = 1 << 4;
17+
constexpr int B5 = 1 << 5;
18+
constexpr int B6 = 1 << 6;

0 commit comments

Comments
 (0)