Skip to content

Commit bb364f9

Browse files
authored
feat(visionos): support for xros platform (#235)
1 parent dc3c76f commit bb364f9

File tree

95 files changed

+1479
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1479
-195
lines changed

.github/workflows/npm_release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT
6060
echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT
6161
- name: Build
62-
run: npm run build
62+
run: npm run build-ios
6363
- name: Upload npm package artifact
6464
uses: actions/upload-artifact@v3
6565
with:

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
4444
npm version $NPM_VERSION --no-git-tag-version
4545
- name: Build
46-
run: npm run build
46+
run: npm run build-ios
4747
- name: Upload npm package artifact
4848
uses: actions/upload-artifact@v3
4949
with:

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ v8_build
5050
# v8 build files...
5151
.gclient*
5252
.cipd/
53+
54+
# project template
55+
/project-template-ios/.build_env_vars.sh
56+
/project-template-ios/__PROJECT_NAME__.xcodeproj/project.xcworkspace/xcshareddata/
57+
/project-template-vision/.build_env_vars.sh
58+
/project-template-vision/__PROJECT_NAME__.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

NativeScript/NativeScript-Prefix.pch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef NativeScript_Prefix_pch
22
#define NativeScript_Prefix_pch
33

4-
#define NATIVESCRIPT_VERSION "8.6.1"
4+
#define NATIVESCRIPT_VERSION "8.7.0-rc.1"
55

66
#ifdef DEBUG
77
#define SIZEOF_OFF_T 8

NativeScript/inspector/utils.mm

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020

2121
NSString* fileExtension = [fullPath pathExtension];
22+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
2223
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, nil);
2324
if (uti == nil) {
2425
return std::string();
399 KB
Binary file not shown.
154 KB
Binary file not shown.
1.29 KB
Binary file not shown.

NativeScript/lib/arm64-xros/libffi.a

108 KB
Binary file not shown.
30 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
71.6 KB
Binary file not shown.
7.73 MB
Binary file not shown.
4.7 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!<arch>
263 KB
Binary file not shown.
Binary file not shown.
1.73 MB
Binary file not shown.

NativeScript/lib/arm64-xros/libzip.a

132 KB
Binary file not shown.
Binary file not shown.
154 KB
Binary file not shown.
Binary file not shown.
109 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!<arch>
Binary file not shown.
Binary file not shown.
Binary file not shown.
132 KB
Binary file not shown.

NativeScript/runtime/Metadata.mm

+19-12
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ void LogMetadataUnavailable(const char* identifierString, uint8_t majorVersion,
1717
);
1818
}
1919

20+
#if !TARGET_OS_VISION
2021
/**
2122
* \brief Gets the system version of the current device.
2223
*/
2324
static UInt8 getSystemVersion() {
24-
static UInt8 iosVersion;
25-
if (iosVersion != 0) {
26-
return iosVersion;
27-
}
25+
static UInt8 iosVersion;
26+
if (iosVersion != 0) {
27+
return iosVersion;
28+
}
2829

29-
NSString* version = [[UIDevice currentDevice] systemVersion];
30-
NSArray* versionTokens = [version componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
31-
UInt8 majorVersion = (UInt8)[versionTokens[0] intValue];
32-
UInt8 minorVersion = (UInt8)[versionTokens[1] intValue];
30+
NSString* version = [[UIDevice currentDevice] systemVersion];
31+
NSArray* versionTokens = [version componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
32+
UInt8 majorVersion = (UInt8)[versionTokens[0] intValue];
33+
UInt8 minorVersion = (UInt8)[versionTokens[1] intValue];
3334

34-
return iosVersion = encodeVersion(majorVersion, minorVersion);
35+
return iosVersion = encodeVersion(majorVersion, minorVersion);
3536
}
37+
#endif
38+
3639
robin_hood::unordered_map<std::string, MembersCollection> getMetasByJSNames(MembersCollection members) {
3740
robin_hood::unordered_map<std::string, MembersCollection> result;
3841
for (auto member : members) {
@@ -43,9 +46,13 @@ static UInt8 getSystemVersion() {
4346

4447
// Meta
4548
bool Meta::isAvailable() const {
46-
UInt8 introducedIn = this->introducedIn();
47-
UInt8 systemVersion = getSystemVersion();
48-
return introducedIn == 0 || introducedIn <= systemVersion;
49+
#if TARGET_OS_VISION
50+
return true;
51+
#else
52+
UInt8 introducedIn = this->introducedIn();
53+
UInt8 systemVersion = getSystemVersion();
54+
return introducedIn == 0 || introducedIn <= systemVersion;
55+
#endif
4956
}
5057

5158
// MethodMeta class

NativeScript/runtime/MetadataInlines.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <objc/runtime.h>
55
#include "StringHasher.h"
6+
#include <cassert>
67

78
namespace tns {
89

NativeScript/runtime/robin_hood.h

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static Counts& counts() {
225225
# define ROBIN_HOOD_PRIVATE_DEFINITION_NODISCARD()
226226
#endif
227227

228+
#pragma GCC diagnostic ignored "-Wdeprecated-builtins"
229+
228230
namespace robin_hood {
229231

230232
#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX14)

build_all.sh renamed to build_all_ios.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
rm -rf ./dist
55
./update_version.sh
66
./build_metadata_generator.sh
7-
./build_nativescript.sh
8-
./build_tklivesync.sh
7+
./build_nativescript.sh --no-vision
8+
./build_tklivesync.sh --no-vision
99
./prepare_dSYMs.sh
10-
./build_npm.sh
10+
./build_npm_ios.sh

build_all_vision.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
rm -rf ./dist
5+
./update_version.sh
6+
./build_metadata_generator.sh
7+
./build_nativescript.sh --no-catalyst --no-iphone --no-sim
8+
./build_tklivesync.sh --no-catalyst --no-iphone --no-sim
9+
./prepare_dSYMs.sh
10+
./build_npm_vision.sh

build_metadata_generator.sh

+5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ rm -rf dist
2323
mkdir dist
2424
checkpoint "Building metadata generator for x86_64 ..."
2525
build "x86_64"
26+
# make sure the binary is linked against the system libc++ instead of an @rpath one (which happens when compiling on arm64)
27+
# todo: perhaps there is a better way to do this with cmake?
28+
install_name_tool -change @rpath/libc++.1.dylib /usr/lib/libc++.1.dylib dist/x86_64/bin/objc-metadata-generator
29+
otool -L dist/x86_64/bin/objc-metadata-generator
2630

2731
checkpoint "Building metadata generator for arm64 ..."
2832
build "arm64"
33+
otool -L dist/arm64/bin/objc-metadata-generator
2934
rm -rf build
3035
popd

build_nativescript.sh

+50-48
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function to_bool() {
2626
BUILD_CATALYST=$(to_bool ${BUILD_CATALYST:=true})
2727
BUILD_IPHONE=$(to_bool ${BUILD_IPHONE:=true})
2828
BUILD_SIMULATOR=$(to_bool ${BUILD_SIMULATOR:=true})
29+
BUILD_VISION=$(to_bool ${BUILD_VISION:=true})
2930
VERBOSE=$(to_bool ${VERBOSE:=false})
3031

3132
for arg in $@; do
@@ -36,6 +37,8 @@ for arg in $@; do
3637
--no-sim|--no-simulator) BUILD_SIMULATOR=false ;;
3738
--iphone|--device) BUILD_IPHONE=true ;;
3839
--no-iphone|--no-device) BUILD_IPHONE=false ;;
40+
--xr|--vision) BUILD_VISION=true ;;
41+
--no-xr|--no-vision) BUILD_VISION=false ;;
3942
--verbose|-v) VERBOSE=true ;;
4043
*) ;;
4144
esac
@@ -58,52 +61,17 @@ xcodebuild -project v8ios.xcodeproj \
5861
-configuration Release clean \
5962
$QUIET
6063

61-
62-
if $BUILD_CATALYST; then
63-
checkpoint "Building NativeScript for Mac Catalyst"
64-
xcodebuild archive -project v8ios.xcodeproj \
65-
-scheme "NativeScript" \
66-
-configuration Release \
67-
-destination "platform=macOS,variant=Mac Catalyst" \
68-
$QUIET \
69-
EXCLUDED_ARCHS="x86_64" \
70-
SKIP_INSTALL=NO \
71-
-archivePath $DIST/intermediates/NativeScript.maccatalyst.xcarchive
72-
fi
73-
7464
if $BUILD_SIMULATOR; then
75-
# checkpoint "Building for x86_64 iphone simulator"
76-
# xcodebuild archive -project v8ios.xcodeproj \
77-
# -scheme "NativeScript" \
78-
# -configuration Release \
79-
# -arch x86_64 \
80-
# -sdk iphonesimulator \
81-
# $QUIET \
82-
# DEVELOPMENT_TEAM=$DEV_TEAM \
83-
# SKIP_INSTALL=NO \
84-
# -archivePath $DIST/NativeScript.x86_64-iphonesimulator.xcarchive
85-
86-
# checkpoint "Building for ARM64 iphone simulator"
87-
# xcodebuild archive -project v8ios.xcodeproj \
88-
# -scheme "NativeScript" \
89-
# -configuration Release \
90-
# -arch arm64 \
91-
# -sdk iphonesimulator \
92-
# $QUIET \
93-
# DEVELOPMENT_TEAM=$DEV_TEAM \
94-
# SKIP_INSTALL=NO \
95-
# -archivePath $DIST/NativeScript.arm64-iphonesimulator.xcarchive
96-
9765
checkpoint "Building NativeScript for iphone simulators (multi-arch)"
9866
xcodebuild archive -project v8ios.xcodeproj \
9967
-scheme "NativeScript" \
10068
-configuration Release \
10169
-destination "generic/platform=iOS Simulator" \
102-
-sdk iphonesimulator \
10370
$QUIET \
10471
EXCLUDED_ARCHS="i386" \
10572
DEVELOPMENT_TEAM=$DEV_TEAM \
10673
SKIP_INSTALL=NO \
74+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
10775
-archivePath $DIST/intermediates/NativeScript.iphonesimulator.xcarchive
10876
fi
10977

@@ -113,27 +81,54 @@ xcodebuild archive -project v8ios.xcodeproj \
11381
-scheme "NativeScript" \
11482
-configuration Release \
11583
-destination "generic/platform=iOS" \
116-
-sdk iphoneos \
11784
$QUIET \
11885
EXCLUDED_ARCHS="armv7" \
11986
DEVELOPMENT_TEAM=$DEV_TEAM \
12087
SKIP_INSTALL=NO \
88+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
12189
-archivePath $DIST/intermediates/NativeScript.iphoneos.xcarchive
90+
fi
12291

123-
#Create fat library for simulator
124-
# rm -rf "$DIST/NativeScript.iphonesimulator.xcarchive"
92+
if $BUILD_CATALYST; then
93+
checkpoint "Building NativeScript for Mac Catalyst"
94+
xcodebuild archive -project v8ios.xcodeproj \
95+
-scheme "NativeScript" \
96+
-configuration Release \
97+
-destination "generic/platform=macOS,variant=Mac Catalyst" \
98+
$QUIET \
99+
EXCLUDED_ARCHS="x86_64" \
100+
SKIP_INSTALL=NO \
101+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
102+
-archivePath $DIST/intermediates/NativeScript.maccatalyst.xcarchive
103+
fi
125104

126-
# cp -R \
127-
# "$DIST/NativeScript.x86_64-iphonesimulator.xcarchive" \
128-
# "$DIST/NativeScript.iphonesimulator.xcarchive"
105+
if $BUILD_VISION; then
129106

130-
# rm "$DIST/NativeScript.iphonesimulator.xcarchive/Products/Library/Frameworks/NativeScript.framework/NativeScript"
107+
checkpoint "Building NativeScript for visionOS Device"
108+
xcodebuild archive -project v8ios.xcodeproj \
109+
-scheme "NativeScript" \
110+
-configuration Release \
111+
-destination "generic/platform=visionOS" \
112+
$QUIET \
113+
EXCLUDED_ARCHS="i386 x86_64" \
114+
VALID_ARCHS=arm64 \
115+
DEVELOPMENT_TEAM=$DEV_TEAM \
116+
SKIP_INSTALL=NO \
117+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
118+
-archivePath $DIST/intermediates/NativeScript.xros.xcarchive
131119

132-
# lipo -create \
133-
# "$DIST/NativeScript.x86_64-iphonesimulator.xcarchive/Products/Library/Frameworks/NativeScript.framework/NativeScript" \
134-
# "$DIST/NativeScript.arm64-iphonesimulator.xcarchive/Products/Library/Frameworks/NativeScript.framework/NativeScript" \
135-
# -output \
136-
# "$DIST/NativeScript.iphonesimulator.xcarchive/Products/Library/Frameworks/NativeScript.framework/NativeScript"
120+
checkpoint "Building NativeScript for visionOS Simulators"
121+
xcodebuild archive -project v8ios.xcodeproj \
122+
-scheme "NativeScript" \
123+
-configuration Release \
124+
-destination "generic/platform=visionOS Simulator" \
125+
$QUIET \
126+
EXCLUDED_ARCHS="i386 x86_64" \
127+
VALID_ARCHS=arm64 \
128+
DEVELOPMENT_TEAM=$DEV_TEAM \
129+
SKIP_INSTALL=NO \
130+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
131+
-archivePath $DIST/intermediates/NativeScript.xrsimulator.xcarchive
137132
fi
138133

139134
XCFRAMEWORKS=()
@@ -152,6 +147,13 @@ if $BUILD_IPHONE; then
152147
-debug-symbols "$DIST/intermediates/NativeScript.iphoneos.xcarchive/dSYMs/NativeScript.framework.dSYM" )
153148
fi
154149

150+
if $BUILD_VISION; then
151+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/NativeScript.xros.xcarchive/Products/Library/Frameworks/NativeScript.framework" \
152+
-debug-symbols "$DIST/intermediates/NativeScript.xros.xcarchive/dSYMs/NativeScript.framework.dSYM" )
153+
XCFRAMEWORKS+=( -framework "$DIST/intermediates/NativeScript.xrsimulator.xcarchive/Products/Library/Frameworks/NativeScript.framework" \
154+
-debug-symbols "$DIST/intermediates/NativeScript.xrsimulator.xcarchive/dSYMs/NativeScript.framework.dSYM" )
155+
fi
156+
155157
checkpoint "Creating NativeScript.xcframework"
156158
OUTPUT_DIR="$DIST/NativeScript.xcframework"
157159
rm -rf $OUTPUT_DIR

build_npm.sh renamed to build_npm_ios.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/bin/bash
22
set -e
3+
source "$(dirname "$0")/build_utils.sh"
34

5+
checkpoint "Preparing npm package for iOS..."
46
OUTPUT_DIR="dist/npm"
57
rm -rf "$OUTPUT_DIR"
68
mkdir -p "$OUTPUT_DIR"
79
mkdir -p "$OUTPUT_DIR/framework"
810
cp ./package.json "$OUTPUT_DIR"
9-
cp -r "./project-template/" "$OUTPUT_DIR/framework"
11+
12+
cp -r "./project-template-ios/" "$OUTPUT_DIR/framework"
1013

1114
cp -r "dist/NativeScript.xcframework" "$OUTPUT_DIR/framework/internal"
1215
cp -r "dist/TKLiveSync.xcframework" "$OUTPUT_DIR/framework/internal"
@@ -28,4 +31,6 @@ cp -r "metadata-generator/dist/arm64/." "$OUTPUT_DIR/framework/internal/metadata
2831
pushd "$OUTPUT_DIR"
2932
npm pack
3033
mv *.tgz ../
31-
popd
34+
popd
35+
36+
checkpoint "npm package created."

build_npm_vision.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -e
3+
source "$(dirname "$0")/build_utils.sh"
4+
5+
checkpoint "Preparing npm package for visionOS..."
6+
OUTPUT_DIR="dist/npm"
7+
rm -rf "$OUTPUT_DIR"
8+
mkdir -p "$OUTPUT_DIR"
9+
mkdir -p "$OUTPUT_DIR/framework"
10+
cp ./package.json "$OUTPUT_DIR"
11+
12+
cp -r "./project-template-vision/" "$OUTPUT_DIR/framework"
13+
14+
cp -r "dist/NativeScript.xcframework" "$OUTPUT_DIR/framework/internal"
15+
cp -r "dist/TKLiveSync.xcframework" "$OUTPUT_DIR/framework/internal"
16+
17+
mkdir -p "$OUTPUT_DIR/framework/internal/metadata-generator-x86_64"
18+
cp -r "metadata-generator/dist/x86_64/." "$OUTPUT_DIR/framework/internal/metadata-generator-x86_64"
19+
20+
mkdir -p "$OUTPUT_DIR/framework/internal/metadata-generator-arm64"
21+
cp -r "metadata-generator/dist/arm64/." "$OUTPUT_DIR/framework/internal/metadata-generator-arm64"
22+
23+
# Add xcframeworks to .zip (NPM modules do not support symlinks, unzipping is done by {N} CLI)
24+
(
25+
set -e
26+
cd $OUTPUT_DIR/framework/internal
27+
zip -qr --symlinks XCFrameworks.zip *.xcframework
28+
rm -rf *.xcframework
29+
)
30+
31+
pushd "$OUTPUT_DIR"
32+
npm pack
33+
mv *.tgz ../
34+
popd
35+
36+
checkpoint "npm package created."

0 commit comments

Comments
 (0)