# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Targets in ths file are to take a V8 context snapshot on build time.
# Created V8 context snapshot is used in
# third_party/blink/renderer/bindings/core/v8/v8_context_snapshot.{cc|h}.
# to speedup creating a V8 context and setting up around it.
import("//build/config/cast.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/v8_target_cpu.gni")
import("//v8/gni/v8.gni")
declare_args() {
# If set, both snapshots are included. At this time, this only applicable to
# android. In other words, it will not work correctly on other platforms.
# Building the context snapshots on android requires building blink multiple
# times. To avoid impacting developer productivity the context snapshot is
# only built for official builds.
include_both_v8_snapshots = is_official_build && target_os == "android"
}
declare_args() {
# TODO(crbug.com/40539769): Enable the feature on more environments.
# Disable in mac and win cross builds since building Blink twice is slow.
use_v8_context_snapshot =
include_both_v8_snapshots ||
(!is_chromeos && !is_android && !is_castos && !is_fuchsia &&
# Android may build for both 64 bit and 32bit. When this happens, the
# v8_target_cpu will not equal the target_cpu (for example,
# v8_target_cpu == "arm" but target_os == "arm64").
(v8_target_cpu == target_cpu || target_os == "android") &&
!(host_toolchain == default_toolchain && is_msan) &&
!(is_win && host_os != "win") && !(is_mac && host_os != "mac"))
# We use a different filename for arm64 macOS builds so that the arm64 and
# x64 snapshots can live side-by-side in a universal macOS app.
if (is_mac) {
if (v8_target_cpu == "x64") {
v8_context_snapshot_filename = "v8_context_snapshot.x86_64.bin"
} else if (v8_target_cpu == "arm64") {
v8_context_snapshot_filename = "v8_context_snapshot.arm64.bin"
}
} else if (target_os == "android") {
if (v8_current_cpu == "arm" || v8_current_cpu == "x86" ||
v8_current_cpu == "mipsel") {
v8_context_snapshot_filename = "v8_context_snapshot_32.bin"
} else {
v8_context_snapshot_filename = "v8_context_snapshot_64.bin"
}
} else {
v8_context_snapshot_filename = "v8_context_snapshot.bin"
}
}
# We cannot use V8 context snapshot, if V8 doesn't use snapshot files.
if (use_v8_context_snapshot && !v8_use_external_startup_data) {
use_v8_context_snapshot = false
}