跨編譯 iOS

此頁面簡要介紹如何為 iOS 目標建置 V8。

需求 #

初始設定 #

按照 建置 V8 的說明 操作。

在位於 v8 原始碼目錄父目錄的 .gclient 組態檔中加入 target_os,以取得 iOS 跨編譯所需的額外工具

# [... other contents of .gclient such as the 'solutions' variable ...]
target_os = ['ios']

更新 .gclient 之後,執行 gclient sync 下載額外工具。

手動建置 #

此區段說明如何建置單一 V8 版本,以便在實體 iOS 裝置或 Xcode iOS 模擬器上使用。此建置的輸出為 libv8_monolith.a 檔案,其中包含所有 V8 函式庫以及 V8 快照。

執行 gn args out/release-ios 並插入下列金鑰,設定 GN 建置檔案

ios_deployment_target = 10
is_component_build = false
is_debug = false
target_cpu = "arm64" # "x64" for a simulator build.
target_os = "ios"
use_custom_libcxx = false # Use Xcode's libcxx.
v8_enable_i18n_support = false # Produces a smaller binary.
v8_monolithic = true # Enable the v8_monolith target.
v8_use_external_startup_data = false # The snaphot is included in the binary.
v8_enable_pointer_compression = false # Unsupported on iOS.

現在建置

ninja -C out/release-ios v8_monolith

最後,將產生的 libv8_monolith.a 檔案新增至您的 Xcode 專案中,作為靜態函式庫。如需將 V8 嵌入應用程式的進一步文件,請參閱 開始嵌入 V8