Skip to content

Commit 452acd3

Browse files
committed
follow react-native-node-api standard approach
Built with: ```sh ./build_all_ios.sh --no-engine --embed-metadata ```
1 parent 5a87628 commit 452acd3

File tree

27 files changed

+408
-167
lines changed

27 files changed

+408
-167
lines changed

NativeScript/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ if(TARGET_PLATFORM_MACOS)
305305

306306
set(METADATA_FILE "metadata.macos.nsmd")
307307
elseif(TARGET_PLATFORM_IOS)
308+
# Convert the Info.plist from binary format to XML format.
309+
# This seemed to unblock a build error when using in React Native.
310+
add_custom_command(TARGET ${NAME} POST_BUILD
311+
COMMAND plutil -convert xml1 $<TARGET_FILE_DIR:${NAME}>/Info.plist
312+
)
313+
308314
if(TARGET_PLATFORM_SIM)
309315
set(METADATA_FILE "metadata.ios-sim.nsmd")
310316
else()

build_nativescript.sh

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,39 +148,51 @@ fi
148148

149149
XCFRAMEWORKS=()
150150
if $BUILD_CATALYST; then
151-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework"
152-
-debug-symbols "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework.dSYM" )
151+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework"
152+
--debug-symbols "$DIST/intermediates/catalyst/$CONFIG_BUILD-maccatalyst/NativeScript.framework.dSYM" )
153153
fi
154154

155155
if $BUILD_SIMULATOR; then
156-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
157-
-debug-symbols "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework.dSYM" )
156+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework"
157+
--debug-symbols "$DIST/intermediates/ios-sim/$CONFIG_BUILD-iphonesimulator/NativeScript.framework.dSYM" )
158158
fi
159159

160160
if $BUILD_IPHONE; then
161-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
162-
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
161+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework"
162+
--debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
163163
fi
164164

165165
if $BUILD_MACOS; then
166-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
167-
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
166+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
167+
--debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
168168
fi
169169

170170
if $BUILD_VISION; then
171-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
172-
-debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
171+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"
172+
--debug-symbols "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
173173

174-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
175-
-debug-symbols "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
174+
XCFRAMEWORKS+=( --framework "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework"
175+
--debug-symbols "$DIST/intermediates/visionos-sim/$CONFIG_BUILD-xros/NativeScript.framework.dSYM" )
176176
fi
177177

178178
if [[ -n "${XCFRAMEWORKS[@]}" ]]; then
179179

180-
checkpoint "Creating NativeScript.xcframework"
181-
OUTPUT_DIR="$DIST/NativeScript.xcframework"
180+
checkpoint "Creating the XCFramework (NativeScript.apple.node)"
181+
182+
# This script used to output to "$DIST/NativeScript.xcframework".
183+
#
184+
# We now follow the react-native-node-api prebuilds standard, emitting an
185+
# XCFramework named "NativeScript.apple.node" into our
186+
# @nativescript/ios-node-api npm package. The reason we do not use .xcframework
187+
# as the file extension is that .node works better for other tooling like
188+
# Node.js. It turns out that Apple apps can link XCFrameworks just fine even if
189+
# the file extension is not .xcframework!
190+
#
191+
# The prebuilds standard is described here:
192+
# https://github.com/callstackincubator/react-native-node-api/blob/9b231c14459b62d7df33360f930a00343d8c46e6/docs/PREBUILDS.md
193+
OUTPUT_DIR="packages/ios/build/Release/NativeScript.apple.node"
182194
rm -rf $OUTPUT_DIR
183-
xcodebuild -create-xcframework ${XCFRAMEWORKS[@]} -output "$OUTPUT_DIR"
195+
deno run -A ./scripts/build_xcframework.mts --output "$OUTPUT_DIR" ${XCFRAMEWORKS[@]}
184196

185197
fi
186198

build_npm_ios.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ cp ./package.json "$OUTPUT_DIR"
1111

1212
cp -r "./project-template-ios/" "$OUTPUT_DIR/framework"
1313

14-
cp -r "dist/NativeScript.xcframework" "$OUTPUT_DIR/framework/internal"
14+
NATIVESCRIPT_IOS_XCFRAMEWORK="packages/ios/build/Release/NativeScript.apple.node"
15+
if [ ! -d "$NATIVESCRIPT_IOS_XCFRAMEWORK" ]; then
16+
echo "Error: Expected to find the NativeScript iOS XCFramework at path \"$NATIVESCRIPT_IOS_XCFRAMEWORK\". Make sure to run ./build_nativescript.sh before running this script." >&2
17+
exit 1
18+
fi
19+
20+
cp -r $NATIVESCRIPT_IOS_XCFRAMEWORK "$OUTPUT_DIR/framework/internal/NativeScript.xcframework"
21+
rm "$OUTPUT_DIR/framework/internal/NativeScript.xcframework/react-native-node-api-module"
22+
1523
cp -r "dist/TKLiveSync.xcframework" "$OUTPUT_DIR/framework/internal"
1624

1725
mkdir -p "$OUTPUT_DIR/framework/internal/metadata-generator-x86_64"

packages/ios/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!build

packages/ios/NativeScript.podspec

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/ios/dist/ios-universal/NativeScript.xcframework/Info.plist renamed to packages/ios/build/Release/NativeScript.apple.node/Info.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
<key>BinaryPath</key>
99
<string>NativeScript.framework/NativeScript</string>
1010
<key>LibraryIdentifier</key>
11-
<string>ios-arm64</string>
11+
<string>ios-arm64_x86_64-simulator</string>
1212
<key>LibraryPath</key>
1313
<string>NativeScript.framework</string>
1414
<key>SupportedArchitectures</key>
1515
<array>
1616
<string>arm64</string>
17+
<string>x86_64</string>
1718
</array>
1819
<key>SupportedPlatform</key>
1920
<string>ios</string>
21+
<key>SupportedPlatformVariant</key>
22+
<string>simulator</string>
2023
</dict>
2124
<dict>
2225
<key>BinaryPath</key>
2326
<string>NativeScript.framework/NativeScript</string>
2427
<key>LibraryIdentifier</key>
25-
<string>ios-arm64_x86_64-simulator</string>
28+
<string>ios-arm64</string>
2629
<key>LibraryPath</key>
2730
<string>NativeScript.framework</string>
2831
<key>SupportedArchitectures</key>
2932
<array>
3033
<string>arm64</string>
31-
<string>x86_64</string>
3234
</array>
3335
<key>SupportedPlatform</key>
3436
<string>ios</string>
35-
<key>SupportedPlatformVariant</key>
36-
<string>simulator</string>
3737
</dict>
3838
</array>
3939
<key>CFBundlePackageType</key>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef NATIVESCRIPT_H
2+
#define NATIVESCRIPT_H
3+
4+
#ifdef __cplusplus
5+
6+
extern "C"
7+
8+
#endif // __cplusplus
9+
10+
void
11+
nativescript_init(void* env, const char* metadata_path, const void* metadata_ptr);
12+
13+
#ifdef __OBJC__
14+
15+
#import <Foundation/Foundation.h>
16+
17+
__attribute__((visibility("default")))
18+
@interface Config : NSObject
19+
20+
@property(nonatomic, retain) NSString* BaseDir;
21+
@property(nonatomic, retain) NSString* ApplicationPath;
22+
@property(nonatomic) void* MetadataPtr;
23+
@property BOOL IsDebug;
24+
@property BOOL LogToSystemConsole;
25+
@property int ArgumentsCount;
26+
@property(nonatomic) char** Arguments;
27+
28+
@end
29+
30+
__attribute__((visibility("default")))
31+
@interface NativeScript : NSObject
32+
33+
- (instancetype)initWithConfig:(Config*)config;
34+
- (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop;
35+
- (void)restartWithConfig:(Config*)config;
36+
- (void)shutdownRuntime;
37+
38+
/**
39+
WARNING: this method does not return in most applications. (UIApplicationMain)
40+
*/
41+
- (void)runMainApplication;
42+
- (bool)liveSync;
43+
44+
@end
45+
46+
#endif // __OBJC__
47+
48+
#endif /* NATIVESCRIPT_H */
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildMachineOSBuild</key>
6+
<string>23G93</string>
7+
<key>CFBundleDevelopmentRegion</key>
8+
<string>English</string>
9+
<key>CFBundleExecutable</key>
10+
<string>NativeScript</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>org.nativescript.runtime</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>0.1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleSupportedPlatforms</key>
22+
<array>
23+
<string>iPhoneOS</string>
24+
</array>
25+
<key>CFBundleVersion</key>
26+
<string>0.1.0</string>
27+
<key>CSResourcesFileMapped</key>
28+
<true/>
29+
<key>DTCompiler</key>
30+
<string>com.apple.compilers.llvm.clang.1_0</string>
31+
<key>DTPlatformBuild</key>
32+
<string>22C146</string>
33+
<key>DTPlatformName</key>
34+
<string>iphoneos</string>
35+
<key>DTPlatformVersion</key>
36+
<string>18.2</string>
37+
<key>DTSDKBuild</key>
38+
<string>22C146</string>
39+
<key>DTSDKName</key>
40+
<string>iphoneos18.2</string>
41+
<key>DTXcode</key>
42+
<string>1620</string>
43+
<key>DTXcodeBuild</key>
44+
<string>16C5032a</string>
45+
<key>MinimumOSVersion</key>
46+
<string>13.0</string>
47+
<key>UIDeviceFamily</key>
48+
<array>
49+
<integer>1</integer>
50+
<integer>2</integer>
51+
</array>
52+
<key>UIRequiredDeviceCapabilities</key>
53+
<array>
54+
<string>arm64</string>
55+
</array>
56+
</dict>
57+
</plist>
441 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef NATIVESCRIPT_H
2+
#define NATIVESCRIPT_H
3+
4+
#ifdef __cplusplus
5+
6+
extern "C"
7+
8+
#endif // __cplusplus
9+
10+
void
11+
nativescript_init(void* env, const char* metadata_path, const void* metadata_ptr);
12+
13+
#ifdef __OBJC__
14+
15+
#import <Foundation/Foundation.h>
16+
17+
__attribute__((visibility("default")))
18+
@interface Config : NSObject
19+
20+
@property(nonatomic, retain) NSString* BaseDir;
21+
@property(nonatomic, retain) NSString* ApplicationPath;
22+
@property(nonatomic) void* MetadataPtr;
23+
@property BOOL IsDebug;
24+
@property BOOL LogToSystemConsole;
25+
@property int ArgumentsCount;
26+
@property(nonatomic) char** Arguments;
27+
28+
@end
29+
30+
__attribute__((visibility("default")))
31+
@interface NativeScript : NSObject
32+
33+
- (instancetype)initWithConfig:(Config*)config;
34+
- (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop;
35+
- (void)restartWithConfig:(Config*)config;
36+
- (void)shutdownRuntime;
37+
38+
/**
39+
WARNING: this method does not return in most applications. (UIApplicationMain)
40+
*/
41+
- (void)runMainApplication;
42+
- (bool)liveSync;
43+
44+
@end
45+
46+
#endif // __OBJC__
47+
48+
#endif /* NATIVESCRIPT_H */

0 commit comments

Comments
 (0)