Skip to content

Commit a1cdb90

Browse files
committed
chore: improve build scripts
1 parent fd4b13a commit a1cdb90

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

NativeScript/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ set(TARGET_PLATFORM "macos" CACHE STRING "Target platform for the Objective-C br
2020
set(TARGET_ENGINE "v8" CACHE STRING "Target JS engine for the NativeScript runtime")
2121
set(METADATA_SIZE 0 CACHE STRING "Size of embedded metadata in bytes")
2222
set(BUILD_CLI_BINARY OFF CACHE BOOL "Build the NativeScript CLI binary")
23+
set(BUILD_MACOS_NODE_API OFF CACHE BOOL "Build the NativeScript macOS Node API dylib")
24+
25+
if (BUILD_MACOS_NODE_API)
26+
set(BUILD_FRAMEWORK OFF)
27+
endif()
2328

2429
if(TARGET_PLATFORM STREQUAL "ios")
2530
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "13.0")
@@ -93,6 +98,10 @@ else()
9398
set(GENERIC_NAPI TRUE)
9499
endif()
95100

101+
if(BUILD_MACOS_NODE_API)
102+
set(GENERIC_NAPI TRUE)
103+
endif()
104+
96105
message(STATUS "TARGET_PLATFORM = ${TARGET_PLATFORM}")
97106
message(STATUS "TARGET_ENGINE = ${TARGET_ENGINE}")
98107
message(STATUS "ENABLE_JS_RUNTIME = ${ENABLE_JS_RUNTIME}")

build_nativescript.sh

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BUILD_VISION=$(to_bool ${BUILD_VISION:=false}) # disable by default for now
99
BUILD_MACOS=$(to_bool ${BUILD_MACOS:=false}) # disable by default for now
1010
VERBOSE=$(to_bool ${VERBOSE:=false})
1111
BUILD_MACOS_CLI=$(to_bool ${BUILD_MACOS_CLI:=false})
12+
BUILD_MACOS_NODE_API=$(to_bool ${BUILD_MACOS_NODE_API:=false})
1213
EMBED_METADATA=$(to_bool ${EMBED_METADATA:=false})
1314
CONFIG_BUILD=RelWithDebInfo
1415

@@ -22,11 +23,13 @@ for arg in $@; do
2223
--sim|--simulator) BUILD_SIMULATOR=true ;;
2324
--no-sim|--no-simulator) BUILD_SIMULATOR=false ;;
2425
--iphone|--device) BUILD_IPHONE=true ;;
25-
--no-iphone|--no-device) BUILD_IPHONE=false ;;
26+
--no-iphone|--no-device|--no-phone|--no-ios) BUILD_IPHONE=false ;;
2627
--xr|--vision) BUILD_VISION=true ;;
2728
--no-xr|--no-vision) BUILD_VISION=false ;;
2829
--macos) BUILD_MACOS=true ;;
2930
--no-macos) BUILD_MACOS=false ;;
31+
--macos-napi) BUILD_MACOS_NODE_API=true ;;
32+
--no-macos-napi) BUILD_MACOS_NODE_API=false ;;
3033
--macos-cli) BUILD_MACOS_CLI=true ;;
3134
--no-macos-cli) BUILD_MACOS_CLI=false ;;
3235
--verbose|-v) VERBOSE=true ;;
@@ -35,7 +38,7 @@ for arg in $@; do
3538
--jsc) TARGET_ENGINE=jsc ;;
3639
--embed-metadata) EMBED_METADATA=true ;;
3740
--hermes) TARGET_ENGINE=hermes ;;
38-
--no-engine) TARGET_ENGINE=none ;;
41+
--no-engine|--generic-napi) TARGET_ENGINE=none ;;
3942
*) ;;
4043
esac
4144
done
@@ -62,9 +65,14 @@ function cmake_build () {
6265
is_macos_cli=true
6366
fi
6467

68+
if [ "$platform" == "macos-napi" ]; then
69+
platform="macos"
70+
is_macos_napi=true
71+
fi
72+
6573
mkdir -p $DIST/intermediates/$platform
6674

67-
if $EMBED_METADATA || $is_macos_cli; then
75+
if $EMBED_METADATA || $is_macos_cli || $is_macos_napi; then
6876

6977
for arch in "${archs[@]}"; do
7078

@@ -74,7 +82,7 @@ function cmake_build () {
7482

7583
fi
7684

77-
cmake -S=./NativeScript -B=$DIST/intermediates/$platform -GXcode -DTARGET_PLATFORM=$platform -DTARGET_ENGINE=$TARGET_ENGINE -DMETADATA_SIZE=$METADATA_SIZE -DBUILD_CLI_BINARY=$is_macos_cli
85+
cmake -S=./NativeScript -B=$DIST/intermediates/$platform -GXcode -DTARGET_PLATFORM=$platform -DTARGET_ENGINE=$TARGET_ENGINE -DMETADATA_SIZE=$METADATA_SIZE -DBUILD_CLI_BINARY=$is_macos_cli -DBUILD_MACOS_NODE_API=$is_macos_napi
7886

7987
cmake --build $DIST/intermediates/$platform --config $CONFIG_BUILD
8088
}
@@ -127,6 +135,12 @@ cmake_build macos-cli x86_64 arm64
127135

128136
fi
129137

138+
if $BUILD_MACOS_NODE_API; then
139+
checkpoint "Building NativeScript for macOS Node API"
140+
141+
cmake_build macos-napi x86_64 arm64
142+
fi
143+
130144
XCFRAMEWORKS=()
131145
if $BUILD_CATALYST; then
132146
XCFRAMEWORKS+=( -framework "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework"
@@ -143,6 +157,11 @@ if $BUILD_IPHONE; then
143157
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
144158
fi
145159

160+
if $BUILD_MACOS; then
161+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
162+
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
163+
fi
164+
146165
if $BUILD_VISION; then
147166
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
148167
-debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
@@ -175,9 +194,6 @@ fi
175194
# As such, there's no point bundling both UIKit-based and AppKit-based into a
176195
# single XCFramework.
177196
if $BUILD_MACOS; then
178-
XCFRAMEWORKS=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
179-
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
180-
181197
if [[ "$TARGET_ENGINE" == "none" ]]; then
182198
checkpoint "Creating the XCFramework for macOS (NativeScript.apple.node)"
183199

@@ -186,12 +202,14 @@ if $BUILD_MACOS; then
186202
OUTPUT_DIR="packages/macos/build/$CONFIG_BUILD/NativeScript.apple.node"
187203
rm -rf $OUTPUT_DIR
188204
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"
192205
fi
193206
fi
194207

208+
if $BUILD_MACOS_NODE_API; then
209+
checkpoint "Creating NativeScript.node for macOS"
210+
cp -r "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/NativeScript.node"
211+
fi
212+
195213
if $BUILD_MACOS_CLI; then
196214

197215
checkpoint "Creating NativeScript CLI"

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@
2828
"update-version": "./update_version.sh",
2929
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
3030
"version": "npm run changelog && git add CHANGELOG.md",
31-
"metagen": "node scripts/metagen.js",
3231
"build-libffi": "node scripts/build_libffi.js",
3332
"build-metagen": "./build_metadata_generator.sh",
34-
"build": "./build_nativescript.sh --quickjs"
33+
"metagen": "node scripts/metagen.js",
34+
"build": "./build_nativescript.sh",
35+
"build:ios": "./build_nativescript.sh --iphone --no-simulator",
36+
"build:ios-sim": "./build_nativescript.sh --no-iphone --simulator",
37+
"build:macos": "./build_nativescript.sh --macos --no-iphone --no-simulator",
38+
"build:macos-cli": "./build_nativescript.sh --no-iphone --no-simulator --macos-cli",
39+
"build:macos-napi": "./build_nativescript.sh --no-iphone --no-simulator --macos-napi",
40+
"nsr": "./dist/nsr"
3541
},
3642
"license": "Apache-2.0",
3743
"devDependencies": {

0 commit comments

Comments
 (0)