Skip to content

Commit c365ebc

Browse files
committed
Added build script for NativeScript.framework
1 parent 90e377e commit c365ebc

File tree

9 files changed

+95
-86
lines changed

9 files changed

+95
-86
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Xcode
2+
build
23
build/
3-
!/build/
4+
#!/build/
45
*.pbxuser
56
!default.pbxuser
67
*.mode1v3

Inspector/utils.mm

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <MobileCoreServices/MobileCoreServices.h>
12
#include <Foundation/Foundation.h>
23
#include "utils.h"
34
#include <codecvt>
@@ -13,28 +14,19 @@
1314
return std::string();
1415
}
1516

16-
NSURL* fileUrl = [NSURL fileURLWithPath:fullPath];
17-
NSURLRequest* request = [[NSURLRequest alloc] initWithURL:fileUrl cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:.1];
18-
19-
__block NSURLResponse *response = nil;
20-
21-
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
22-
NSURLSession* session = [NSURLSession sharedSession];
23-
NSURLSessionDataTask* task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *urlResponse, NSError *error) {
24-
if (error == nil) {
25-
response = urlResponse;
26-
}
27-
dispatch_semaphore_signal(sem);
28-
}];
29-
[task resume];
30-
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
17+
NSString* fileExtension = [fullPath pathExtension];
18+
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, nil);
19+
if (uti == nil) {
20+
return std::string();
21+
}
3122

32-
if (response != nil) {
33-
NSString* mimeType = [response MIMEType];
34-
return [mimeType UTF8String];
23+
NSString* mimeType = (__bridge NSString*)UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
24+
if (mimeType == nil) {
25+
return std::string();
3526
}
3627

37-
return std::string();
28+
std::string result = [mimeType UTF8String];
29+
return result;
3830
}
3931

4032
std::string v8_inspector::ToStdString(const StringView& value) {

NativeScript/NativeScript.cpp

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

NativeScript/NativeScript.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
#ifndef NativeScript_h
2-
#define NativeScript_h
1+
@interface NativeScript : NSObject
32

4-
#include <string>
3+
+ (void)start:(void*)metadataPtr;
54

6-
namespace tns {
7-
8-
class NativeScript {
9-
public:
10-
static void Start(void* metadataPtr, std::string baseDir);
11-
};
12-
13-
}
14-
15-
#endif /* NativeScript_h */
5+
@end

NativeScript/NativeScript.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <Foundation/Foundation.h>
2+
#include "NativeScript.h"
3+
#include "Runtime/Runtime.h"
4+
5+
@implementation NativeScript
6+
7+
+(void)start:(void*)metadataPtr {
8+
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
9+
NSArray* components = [NSArray arrayWithObjects:resourcePath, @"app", nil];
10+
NSString* path = [NSString pathWithComponents:components];
11+
const char* baseDir = [path UTF8String];
12+
13+
tns::Runtime::InitializeMetadata(metadataPtr);
14+
tns::Runtime* runtime = new tns::Runtime();
15+
runtime->InitAndRunMainScript(baseDir);
16+
}
17+
18+
@end

TestApp/Source Files/main.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import <UIKit/UIKit.h>
2+
#import <NativeScript/NativeScript.h>
3+
4+
extern char startOfMetadataSection __asm("section$start$__DATA$__TNSMetadata");
5+
6+
int main(int argc, char *argv[]) {
7+
@autoreleasepool {
8+
void* metadataPtr = &startOfMetadataSection;
9+
10+
[NativeScript start:metadataPtr];
11+
12+
return 0;
13+
}
14+
}

TestApp/Source Files/main.mm

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

build_nativescript.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
echo "Cleanup"
4+
xcodebuild -project v8ios.xcodeproj -target "NativeScript" -configuration Release clean
5+
6+
echo "Building for iphone simulator"
7+
xcodebuild -project v8ios.xcodeproj -target "NativeScript" -configuration Release -arch x86_64 -sdk iphonesimulator
8+
9+
echo "Building for ARM64 device"
10+
xcodebuild -project v8ios.xcodeproj -target "NativeScript" -configuration Release -arch arm64 -sdk iphoneos
11+
12+
echo "Creating fat library"
13+
OUTPUT_DIR="build/NativeScript.framework"
14+
rm -rf "$OUTPUT_DIR"
15+
mkdir -p "$OUTPUT_DIR"
16+
cp -r "build/Release-iphoneos/NativeScript.framework/" "$OUTPUT_DIR"
17+
lipo -create build/Release-iphonesimulator/NativeScript.framework/NativeScript build/Release-iphoneos/NativeScript.framework/NativeScript -output "$OUTPUT_DIR/NativeScript"

v8ios.xcodeproj/project.pbxproj

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@
156156
C2DDEBB3229EAC8300345BFE /* ClassBuilder.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2DDEB8A229EAC8300345BFE /* ClassBuilder.mm */; };
157157
C2DDEBB4229EAC8300345BFE /* DictionaryAdapter.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2DDEB8B229EAC8300345BFE /* DictionaryAdapter.mm */; };
158158
C2DDEBB5229EAC8300345BFE /* Tasks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2DDEB8C229EAC8300345BFE /* Tasks.cpp */; };
159-
C2DDEBDC229EB37A00345BFE /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2DDEBDB229EB37A00345BFE /* main.mm */; };
159+
C2DDEBDC229EB37A00345BFE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C2DDEBDB229EB37A00345BFE /* main.m */; };
160160
C2DDEBDE229EB4A900345BFE /* app in Resources */ = {isa = PBXBuildFile; fileRef = C2DDEBDD229EB4A900345BFE /* app */; };
161-
C2F64E8322E870A300EDB057 /* NativeScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2F64E8222E870A300EDB057 /* NativeScript.cpp */; };
161+
C2F64E8322E870A300EDB057 /* NativeScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2F64E8222E870A300EDB057 /* NativeScript.mm */; };
162162
C2FEA16F22A3C75C00A5C0FC /* InlineFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2FEA16D22A3C75C00A5C0FC /* InlineFunctions.cpp */; };
163163
C2FEA17022A3C75C00A5C0FC /* InlineFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = C2FEA16E22A3C75C00A5C0FC /* InlineFunctions.h */; };
164164
/* End PBXBuildFile section */
@@ -171,19 +171,19 @@
171171
remoteGlobalIDString = C2DDEB31229EAB3B00345BFE;
172172
remoteInfo = NativeScript;
173173
};
174-
C293752A229FC4740075CB16 /* PBXContainerItemProxy */ = {
174+
C286B78422F06C7400795E21 /* PBXContainerItemProxy */ = {
175175
isa = PBXContainerItemProxy;
176176
containerPortal = C27E277822202663009C10A3 /* Project object */;
177177
proxyType = 1;
178-
remoteGlobalIDString = C29374E1229FC0F60075CB16;
179-
remoteInfo = TestFixtures;
178+
remoteGlobalIDString = C2BD9CAE22E5CB4E005CC701;
179+
remoteInfo = Inspector;
180180
};
181-
C2BD9D7522E5D8E8005CC701 /* PBXContainerItemProxy */ = {
181+
C293752A229FC4740075CB16 /* PBXContainerItemProxy */ = {
182182
isa = PBXContainerItemProxy;
183183
containerPortal = C27E277822202663009C10A3 /* Project object */;
184184
proxyType = 1;
185-
remoteGlobalIDString = C2BD9CAE22E5CB4E005CC701;
186-
remoteInfo = Inspector;
185+
remoteGlobalIDString = C29374E1229FC0F60075CB16;
186+
remoteInfo = TestFixtures;
187187
};
188188
C2F4CBBB22C61CF20036B56F /* PBXContainerItemProxy */ = {
189189
isa = PBXContainerItemProxy;
@@ -515,10 +515,10 @@
515515
C2DDEB8A229EAC8300345BFE /* ClassBuilder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClassBuilder.mm; sourceTree = "<group>"; };
516516
C2DDEB8B229EAC8300345BFE /* DictionaryAdapter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DictionaryAdapter.mm; sourceTree = "<group>"; };
517517
C2DDEB8C229EAC8300345BFE /* Tasks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tasks.cpp; sourceTree = "<group>"; };
518-
C2DDEBDB229EB37A00345BFE /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
518+
C2DDEBDB229EB37A00345BFE /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
519519
C2DDEBDD229EB4A900345BFE /* app */ = {isa = PBXFileReference; lastKnownFileType = folder; path = app; sourceTree = "<group>"; };
520520
C2F4CBB322C60BFD0036B56F /* metadata-generator */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "metadata-generator"; sourceTree = BUILT_PRODUCTS_DIR; };
521-
C2F64E8222E870A300EDB057 /* NativeScript.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = NativeScript.cpp; sourceTree = "<group>"; };
521+
C2F64E8222E870A300EDB057 /* NativeScript.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NativeScript.mm; sourceTree = "<group>"; };
522522
C2FEA16D22A3C75C00A5C0FC /* InlineFunctions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineFunctions.cpp; sourceTree = "<group>"; };
523523
C2FEA16E22A3C75C00A5C0FC /* InlineFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InlineFunctions.h; sourceTree = "<group>"; };
524524
C2FF3017225203FD00933782 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -1062,7 +1062,7 @@
10621062
C2DDEB3B229EAB8600345BFE /* Runtime */,
10631063
C2DDEB3A229EAB7400345BFE /* Snapshot */,
10641064
C2DDEB34229EAB3B00345BFE /* NativeScript.h */,
1065-
C2F64E8222E870A300EDB057 /* NativeScript.cpp */,
1065+
C2F64E8222E870A300EDB057 /* NativeScript.mm */,
10661066
C2DDEB35229EAB3B00345BFE /* Info.plist */,
10671067
);
10681068
path = NativeScript;
@@ -1170,7 +1170,7 @@
11701170
C2DDEBDA229EB37A00345BFE /* Source Files */ = {
11711171
isa = PBXGroup;
11721172
children = (
1173-
C2DDEBDB229EB37A00345BFE /* main.mm */,
1173+
C2DDEBDB229EB37A00345BFE /* main.m */,
11741174
);
11751175
path = "Source Files";
11761176
sourceTree = "<group>";
@@ -1309,7 +1309,7 @@
13091309
buildRules = (
13101310
);
13111311
dependencies = (
1312-
C2BD9D7622E5D8E8005CC701 /* PBXTargetDependency */,
1312+
C286B78522F06C7400795E21 /* PBXTargetDependency */,
13131313
);
13141314
name = NativeScript;
13151315
productName = NativeScript;
@@ -1524,7 +1524,7 @@
15241524
isa = PBXSourcesBuildPhase;
15251525
buildActionMask = 2147483647;
15261526
files = (
1527-
C2DDEBDC229EB37A00345BFE /* main.mm in Sources */,
1527+
C2DDEBDC229EB37A00345BFE /* main.m in Sources */,
15281528
);
15291529
runOnlyForDeploymentPostprocessing = 0;
15301530
};
@@ -1561,7 +1561,7 @@
15611561
C2C8EE7422CE3266001F8CEC /* ConcurrentQueue.cpp in Sources */,
15621562
C2DDEBA0229EAC8300345BFE /* Interop.mm in Sources */,
15631563
C266569E22B282BA00EE15CC /* FunctionReference.cpp in Sources */,
1564-
C2F64E8322E870A300EDB057 /* NativeScript.cpp in Sources */,
1564+
C2F64E8322E870A300EDB057 /* NativeScript.mm in Sources */,
15651565
C2DDEBB5229EAC8300345BFE /* Tasks.cpp in Sources */,
15661566
C2DDEBB1229EAC8300345BFE /* Caches.cpp in Sources */,
15671567
);
@@ -1582,16 +1582,16 @@
15821582
target = C2DDEB31229EAB3B00345BFE /* NativeScript */;
15831583
targetProxy = C22C091E22CA2E860080D176 /* PBXContainerItemProxy */;
15841584
};
1585+
C286B78522F06C7400795E21 /* PBXTargetDependency */ = {
1586+
isa = PBXTargetDependency;
1587+
target = C2BD9CAE22E5CB4E005CC701 /* Inspector */;
1588+
targetProxy = C286B78422F06C7400795E21 /* PBXContainerItemProxy */;
1589+
};
15851590
C293752B229FC4740075CB16 /* PBXTargetDependency */ = {
15861591
isa = PBXTargetDependency;
15871592
target = C29374E1229FC0F60075CB16 /* TestFixtures */;
15881593
targetProxy = C293752A229FC4740075CB16 /* PBXContainerItemProxy */;
15891594
};
1590-
C2BD9D7622E5D8E8005CC701 /* PBXTargetDependency */ = {
1591-
isa = PBXTargetDependency;
1592-
target = C2BD9CAE22E5CB4E005CC701 /* Inspector */;
1593-
targetProxy = C2BD9D7522E5D8E8005CC701 /* PBXContainerItemProxy */;
1594-
};
15951595
C2F4CBBC22C61CF20036B56F /* PBXTargetDependency */ = {
15961596
isa = PBXTargetDependency;
15971597
target = C2F4CBB222C60BFD0036B56F /* metadata-generator */;
@@ -1788,15 +1788,16 @@
17881788
C2DDEB2A229EA89200345BFE /* Debug */ = {
17891789
isa = XCBuildConfiguration;
17901790
buildSettings = {
1791-
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
1791+
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
1792+
CLANG_CXX_LIBRARY = "compiler-default";
17921793
CODE_SIGN_STYLE = Automatic;
17931794
DEVELOPMENT_TEAM = CHSQ3M3P37;
17941795
EXPORTED_SYMBOLS_FILE = "$(PROJECT_DIR)/TestFixtures/exported-symbols.txt";
17951796
FRAMEWORK_SEARCH_PATHS = (
17961797
"$(inherited)",
17971798
"$(PROJECT_DIR)/TestApp/Frameworks",
17981799
);
1799-
GCC_C_LANGUAGE_STANDARD = c11;
1800+
GCC_C_LANGUAGE_STANDARD = gnu99;
18001801
HEADER_SEARCH_PATHS = (
18011802
"$(SRCROOT)/include",
18021803
"$(SRCROOT)/NativeScript",
@@ -1832,15 +1833,16 @@
18321833
C2DDEB2B229EA89200345BFE /* Release */ = {
18331834
isa = XCBuildConfiguration;
18341835
buildSettings = {
1835-
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
1836+
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
1837+
CLANG_CXX_LIBRARY = "compiler-default";
18361838
CODE_SIGN_STYLE = Automatic;
18371839
DEVELOPMENT_TEAM = CHSQ3M3P37;
18381840
EXPORTED_SYMBOLS_FILE = "$(PROJECT_DIR)/TestFixtures/exported-symbols.txt";
18391841
FRAMEWORK_SEARCH_PATHS = (
18401842
"$(inherited)",
18411843
"$(PROJECT_DIR)/TestApp/Frameworks",
18421844
);
1843-
GCC_C_LANGUAGE_STANDARD = c11;
1845+
GCC_C_LANGUAGE_STANDARD = gnu99;
18441846
HEADER_SEARCH_PATHS = (
18451847
"$(SRCROOT)/include",
18461848
"$(SRCROOT)/NativeScript",
@@ -1909,6 +1911,8 @@
19091911
OTHER_LDFLAGS = (
19101912
"-framework",
19111913
UIKit,
1914+
"-framework",
1915+
MobileCoreServices,
19121916
"-force_load",
19131917
"$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/libInspector.a",
19141918
);
@@ -1957,6 +1961,8 @@
19571961
OTHER_LDFLAGS = (
19581962
"-framework",
19591963
UIKit,
1964+
"-framework",
1965+
MobileCoreServices,
19601966
);
19611967
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
19621968
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";

0 commit comments

Comments
 (0)