Skip to content

Commit 7c6eb25

Browse files
committed
follow react-native-node-api standard approach
Built with: ```sh ./build_all_react_native.sh ```
1 parent 6b48408 commit 7c6eb25

File tree

455 files changed

+150538
-126425
lines changed

Some content is hidden

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

455 files changed

+150538
-126425
lines changed

NativeScript/CMakeLists.txt

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cmake_minimum_required(VERSION 3.15)
22

33
# Metadata
4-
54
project(NativeScript CXX OBJCXX)
65

76
set(NAME NativeScript)
@@ -17,7 +16,6 @@ set(COMMON_FLAGS "-O3 -Wno-shorten-64-to-32")
1716
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
1817

1918
# Arguments
20-
2119
set(TARGET_PLATFORM "macos" CACHE STRING "Target platform for the Objective-C bridge")
2220
set(TARGET_ENGINE "v8" CACHE STRING "Target JS engine for the NativeScript runtime")
2321
set(METADATA_SIZE 0 CACHE STRING "Size of embedded metadata in bytes")
@@ -56,6 +54,10 @@ elseif(TARGET_PLATFORM STREQUAL "macos")
5654
set(TARGET_PLATFORM_SPEC "macos-arm64_x86_64")
5755
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTARGET_PLATFORM_MACOS")
5856

57+
# Unlike "ios", "macos" doesn't seem to produce a NativeScript.framework.dSYM
58+
# by default. We can produce it by setting these variables.
59+
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym")
60+
set(CMAKE_XCODE_ATTRIBUTE_DWARF_DSYM_FOLDER_PATH "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
5961
else()
6062
message(FATAL_ERROR "Unknown target platform: ${TARGET_PLATFORM}")
6163
return()
@@ -87,18 +89,16 @@ endif()
8789
if(ENABLE_JS_RUNTIME)
8890
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_JS_RUNTIME")
8991
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_JS_RUNTIME")
90-
elseif(TARGET_PLATFORM_MACOS)
91-
# If building a generic library for macOS, we'll build a dylib instead of a framework
92-
unset(BUILD_FRAMEWORK)
92+
else()
9393
set(GENERIC_NAPI TRUE)
9494
endif()
9595

9696
message(STATUS "TARGET_PLATFORM = ${TARGET_PLATFORM}")
9797
message(STATUS "TARGET_ENGINE = ${TARGET_ENGINE}")
9898
message(STATUS "ENABLE_JS_RUNTIME = ${ENABLE_JS_RUNTIME}")
99+
message(STATUS "GENERIC_NAPI = ${GENERIC_NAPI}")
99100

100101
# Set up sources
101-
102102
include_directories(
103103
./
104104
../metadata-generator/include
@@ -201,12 +201,14 @@ if(ENABLE_JS_RUNTIME)
201201
)
202202

203203
set(SOURCE_FILES ${SOURCE_FILES}
204+
204205
# quickjs
205206
napi/quickjs/source/cutils.c
206207
napi/quickjs/source/libregexp.c
207208
napi/quickjs/source/libbf.c
208209
napi/quickjs/source/libunicode.c
209210
napi/quickjs/source/quickjs.c
211+
210212
# napi
211213
napi/quickjs/quickjs-api.c
212214
napi/quickjs/jsr.cpp
@@ -223,7 +225,6 @@ if(ENABLE_JS_RUNTIME)
223225
napi/jsc/jsc-api.cpp
224226
napi/jsc/jsr.cpp
225227
)
226-
227228
endif()
228229
else()
229230
include_directories(
@@ -239,7 +240,6 @@ if(BUILD_CLI_BINARY)
239240
endif()
240241

241242
# Find SDK
242-
243243
find_program(XCODEBUILD_EXECUTABLE xcodebuild)
244244

245245
if(METADATA_SIZE EQUAL 0)
@@ -265,7 +265,6 @@ set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "")
265265
message(STATUS "SDK = ${CMAKE_OSX_SYSROOT}")
266266

267267
# Build targets
268-
269268
if(BUILD_CLI_BINARY)
270269
add_executable(${NAME} ${SOURCE_FILES})
271270
else()
@@ -301,11 +300,22 @@ endif()
301300

302301
if(TARGET_PLATFORM_MACOS)
303302
# add_custom_command(TARGET ${NAME} POST_BUILD
304-
# COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
303+
# COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
305304
# )
306305

306+
# Convert the Info.plist from binary format to XML format.
307+
# This seemed to unblock a build error when using in React Native.
308+
add_custom_command(TARGET ${NAME} POST_BUILD
309+
COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
310+
)
307311
set(METADATA_FILE "metadata.macos.nsmd")
308312
elseif(TARGET_PLATFORM_IOS)
313+
# Convert the Info.plist from binary format to XML format.
314+
# This seemed to unblock a build error when using in React Native.
315+
add_custom_command(TARGET ${NAME} POST_BUILD
316+
COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Info.plist
317+
)
318+
309319
if(TARGET_PLATFORM_SIM)
310320
set(METADATA_FILE "metadata.ios-sim.nsmd")
311321
else()
@@ -362,7 +372,7 @@ if(TARGET_ENGINE_JSC)
362372
endif()
363373

364374
if(TARGET_ENGINE_V8)
365-
if (TARGET_PLATFORM_MACOS)
375+
if(TARGET_PLATFORM_MACOS)
366376
target_link_directories(
367377
${NAME}
368378
PRIVATE
@@ -414,12 +424,12 @@ if(TARGET_ENGINE_QUICKJS)
414424
)
415425
endif()
416426

417-
# if (GENERIC_NAPI)
418-
target_link_options(
419-
${NAME}
420-
PRIVATE
421-
"-Wl"
422-
"-undefined"
423-
"dynamic_lookup"
424-
)
425-
# endif()
427+
if(GENERIC_NAPI)
428+
target_link_options(
429+
${NAME}
430+
PRIVATE
431+
"-Wl"
432+
"-undefined"
433+
"dynamic_lookup"
434+
)
435+
endif()

build_all_ios.sh

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
#!/bin/bash
22
set -e
3+
source "$(dirname "$0")/build_utils.sh"
4+
5+
TARGET_ENGINE=${TARGET_ENGINE:=some}
6+
BUILD_IPHONE=$(to_bool ${BUILD_IPHONE:=true})
7+
BUILD_SIMULATOR=$(to_bool ${BUILD_SIMULATOR:=true})
8+
BUILD_MACOS=$(to_bool ${BUILD_MACOS:=false})
9+
EMBED_METADATA=$(to_bool ${EMBED_METADATA:=false})
10+
11+
# See build_nativescript.sh for all supported flags. This parent script is only
12+
# interested in intercepting --no-engine.
13+
for arg in $@; do
14+
case $arg in
15+
--v8|--quickjs|--jsc|--hermes) TARGET_ENGINE=some ;;
16+
--sim|--simulator) BUILD_SIMULATOR=true ;;
17+
--no-sim|--no-simulator) BUILD_SIMULATOR=false ;;
18+
--iphone|--device) BUILD_IPHONE=true ;;
19+
--no-iphone|--no-device) BUILD_IPHONE=false ;;
20+
--macos) BUILD_MACOS=true ;;
21+
--no-macos) BUILD_MACOS=false ;;
22+
--no-engine) TARGET_ENGINE=none ;;
23+
--embed-metadata) EMBED_METADATA=true ;;
24+
*) ;;
25+
esac
26+
done
327

428
rm -rf ./dist
529
# don't run if NO_UPDATE_VERSION is set
@@ -8,7 +32,37 @@ rm -rf ./dist
832
# ./update_version.sh
933
# fi
1034
./build_metadata_generator.sh
11-
./build_nativescript.sh --no-vision $1 $2
12-
./build_tklivesync.sh --no-vision
13-
./prepare_dSYMs.sh
14-
./build_npm_ios.sh
35+
36+
if $EMBED_METADATA; then
37+
checkpoint "Generating metadata, as --embed-metadata was passed..."
38+
39+
if $BUILD_IPHONE; then
40+
checkpoint "Generating metadata for iOS (physical device)..."
41+
npm run metagen ios
42+
fi
43+
if $BUILD_SIMULATOR; then
44+
checkpoint "Generating metadata for iOS (simulator)..."
45+
npm run metagen ios-sim
46+
fi
47+
if $BUILD_MACOS; then
48+
checkpoint "Generating metadata for macOS..."
49+
npm run metagen macos
50+
fi
51+
52+
checkpoint "... All metadata generated!"
53+
fi
54+
55+
./build_nativescript.sh --no-vision $1 $2 $3 $4 $5 $6 $7 $8 $9
56+
57+
if [[ "$TARGET_ENGINE" == "none" ]]; then
58+
# If you're building *with* --no-engine, you're trying to make an npm release
59+
# of a workspace under ./packages/*, like @nativescript/ios-node-api.
60+
echo "Skipping build_npm_ios.sh due to --no-engine flag."
61+
echo "build_all_ios.sh finished!"
62+
else
63+
# If you're building *without* --no-engine, you're trying to make an npm
64+
# release of the root-level workspace, @nativescript/ios.
65+
./build_tklivesync.sh --no-vision
66+
./prepare_dSYMs.sh
67+
./build_npm_ios.sh
68+
fi

build_all_react_native.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
./build_all_ios.sh --no-engine --embed-metadata --macos

build_all_vision.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
#!/bin/bash
22
set -e
33

4+
TARGET_ENGINE=${TARGET_ENGINE:=v8} # default to v8 for compat
5+
6+
# See build_nativescript.sh for all supported flags. This parent script is only
7+
# interested in --no-engine.
8+
for arg in $@; do
9+
case $arg in
10+
--v8) TARGET_ENGINE=v8 ;;
11+
--quickjs) TARGET_ENGINE=quickjs ;;
12+
--jsc) TARGET_ENGINE=jsc ;;
13+
--hermes) TARGET_ENGINE=hermes ;;
14+
--no-engine) TARGET_ENGINE=none ;;
15+
*) ;;
16+
esac
17+
done
18+
419
rm -rf ./dist
520
./update_version.sh
621
./build_metadata_generator.sh
7-
./build_nativescript.sh --no-catalyst --no-iphone --no-sim
22+
./build_nativescript.sh --no-catalyst --no-iphone --no-sim $1
823
./build_tklivesync.sh --no-catalyst --no-iphone --no-sim
924
./prepare_dSYMs.sh
10-
./build_npm_vision.sh
25+
26+
if [[ "$TARGET_ENGINE" == "none" ]]; then
27+
# If you're building *with* --no-engine, you're trying to make an npm release
28+
# of a workspace under ./packages/*, like @nativescript/ios-node-api.
29+
echo "Skipping build_npm_vision.sh due to --no-engine flag."
30+
echo "build_all_vision.sh finished!"
31+
else
32+
# If you're building *without* --no-engine, you're trying to make an npm
33+
# release of the root-level workspace, @nativescript/ios.
34+
./build_npm_vision.sh
35+
fi

0 commit comments

Comments
 (0)