Skip to content

Jasssonpet/shared nativescript library #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2015
Merged
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1")

# TODO: Clang Analyzer, Tidy ...

if(${BUILD_SHARED_LIBS})
set(NATIVESCRIPT_LIBRARY_TYPE SHARED)
else()
set(NATIVESCRIPT_LIBRARY_TYPE STATIC)
endif()

add_subdirectory(src/NativeScript)
add_subdirectory(examples/Gameraww)
add_subdirectory(examples/BlankApp)
Expand Down
17 changes: 17 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ cp \
$NATIVESCRIPT_DIR/TNSRuntime.h \
$NATIVESCRIPT_DIR/TNSRuntime+Inspector.h \
$WORKSPACE/dist/NativeScript/include

cmake .. -DCMAKE_OSX_SYSROOT=iphonesimulator $CMAKE_FLAGS -DBUILD_SHARED_LIBS=YES
cmake --build . --config Release --target NativeScript

cmake .. -DCMAKE_OSX_SYSROOT=iphoneos $CMAKE_FLAGS -DBUILD_SHARED_LIBS=YES
cmake --build . --config Release --target NativeScript

echo "Packaging NativeScript-Shared..."
mkdir -p $WORKSPACE/dist/NativeScriptEmbedded/Release
cp -r $WORKSPACE/cmake-build/src/NativeScript/Release-iphoneos/NativeScript.framework $WORKSPACE/dist/NativeScriptEmbedded/Release

mkdir -p $WORKSPACE/dist/NativeScriptEmbedded/Debug
cp -r $WORKSPACE/dist/NativeScriptEmbedded/Release/NativeScript.framework $WORKSPACE/dist/NativeScriptEmbedded/Debug
rm $WORKSPACE/dist/NativeScriptEmbedded/Debug/NativeScript.framework/NativeScript
lipo -create -output $WORKSPACE/dist/NativeScriptEmbedded/Debug/NativeScript.framework/NativeScript \
$WORKSPACE/cmake-build/src/NativeScript/Release-iphonesimulator/NativeScript.framework/NativeScript \
$WORKSPACE/cmake-build/src/NativeScript/Release-iphoneos/NativeScript.framework/NativeScript
33 changes: 33 additions & 0 deletions examples/TodayExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>TodayExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.nativescript.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widget-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>TNSTodayExtension</string>
</dict>
</dict>
</plist>
17 changes: 17 additions & 0 deletions examples/TodayExtension/app/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
UIViewController.extend({
loadView: function() {
this.view = new UIView(CGRectMake(0, 0, 320, 200));
},
viewDidLoad: function() {
UIViewController.prototype.viewDidLoad.apply(this, arguments);
this.preferredContentSize = CGSizeMake(0, 200);

var label = new UILabel(CGRectMake(0, 0, 250, 60));
label.text = "Hello, World!";
label.textColor = UIColor.whiteColor();

this.view.addSubview(label);
}
}, {
name: "TNSTodayExtension"
});
21 changes: 21 additions & 0 deletions examples/TodayExtension/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// main.m
// TodayExtension
//
// Created by Jason Zhekov on 5/7/15.
// Copyright (c) 2015 Telerik. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <NativeScript/NativeScript.h>

static TNSRuntime* runtime;

// TODO: The order between this constructor and MetadataFile constructor is random
__attribute__((constructor))
static void initRuntime() {
runtime = [[TNSRuntime alloc] initWithApplicationPath:[NSBundle mainBundle].bundlePath];
TNSRuntimeInspector.logsToSystemConsole = YES;

[runtime executeModule:@"./"];
}
33 changes: 28 additions & 5 deletions src/NativeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,36 @@ set_target_properties(NativeScript PROPERTIES
-Werror -Wall -Wextra -Wcast-align -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wundef -Wwrite-strings
-Wno-shorten-64-to-32 -Wno-bool-conversion -Wno-unused-parameter
"
STATIC_LIBRARY_FLAGS "
-lJavaScriptCore -L\"${WEBKIT_DIR}/lib\"
-lffi -L\"${LIBFFI_DIR}/lib\"
"
XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "7.0"
)

if(${NATIVESCRIPT_LIBRARY_TYPE} STREQUAL "STATIC")
set_target_properties(NativeScript PROPERTIES
STATIC_LIBRARY_FLAGS "
-lJavaScriptCore -L\"${WEBKIT_DIR}/lib\"
-lffi -L\"${LIBFFI_DIR}/lib\"
"
XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES
)
elseif(${NATIVESCRIPT_LIBRARY_TYPE} STREQUAL "SHARED")
set_target_properties(NativeScript PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION "1.0" # TODO
PUBLIC_HEADER "NativeScript.h;TNSRuntime.h;TNSRuntime+Inspector.h" # TODO
INSTALL_NAME_DIR "@executable_path/Frameworks"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
MACOSX_FRAMEWORK_IDENTIFIER "org.nativescript.NativeScript"
)
target_link_libraries(NativeScript
-lJavaScriptCore -L"${WEBKIT_DIR}/lib"
-lffi -L"${LIBFFI_DIR}/lib"
"-framework UIKit"
libicucore.dylib
libz.dylib
libc++.dylib
)
endif()

include(EmbedResourceInHeader)
foreach(_jsfile ${JSFILES})
EmbedResourceInHeader(NativeScript ${_jsfile})
Expand Down
5 changes: 5 additions & 0 deletions src/NativeScript/Metadata/MetaFile.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MetaFile.h"
#include <iostream>
#include <sys/stat.h>
#include <stdio.h>

namespace Metadata {

Expand All @@ -17,6 +18,10 @@
void* loadFile(const char* filePath) {
const char* path = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithUTF8String:filePath]] UTF8String];
int fd = open(path, O_RDONLY);
if (fd == -1) {
perror("Could not load metadata file");
exit(1);
}
struct stat fileStat;
fstat(fd, &fileStat);
void* file = mmap(NULL, (size_t)fileStat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
Expand Down