diff --git a/NativeScript/CMakeLists.txt b/NativeScript/CMakeLists.txt index 56f4c2cf..a62b13db 100644 --- a/NativeScript/CMakeLists.txt +++ b/NativeScript/CMakeLists.txt @@ -305,6 +305,12 @@ if(TARGET_PLATFORM_MACOS) 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 $/Info.plist + ) + if(TARGET_PLATFORM_SIM) set(METADATA_FILE "metadata.ios-sim.nsmd") else() diff --git a/build_all_ios.sh b/build_all_ios.sh index d5ad6548..c4845604 100755 --- a/build_all_ios.sh +++ b/build_all_ios.sh @@ -1,6 +1,21 @@ #!/bin/bash set -e +TARGET_ENGINE=${TARGET_ENGINE:=v8} # default to v8 for compat + +# See build_nativescript.sh for all supported flags. This parent script is only +# interested in --no-engine. +for arg in $@; do + case $arg in + --v8) TARGET_ENGINE=v8 ;; + --quickjs) TARGET_ENGINE=quickjs ;; + --jsc) TARGET_ENGINE=jsc ;; + --hermes) TARGET_ENGINE=hermes ;; + --no-engine) TARGET_ENGINE=none ;; + *) ;; + esac +done + rm -rf ./dist # don't run if NO_UPDATE_VERSION is set # if [ -z "$NO_UPDATE_VERSION" ]; then @@ -8,7 +23,17 @@ rm -rf ./dist # ./update_version.sh # fi ./build_metadata_generator.sh -./build_nativescript.sh --no-vision $1 +./build_nativescript.sh --no-vision $1 $2 ./build_tklivesync.sh --no-vision ./prepare_dSYMs.sh -./build_npm_ios.sh \ No newline at end of file + +if [[ "$TARGET_ENGINE" == "none" ]]; then + # If you're building *with* --no-engine, you're trying to make an npm release + # of a workspace under ./packages/*, like @nativescript/ios-node-api. + echo "Skipping build_npm_ios.sh due to --no-engine flag." + echo "build_all_ios.sh finished!" +else + # If you're building *without* --no-engine, you're trying to make an npm + # release of the root-level workspace, @nativescript/ios. + ./build_npm_ios.sh +fi \ No newline at end of file diff --git a/build_all_vision.sh b/build_all_vision.sh index f5d1bd40..d8116418 100755 --- a/build_all_vision.sh +++ b/build_all_vision.sh @@ -1,10 +1,35 @@ #!/bin/bash set -e +TARGET_ENGINE=${TARGET_ENGINE:=v8} # default to v8 for compat + +# See build_nativescript.sh for all supported flags. This parent script is only +# interested in --no-engine. +for arg in $@; do + case $arg in + --v8) TARGET_ENGINE=v8 ;; + --quickjs) TARGET_ENGINE=quickjs ;; + --jsc) TARGET_ENGINE=jsc ;; + --hermes) TARGET_ENGINE=hermes ;; + --no-engine) TARGET_ENGINE=none ;; + *) ;; + esac +done + rm -rf ./dist ./update_version.sh ./build_metadata_generator.sh -./build_nativescript.sh --no-catalyst --no-iphone --no-sim +./build_nativescript.sh --no-catalyst --no-iphone --no-sim $1 ./build_tklivesync.sh --no-catalyst --no-iphone --no-sim ./prepare_dSYMs.sh -./build_npm_vision.sh \ No newline at end of file + +if [[ "$TARGET_ENGINE" == "none" ]]; then + # If you're building *with* --no-engine, you're trying to make an npm release + # of a workspace under ./packages/*, like @nativescript/ios-node-api. + echo "Skipping build_npm_vision.sh due to --no-engine flag." + echo "build_all_vision.sh finished!" +else + # If you're building *without* --no-engine, you're trying to make an npm + # release of the root-level workspace, @nativescript/ios. + ./build_npm_vision.sh +fi \ No newline at end of file diff --git a/build_nativescript.sh b/build_nativescript.sh index 3dd04cd3..438e9443 100755 --- a/build_nativescript.sh +++ b/build_nativescript.sh @@ -177,10 +177,22 @@ fi if [[ -n "${XCFRAMEWORKS[@]}" ]]; then -checkpoint "Creating NativeScript.xcframework" -OUTPUT_DIR="$DIST/NativeScript.xcframework" -rm -rf $OUTPUT_DIR -xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR" + +if [[ "$TARGET_ENGINE" == "none" ]]; then + checkpoint "Creating the XCFramework (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/Release/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 fi diff --git a/packages/ios/.gitignore b/packages/ios/.gitignore new file mode 100644 index 00000000..684ae5d8 --- /dev/null +++ b/packages/ios/.gitignore @@ -0,0 +1 @@ +!build \ No newline at end of file diff --git a/packages/ios/NativeScript.podspec b/packages/ios/NativeScript.podspec deleted file mode 100644 index 51a19515..00000000 --- a/packages/ios/NativeScript.podspec +++ /dev/null @@ -1,14 +0,0 @@ -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "package.json"))) - -Pod::Spec.new do |s| - s.name = "NativeScript" - s.version = package['version'] - s.summary = "An embeddable, engine-agnostic NativeScript runtime for iOS based on Node-API" - s.homepage = "https://github.com/NativeScript/runtime-node-api.git" - s.author = "DjDeveloperr", "Jamie Birch" - s.source = { git: '' } - s.vendored_frameworks = "build/ios-universal/NativeScript.xcframework" - s.platform = :ios, '13.4' -end diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/Info.plist b/packages/ios/build/Release/NativeScript.apple.node/Info.plist similarity index 100% rename from packages/ios/dist/ios-universal/NativeScript.xcframework/Info.plist rename to packages/ios/build/Release/NativeScript.apple.node/Info.plist index 2d891332..66a43844 100644 --- a/packages/ios/dist/ios-universal/NativeScript.xcframework/Info.plist +++ b/packages/ios/build/Release/NativeScript.apple.node/Info.plist @@ -8,32 +8,32 @@ BinaryPath NativeScript.framework/NativeScript LibraryIdentifier - ios-arm64 + ios-arm64_x86_64-simulator LibraryPath NativeScript.framework SupportedArchitectures arm64 + x86_64 SupportedPlatform ios + SupportedPlatformVariant + simulator BinaryPath NativeScript.framework/NativeScript LibraryIdentifier - ios-arm64_x86_64-simulator + ios-arm64 LibraryPath NativeScript.framework SupportedArchitectures arm64 - x86_64 SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Headers/NativeScript.h b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Headers/NativeScript.h new file mode 100644 index 00000000..32802134 --- /dev/null +++ b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Headers/NativeScript.h @@ -0,0 +1,48 @@ +#ifndef NATIVESCRIPT_H +#define NATIVESCRIPT_H + +#ifdef __cplusplus + +extern "C" + +#endif // __cplusplus + + void + nativescript_init(void* env, const char* metadata_path, const void* metadata_ptr); + +#ifdef __OBJC__ + +#import + +__attribute__((visibility("default"))) +@interface Config : NSObject + +@property(nonatomic, retain) NSString* BaseDir; +@property(nonatomic, retain) NSString* ApplicationPath; +@property(nonatomic) void* MetadataPtr; +@property BOOL IsDebug; +@property BOOL LogToSystemConsole; +@property int ArgumentsCount; +@property(nonatomic) char** Arguments; + +@end + +__attribute__((visibility("default"))) +@interface NativeScript : NSObject + +- (instancetype)initWithConfig:(Config*)config; +- (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop; +- (void)restartWithConfig:(Config*)config; +- (void)shutdownRuntime; + +/** + WARNING: this method does not return in most applications. (UIApplicationMain) + */ +- (void)runMainApplication; +- (bool)liveSync; + +@end + +#endif // __OBJC__ + +#endif /* NATIVESCRIPT_H */ diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Info.plist b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Info.plist new file mode 100644 index 00000000..5b55eb49 --- /dev/null +++ b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/Info.plist @@ -0,0 +1,57 @@ + + + + + BuildMachineOSBuild + 23G93 + CFBundleDevelopmentRegion + English + CFBundleExecutable + NativeScript + CFBundleIdentifier + org.nativescript.runtime + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleShortVersionString + 0.1.0 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + iPhoneOS + + CFBundleVersion + 0.1.0 + CSResourcesFileMapped + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 22C146 + DTPlatformName + iphoneos + DTPlatformVersion + 18.2 + DTSDKBuild + 22C146 + DTSDKName + iphoneos18.2 + DTXcode + 1620 + DTXcodeBuild + 16C5032a + MinimumOSVersion + 13.0 + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + + diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/NativeScript b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/NativeScript new file mode 100755 index 00000000..2170e2a5 Binary files /dev/null and b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64/NativeScript.framework/NativeScript differ diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h new file mode 100644 index 00000000..32802134 --- /dev/null +++ b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h @@ -0,0 +1,48 @@ +#ifndef NATIVESCRIPT_H +#define NATIVESCRIPT_H + +#ifdef __cplusplus + +extern "C" + +#endif // __cplusplus + + void + nativescript_init(void* env, const char* metadata_path, const void* metadata_ptr); + +#ifdef __OBJC__ + +#import + +__attribute__((visibility("default"))) +@interface Config : NSObject + +@property(nonatomic, retain) NSString* BaseDir; +@property(nonatomic, retain) NSString* ApplicationPath; +@property(nonatomic) void* MetadataPtr; +@property BOOL IsDebug; +@property BOOL LogToSystemConsole; +@property int ArgumentsCount; +@property(nonatomic) char** Arguments; + +@end + +__attribute__((visibility("default"))) +@interface NativeScript : NSObject + +- (instancetype)initWithConfig:(Config*)config; +- (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop; +- (void)restartWithConfig:(Config*)config; +- (void)shutdownRuntime; + +/** + WARNING: this method does not return in most applications. (UIApplicationMain) + */ +- (void)runMainApplication; +- (bool)liveSync; + +@end + +#endif // __OBJC__ + +#endif /* NATIVESCRIPT_H */ diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist new file mode 100644 index 00000000..1fb67bbb --- /dev/null +++ b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist @@ -0,0 +1,53 @@ + + + + + BuildMachineOSBuild + 23G93 + CFBundleDevelopmentRegion + English + CFBundleExecutable + NativeScript + CFBundleIdentifier + org.nativescript.runtime + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleShortVersionString + 0.1.0 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + iPhoneSimulator + + CFBundleVersion + 0.1.0 + CSResourcesFileMapped + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 22C146 + DTPlatformName + iphonesimulator + DTPlatformVersion + 18.2 + DTSDKBuild + 22C146 + DTSDKName + iphonesimulator18.2 + DTXcode + 1620 + DTXcodeBuild + 16C5032a + MinimumOSVersion + 13.0 + UIDeviceFamily + + 1 + 2 + + + diff --git a/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript new file mode 100755 index 00000000..87590268 Binary files /dev/null and b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript differ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/_CodeSignature/CodeResources b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources similarity index 94% rename from packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/_CodeSignature/CodeResources rename to packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources index 88ba37ed..bbfc1afb 100644 --- a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/_CodeSignature/CodeResources +++ b/packages/ios/build/Release/NativeScript.apple.node/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources @@ -6,11 +6,11 @@ Headers/NativeScript.h - hv9kw9yeSQfQSsL9hhNjAnfiwYg= + 39ICnat7eEdDM8V81X+AgQ8An7I= Info.plist - P0o6/krbAZmvndbb7mb0+Ma1edA= + zBZoNBpj08SoKa8RFtrh7RpaZVQ= files2 @@ -19,7 +19,7 @@ hash2 - e1+RNHPOYCS4IO10Ivc416EzR0zr2gXGvdF7Ay1itw8= + b2VIqZHl3+JydH2yR49bt1Gfz27RYQtgJNc6pl/6RdA= diff --git a/packages/ios/build/Release/NativeScript.apple.node/react-native-node-api-module b/packages/ios/build/Release/NativeScript.apple.node/react-native-node-api-module new file mode 100644 index 00000000..e69de29b diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Headers/NativeScript.h b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Headers/NativeScript.h deleted file mode 100644 index 0b3d7712..00000000 --- a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Headers/NativeScript.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef NATIVESCRIPT_H -#define NATIVESCRIPT_H - -extern "C" void objc_bridge_init(void *env, const char *metadata_path); - -#endif /* NATIVESCRIPT_H */ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Info.plist b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Info.plist deleted file mode 100644 index b05c8dff..00000000 Binary files a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/Info.plist and /dev/null differ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/NativeScript b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/NativeScript deleted file mode 100755 index 5b858f98..00000000 Binary files a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64/NativeScript.framework/NativeScript and /dev/null differ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h deleted file mode 100644 index 0b3d7712..00000000 --- a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Headers/NativeScript.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef NATIVESCRIPT_H -#define NATIVESCRIPT_H - -extern "C" void objc_bridge_init(void *env, const char *metadata_path); - -#endif /* NATIVESCRIPT_H */ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist deleted file mode 100644 index 4e753029..00000000 Binary files a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/Info.plist and /dev/null differ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript deleted file mode 100755 index b3c22741..00000000 Binary files a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/NativeScript and /dev/null differ diff --git a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources b/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources deleted file mode 100644 index b6583cd7..00000000 --- a/packages/ios/dist/ios-universal/NativeScript.xcframework/ios-arm64_x86_64-simulator/NativeScript.framework/_CodeSignature/CodeResources +++ /dev/null @@ -1,113 +0,0 @@ - - - - - files - - Headers/NativeScript.h - - hv9kw9yeSQfQSsL9hhNjAnfiwYg= - - Info.plist - - AnVo34/si2OHuSyg5ZuQDFsSo0w= - - - files2 - - Headers/NativeScript.h - - hash2 - - e1+RNHPOYCS4IO10Ivc416EzR0zr2gXGvdF7Ay1itw8= - - - - rules - - ^.* - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^Base\.lproj/ - - weight - 1010 - - ^version.plist$ - - - rules2 - - .*\.dSYM($|/) - - weight - 11 - - ^(.*/)?\.DS_Store$ - - omit - - weight - 2000 - - ^.* - - ^.*\.lproj/ - - optional - - weight - 1000 - - ^.*\.lproj/locversion.plist$ - - omit - - weight - 1100 - - ^Base\.lproj/ - - weight - 1010 - - ^Info\.plist$ - - omit - - weight - 20 - - ^PkgInfo$ - - omit - - weight - 20 - - ^embedded\.provisionprofile$ - - weight - 20 - - ^version\.plist$ - - weight - 20 - - - - diff --git a/packages/ios/index.d.ts b/packages/ios/index.d.ts index 9ebe90fa..a9b51353 100644 --- a/packages/ios/index.d.ts +++ b/packages/ios/index.d.ts @@ -1,2 +1,20 @@ /// /// + +/** + * The function to initialize all the JS bindings to the iOS SDK, allowing you + * to call iOS APIs from JS (e.g. `NSString.alloc().init()`). + * + * For NativeScript apps (i.e. apps using NativeScript Core), don't call this! + * The initialization will be done for you under-the-hood from the native side. + * + * For React Native apps, and any other hosts that implement the + * `react-native-node-api` [prebuilds standard](https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md), + * call this before calling any iOS APIs from JS. It's simplest to call it early + * on in the entrypoint of your app. + * + * It's not safe to call this API twice - so if you put it in a useEffect() + * hook, be careful about the hook getting called twice due to a HMR update or + * React Strict Mode. + */ +export function init(): void; diff --git a/packages/ios/index.js b/packages/ios/index.js new file mode 100644 index 00000000..4df8a378 --- /dev/null +++ b/packages/ios/index.js @@ -0,0 +1,19 @@ +// react-native-node-api/babel-plugin will rewrite this path to: +// module.exports = require("react-native-node-api").requireNodeAddon("-nativescript-ios-node-api—-NativeScript"); +// ... And some other build-time tooling in react-native-node-api searches this +// package for `*.node` files to point `requireNodeAddon()` to the true path. +// +// This is why we've added react-native-node-api as a peer dependency. We've +// marked it as optional, however, because other hosts may choose not to use +// that Babel transform. +module.exports = require("./build/Release/NativeScript.apple.node"); + +// Out of interest, we could alternatively write the path as follows: +// module.exports = require("bindings")("NativeScript"); +// +// react-native-node-api/babel-plugin would recognise and rewrite it all the +// same. That approach might make sense if we were also supporting Node.js with +// this package (as in the case of Node.js, you'd omit the Babel transform and +// you would actually depend on the "bindings" package), but unless we one day +// merge the iOS and macOS packages into one, it feels better to reduce the +// amount of magic involved. diff --git a/packages/ios/package.json b/packages/ios/package.json index d6cc1db5..e6dfa6c0 100644 --- a/packages/ios/package.json +++ b/packages/ios/package.json @@ -4,15 +4,14 @@ "description": "An embeddable, engine-agnostic NativeScript runtime for iOS based on Node-API", "repository": { "type": "git", - "url": "https://github.com/NativeScript/runtime-node-api.git", + "url": "https://github.com/NativeScript/napi-ios.git", "directory": "packages/ios" }, "typings": "index.d.ts", "type": "module", "files": [ - "dist/ios-universal/NativeScript.xcframework", + "build/Release/NativeScript.apple.node", "index.d.ts", - "NativeScript.podspec", "types" ], "scripts": { @@ -22,6 +21,7 @@ "keywords": [ "iOS", "NativeScript", + "React Native", "UIKit" ], "contributors": [ @@ -43,6 +43,14 @@ } ], "license": "MIT", + "peerDependencies": { + "react-native-node-api": "*" + }, + "peerDependenciesMeta": { + "react-native-node-api": { + "optional": true + } + }, "dependencies": { "@nativescript/objc-node-api": ">=1.0.0-alpha.5" }, diff --git a/scripts/build_xcframework.mts b/scripts/build_xcframework.mts new file mode 100644 index 00000000..76ff19eb --- /dev/null +++ b/scripts/build_xcframework.mts @@ -0,0 +1,111 @@ +import path from "node:path"; +import process from "node:process"; +import yargsParser from "yargs-parser"; +import { createXCframework } from "react-native-node-api"; + +main(); + +async function main() { + const __dirname = import.meta.dirname; + if (!__dirname) { + throw new Error("Expected import.meta.dirname to be truthy."); + } + + const monorepoRoot = path.resolve(__dirname, ".."); + + const args = yargsParser(process.argv.slice(2), { + configuration: { + "short-option-groups": false, + }, + string: ["output", "framework", "debug-symbols"], + array: ["framework", "debug-symbols"], + boolean: ["help"], + alias: { + h: "help", + }, + default: { + help: false, + }, + }); + + const { + output, + framework: frameworks = new Array(), + "debug-symbols": debugSymbols = new Array(), + help, + } = args; + + const helpText = ` +Typical usage: + +$ deno run -A ./scripts/build_xcframework.mts --output packages/ios/build/Release/NativeScript.apple.node -framework dist/intermediates/ios/RelWithDebInfo-iphoneos/NativeScript.framework -debug-symbols dist/intermediates/ios/RelWithDebInfo-iphoneos/NativeScript.framework.dSYM +`.trim(); + + if (help) { + console.log(helpText); + process.exit(0); + } + + if (!output) { + console.log( + `Please specify the output directory by passing the \`--output\` arg.\n\n${helpText}` + ); + process.exit(1); + } + + if (!isStringArray(frameworks) || !isStringArray(debugSymbols)) { + console.log( + `Expected -framework and -debug-symbols to be parsed as arrays.\n\n${helpText}` + ); + process.exit(1); + } + + if (!frameworks?.length) { + console.log( + `Please specify at least one framework to bundle into the xcframework by passing the \`-framework\` arg one or more times.\n\n${helpText}` + ); + process.exit(1); + } + + const outputPath = path.resolve(monorepoRoot, output); + const frameworkPaths = frameworks.map((framework) => + path.resolve(monorepoRoot, framework) + ); + // TODO: Pass this to the createXCFramework() options, once supported. + const _dsymPaths = + debugSymbols?.map((dsym) => path.resolve(monorepoRoot, dsym)) ?? []; + + try { + await createXCframework({ + outputPath, + frameworkPaths, + // dsymPaths, + autoLink: true, + }); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : ""; + console.error(`Failed to assemble XCFramework: ${errorMessage}`); + process.exit(1); + } + + console.log( + `\x1b[32m✔\x1b[0m XCFramework assembled into \x1b[2m${path.relative( + monorepoRoot, + outputPath + )}\x1b[22m` + ); +} + +function isStringArray(value: unknown): value is Array { + if (!Array.isArray(value)) { + return false; + } + + for (const element of value) { + if (typeof element !== "string") { + return false; + } + } + + return true; +} diff --git a/scripts/package.json b/scripts/package.json index 95d55652..907b361c 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -11,6 +11,10 @@ "type": "commonjs", "description": "", "dependencies": { - "@nativescript/core": "^8.8.6" + "@nativescript/core": "^8.8.6", + "yargs-parser": "^22.0.0" + }, + "devDependencies": { + "react-native-node-api": "^0.3.2" } }