22set -e
33source " $( 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-
265BUILD_CATALYST=$( to_bool ${BUILD_CATALYST:= false} ) # disable by default for now
276BUILD_IPHONE=$( to_bool ${BUILD_IPHONE:= true} )
287BUILD_SIMULATOR=$( to_bool ${BUILD_SIMULATOR:= true} )
@@ -74,6 +53,8 @@ mkdir -p $DIST/intermediates
7453
7554function 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 () {
10182if $BUILD_CATALYST ; then
10283checkpoint " Building NativeScript for Mac Catalyst"
10384
104- # cmake_build catalyst
85+ # cmake_build catalyst x86_64 arm64
10586
10687fi
10788
10889if $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
11394fi
11495
11596if $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
120101fi
121102
122103if $BUILD_MACOS ; then
123104checkpoint " 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
129108fi
130109
131110if $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
141120fi
142121
143122if $BUILD_MACOS_CLI ; then
144123
145124checkpoint " Building NativeScript for macOS CLI"
146125
147- cmake_build macos-cli
126+ cmake_build macos-cli x86_64 arm64
148127
149128fi
150129
@@ -164,7 +143,6 @@ if $BUILD_IPHONE; then
164143 -debug-symbols " $DIST /intermediates/ios/$CONFIG_BUILD -iphoneos/NativeScript.framework.dSYM" )
165144fi
166145
167-
168146if $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
174152fi
175153
176154if [[ -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
183170fi
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.
185177if $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
191193fi
192194
193195if $BUILD_MACOS_CLI ; then
0 commit comments