Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions NativeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ set(TARGET_ENGINE "v8" CACHE STRING "Target JS engine for the NativeScript runti
set(METADATA_SIZE 0 CACHE STRING "Size of embedded metadata in bytes")
set(BUILD_CLI_BINARY OFF CACHE BOOL "Build the NativeScript CLI binary")

if(CMAKE_OSX_SYSROOT STREQUAL "iphoneos")
set(TARGET_PLATFORM "ios")
elseif(CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator")
set(TARGET_PLATFORM "ios-sim")
elseif(CMAKE_OSX_SYSROOT STREQUAL "macosx")
set(TARGET_PLATFORM "macos")
endif()

if(TARGET_PLATFORM STREQUAL "ios")
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "13.0")
set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
Expand Down Expand Up @@ -305,16 +313,16 @@ if(TARGET_PLATFORM_MACOS)

# Convert the Info.plist from binary format to XML format.
# This seemed to unblock a build error when using in React Native.
add_custom_command(TARGET ${NAME} POST_BUILD
COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
)
# add_custom_command(TARGET ${NAME} POST_BUILD
# COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
# )
set(METADATA_FILE "metadata.macos.nsmd")
elseif(TARGET_PLATFORM_IOS)
# Convert the Info.plist from binary format to XML format.
# This seemed to unblock a build error when using in React Native.
add_custom_command(TARGET ${NAME} POST_BUILD
COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Info.plist
)
# add_custom_command(TARGET ${NAME} POST_BUILD
# COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Info.plist
# )

if(TARGET_PLATFORM_SIM)
set(METADATA_FILE "metadata.ios-sim.nsmd")
Expand Down
104 changes: 61 additions & 43 deletions build_nativescript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,60 @@ function cmake_build () {
cmake --build $DIST/intermediates/$platform --config $CONFIG_BUILD
}

TRIPLETS=()

if $BUILD_CATALYST; then
checkpoint "Building NativeScript for Mac Catalyst"

# cmake_build catalyst x86_64 arm64

fi

if $BUILD_SIMULATOR; then
checkpoint "Building NativeScript for iPhone (simulator)"
if [[ $BUILD_SIMULATOR && "$TARGET_ENGINE" == "none" ]]; then
# TODO: Add x86_64-apple-ios-sim once supported
TRIPLETS+=("arm64-apple-ios-sim")
elif $BUILD_SIMULATOR; then
checkpoint "Building NativeScript for iPhone (simulator)"

cmake_build ios-sim x86_64 arm64
cmake_build ios-sim x86_64 arm64

fi

if $BUILD_IPHONE; then
checkpoint "Building NativeScript for iPhone (physical)"
if [[ $BUILD_IPHONE && "$TARGET_ENGINE" == "none" ]]; then
TRIPLETS+=("arm64-apple-ios")

elif $BUILD_IPHONE; then
checkpoint "Building NativeScript for iPhone (physical)"

cmake_build ios arm64
cmake_build ios arm64

fi

if $BUILD_MACOS; then
checkpoint "Building NativeScript for macOS"
if [[ $BUILD_MACOS && "$TARGET_ENGINE" == "none" ]]; then
TRIPLETS+=("arm64;x86_64-apple-darwin")

cmake_build macos x86_64 arm64
elif $BUILD_MACOS; then
checkpoint "Building NativeScript for macOS"
cmake_build macos x86_64 arm64

fi

if $BUILD_VISION; then
if [[ $BUILD_VISION && "$TARGET_ENGINE" == "none" ]]; then
# TRIPLETS+=("arm64-apple-visionos")
# TODO: Add x86_64-apple-visionos-sim once supported
# TRIPLETS+=("x86_64-apple-visionos-sim")
# TRIPLETS+=("arm64-apple-visionos-sim")
echo "Skipping visionOS prebuilds for React Native Node-API as they are not yet supported."

elif $BUILD_VISION; then

checkpoint "Building NativeScript for visionOS (physical)"
checkpoint "Building NativeScript for visionOS (physical)"

# cmake_build visionos arm64
# cmake_build visionos arm64

checkpoint "Building NativeScript for visionOS (simulator)"
checkpoint "Building NativeScript for visionOS (simulator)"

# cmake_build visionos-sim x86_64 arm64
# cmake_build visionos-sim x86_64 arm64

fi

Expand Down Expand Up @@ -151,45 +168,46 @@ if $BUILD_VISION; then
-debug-symbols "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
fi

if [[ -n "${XCFRAMEWORKS[@]}" ]]; then
if [[ "$TARGET_ENGINE" == "none" ]]; then
checkpoint "Creating the XCFramework for iOS (NativeScript.apple.node)"

# We adhere to the prebuilds standard as described here:
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
OUTPUT_DIR="packages/ios/build/$CONFIG_BUILD/NativeScript.apple.node"
rm -rf $OUTPUT_DIR
deno run -A ./scripts/build_xcframework.mts --output "$OUTPUT_DIR" ${XCFRAMEWORKS[@]}
else
checkpoint "Creating NativeScript.xcframework"

OUTPUT_DIR="$DIST/NativeScript.xcframework"
rm -rf $OUTPUT_DIR
xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR"
fi
if [[ -n "${XCFRAMEWORKS[@]}" && "$TARGET_ENGINE" != "none" ]]; then
checkpoint "Creating NativeScript.xcframework"

OUTPUT_DIR="$DIST/NativeScript.xcframework"
rm -rf $OUTPUT_DIR
xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR"
fi

if [[ -n "${TRIPLETS[@]}" && "$TARGET_ENGINE" == "none" ]]; then
checkpoint "Building NativeScript prebuilt for React Native Node-API (NativeScript.apple.node)"

TRIPLET_ARGS=()
for triplet in "${TRIPLETS[@]}"; do
TRIPLET_ARGS+=(--triplet "$triplet")
done

# We adhere to the prebuilds standard as described here:
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
OUTPUT_DIR="packages/ios/build/$CONFIG_BUILD"
cmake-rn --source ./NativeScript --build "$DIST/intermediates" --out "$OUTPUT_DIR" -D TARGET_ENGINE=$TARGET_ENGINE "${TRIPLET_ARGS[@]}"
fi

# We're currently distributing two separate packages:
# 1. UIKit-based (@nativescript/ios-node-api)
# 2. AppKit-based (@nativescript/macos-node-api)
# As such, there's no point bundling both UIKit-based and AppKit-based into a
# single XCFramework.
if $BUILD_MACOS; then
if [[ $BUILD_MACOS && "$TARGET_ENGINE" == "none" ]]; then
checkpoint "Creating the XCFramework for macOS (NativeScript.apple.node)"

OUTPUT_DIR="packages/macos/build/$CONFIG_BUILD"
cmake-rn --source ./NativeScript --build "$DIST/intermediates" --out "$OUTPUT_DIR" -D TARGET_ENGINE=$TARGET_ENGINE --triplet 'arm64;x86_64-apple-darwin'

elif $BUILD_MACOS; then
XCFRAMEWORKS=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )

if [[ "$TARGET_ENGINE" == "none" ]]; then
checkpoint "Creating the XCFramework for macOS (NativeScript.apple.node)"

# We adhere to the prebuilds standard as described here:
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
OUTPUT_DIR="packages/macos/build/$CONFIG_BUILD/NativeScript.apple.node"
rm -rf $OUTPUT_DIR
deno run -A ./scripts/build_xcframework.mts --output "$OUTPUT_DIR" ${XCFRAMEWORKS[@]}
else
checkpoint "Creating NativeScript.node for macOS"
cp -r "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/NativeScript.node"
fi

checkpoint "Creating NativeScript.node for macOS"
cp -r "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/NativeScript.node"
fi

if $BUILD_MACOS_CLI; then
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"cmake-rn": "^0.5.1",
"conventional-changelog-cli": "^2.1.1",
"dayjs": "^1.11.7",
"husky": "^9.0.11",
Expand Down
124 changes: 0 additions & 124 deletions scripts/build_xcframework.mts

This file was deleted.