Skip to content

Commit cd67c22

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

File tree

454 files changed

+150511
-126423
lines changed

Some content is hidden

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

454 files changed

+150511
-126423
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 a subset of them.
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_nativescript.sh

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@
22
set -e
33
source "$(dirname "$0")/build_utils.sh"
44

5-
function to_bool() {
6-
local arg="$1"
7-
case "$(echo "$arg" | tr '[:upper:]' '[:lower:]')" in
8-
[0-9]+)
9-
if [ $arg -eq 0 ]; then
10-
echo false
11-
else
12-
echo true
13-
fi
14-
;;
15-
n|no|f|false) echo false ;;
16-
y|yes|t|true) echo true ;;
17-
* )
18-
if [ -n "$arg" ]; then
19-
echo "warning: invalid boolean argument ('$arg'). Expected true or false" >&2
20-
fi
21-
echo false
22-
;;
23-
esac;
24-
}
25-
265
BUILD_CATALYST=$(to_bool ${BUILD_CATALYST:=false}) # disable by default for now
276
BUILD_IPHONE=$(to_bool ${BUILD_IPHONE:=true})
287
BUILD_SIMULATOR=$(to_bool ${BUILD_SIMULATOR:=true})
@@ -74,6 +53,8 @@ mkdir -p $DIST/intermediates
7453

7554
function cmake_build () {
7655
local platform="$1"
56+
shift
57+
local archs=("$@")
7758
local is_macos_cli=false
7859

7960
if [ "$platform" == "macos-cli" ]; then
@@ -85,7 +66,7 @@ function cmake_build () {
8566

8667
if $EMBED_METADATA || $is_macos_cli; then
8768

88-
for arch in x86_64 arm64; do
69+
for arch in "${archs[@]}"; do
8970

9071
METADATA_SIZE=$(($METADATA_SIZE > $(stat -f%z "./metadata-generator/metadata/metadata.$platform.$arch.nsmd") ? $METADATA_SIZE : $(stat -f%z "./metadata-generator/metadata/metadata.$platform.$arch.nsmd")))
9172

@@ -101,50 +82,48 @@ function cmake_build () {
10182
if $BUILD_CATALYST; then
10283
checkpoint "Building NativeScript for Mac Catalyst"
10384

104-
# cmake_build catalyst
85+
# cmake_build catalyst x86_64 arm64
10586

10687
fi
10788

10889
if $BUILD_SIMULATOR; then
109-
checkpoint "Building NativeScript for iphone simulators (multi-arch)"
90+
checkpoint "Building NativeScript for iPhone (simulator)"
11091

111-
cmake_build ios-sim
92+
cmake_build ios-sim x86_64 arm64
11293

11394
fi
11495

11596
if $BUILD_IPHONE; then
116-
checkpoint "Building NativeScript for ARM64 device"
97+
checkpoint "Building NativeScript for iPhone (physical)"
11798

118-
cmake_build ios
99+
cmake_build ios arm64
119100

120101
fi
121102

122103
if $BUILD_MACOS; then
123104
checkpoint "Building NativeScript for macOS"
124105

125-
cmake_build macos
126-
127-
cp "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/../packages/macos/dist/macos/NativeScript.node"
106+
cmake_build macos x86_64 arm64
128107

129108
fi
130109

131110
if $BUILD_VISION; then
132111

133-
checkpoint "Building NativeScript for visionOS Device"
112+
checkpoint "Building NativeScript for visionOS (physical)"
134113

135-
# cmake_build visionos
114+
# cmake_build visionos arm64
136115

137-
checkpoint "Building NativeScript for visionOS Simulators"
116+
checkpoint "Building NativeScript for visionOS (simulator)"
138117

139-
# cmake_build visionos-sim
118+
# cmake_build visionos-sim x86_64 arm64
140119

141120
fi
142121

143122
if $BUILD_MACOS_CLI; then
144123

145124
checkpoint "Building NativeScript for macOS CLI"
146125

147-
cmake_build macos-cli
126+
cmake_build macos-cli x86_64 arm64
148127

149128
fi
150129

@@ -164,7 +143,6 @@ if $BUILD_IPHONE; then
164143
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
165144
fi
166145

167-
168146
if $BUILD_VISION; then
169147
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
170148
-debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
@@ -174,20 +152,44 @@ if $BUILD_VISION; then
174152
fi
175153

176154
if [[ -n "${XCFRAMEWORKS[@]}" ]]; then
177-
178-
checkpoint "Creating NativeScript.xcframework"
179-
OUTPUT_DIR="$DIST/NativeScript.xcframework"
180-
rm -rf $OUTPUT_DIR
181-
xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR"
182-
155+
if [[ "$TARGET_ENGINE" == "none" ]]; then
156+
checkpoint "Creating the XCFramework for iOS (NativeScript.apple.node)"
157+
158+
# We adhere to the prebuilds standard as described here:
159+
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
160+
OUTPUT_DIR="packages/ios/build/$CONFIG_BUILD/NativeScript.apple.node"
161+
rm -rf $OUTPUT_DIR
162+
deno run -A ./scripts/build_xcframework.mts --output "$OUTPUT_DIR" ${XCFRAMEWORKS[@]}
163+
else
164+
checkpoint "Creating NativeScript.xcframework"
165+
166+
OUTPUT_DIR="$DIST/NativeScript.xcframework"
167+
rm -rf $OUTPUT_DIR
168+
xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR"
169+
fi
183170
fi
184171

172+
# We're currently distributing two separate packages:
173+
# 1. UIKit-based (@nativescript/ios-node-api)
174+
# 2. AppKit-based (@nativescript/macos-node-api)
175+
# As such, there's no point bundling both UIKit-based and AppKit-based into a
176+
# single XCFramework.
185177
if $BUILD_MACOS; then
186-
187-
checkpoint "Creating NativeScript.node"
188-
189-
cp -r "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/NativeScript.node"
190-
178+
XCFRAMEWORKS=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
179+
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
180+
181+
if [[ "$TARGET_ENGINE" == "none" ]]; then
182+
checkpoint "Creating the XCFramework for macOS (NativeScript.apple.node)"
183+
184+
# We adhere to the prebuilds standard as described here:
185+
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
186+
OUTPUT_DIR="packages/macos/build/$CONFIG_BUILD/NativeScript.apple.node"
187+
rm -rf $OUTPUT_DIR
188+
deno run -A ./scripts/build_xcframework.mts --output "$OUTPUT_DIR" ${XCFRAMEWORKS[@]}
189+
else
190+
checkpoint "Creating NativeScript.node for macOS"
191+
cp -r "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/NativeScript.node"
192+
fi
191193
fi
192194

193195
if $BUILD_MACOS_CLI; then

0 commit comments

Comments
 (0)