jonathansadler / ns-v8ios-runtime

NativeScript iOS runtime using the V8 engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started

To start diving into the v8 iOS runtime make sure you have XCode and Homebrew installed, and then run the following

# Install CMake
brew install cmake

# Clone repo
git clone https://github.com/NativeScript/ns-v8ios-runtime.git

# Initialize and clone the submodules
cd ns-v8ios-runtime
git submodule update --init

# Open the runtime in XCode
open v8ios.xcodeproj

Select the TestRunner target and an emulator and hit Run (the play button).

Screenshot 2020-09-09 at 18 25 43

This should take a while, but once built the emulator should start and show a black screen (this is normal). In this phase the app will run all the built-in tests, and report the results to the console:

Runtime initialization took 55ms
2020-09-09 18:30:37.797265+0200 TestRunner[14285:1238340] CONSOLE LOG: Application Start!
2020-09-09 18:30:38.288740+0200 TestRunner[14285:1238340] No implementation found for exposed method "nonExistingSelector"
2020-09-09 18:30:49.720055+0200 TestRunner[14285:1238340] CONSOLE LOG: SUCCESS: 684 specs, 0 failures, 0 skipped, 0 disabled in 11.81s.

If all tests pass, everything is good! At this point you can make changes to the runtime, add breakpoints and step through with the debugger. In the next section we'll see how to attach the runtime to an existing NativeScript application allowing us to debug runtime issues in actual apps.

Attaching the runtime to a NativeScript app

In the existing app, we need to prepare the XCode project using ns prepare ios. This should create a folder named platforms/ios and in there a <appname>.xcworkspace (if there is no .xcworkspace use the .xcodeproj instead). Open it in XCode and then drag the v8ios.xcodeproj from the ns-v8ios-runtime folder under the <appname> in the XCode sidebar.

Screenshot 2020-09-09 at 18 46 18

Remove the NativeScript.xcframework from the General tab, as we will no longer be using the framework from node_modules and instead will use the source directly:

Screenshot 2020-09-09 at 18 47 23

Add the Nativescript.framework from the v8ios workspace (only required when running on a physical device):

Screen Shot 2021-04-12 at 11 49 10 AM

Hitting Run in XCode should start the app in the simulator, and we can now add breakpoints to the runtime and step through it with the debugger. To apply changes to the javascript, make sure you run ns prepare ios to re-bundle it into the platforms/ios folder.

Overview

POC showing the {N} iOS runtime running with the V8 engine.

Supported architectures:

  • x86_64
  • arm64

iOS deployment target:

  • 9.0

The --jitless mode in which V8 is running is explained in the following document

Building V8

In order to build the V8 engine for iOS and produce the static libraries used in this project follow those steps:

  1. Get depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
  1. fetch v8 (this will create a v8 repo folder automatically checking out the master branch)

  2. cd v8; gclient sync (this will fetch additional dependencies for building the latest revision)

Ensure you navigate back to root of project: cd ..

  1. Apply patches: apply_patch.sh

  2. Run build_v8.sh

The compiled fat static libraries will be placed inside the v8/dist folder.

Building a Distribution Package

Use the build_all.sh script included in this repository to produce the dist/npm/nativescript-ios-{version}.tgz NPM package.

About

NativeScript iOS runtime using the V8 engine


Languages

Language:JavaScript 76.5%Language:C++ 17.1%Language:C 3.2%Language:Objective-C++ 1.8%Language:Objective-C 0.6%Language:Swift 0.5%Language:Shell 0.1%Language:TypeScript 0.1%Language:CMake 0.0%Language:Python 0.0%