141 lines
4.9 KiB
Text
141 lines
4.9 KiB
Text
# Copyright 2017 The Chromium Authors. All rights reserved.
|
|
# 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/WebKit/Source/bindings/core/v8/V8ContextSnapshot.{cpp|h}.
|
|
# to speedup creating a V8 context and setting up around it.
|
|
|
|
import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
|
|
|
|
import("//build/config/c++/c++.gni")
|
|
import("//build/config/compiler/compiler.gni")
|
|
import("//v8/gni/snapshot_toolchain.gni")
|
|
|
|
if (is_android) {
|
|
import("//build/config/android/rules.gni")
|
|
}
|
|
|
|
group("v8_context_snapshot") {
|
|
if (use_v8_context_snapshot) {
|
|
public_deps = [ ":generate_v8_context_snapshot($v8_snapshot_toolchain)" ]
|
|
if (!is_android) {
|
|
data = [ "$root_out_dir/$v8_context_snapshot_filename" ]
|
|
}
|
|
}
|
|
}
|
|
|
|
config("use_v8_context_snapshot") {
|
|
defines = []
|
|
if (use_v8_context_snapshot) {
|
|
defines += [
|
|
"USE_V8_CONTEXT_SNAPSHOT",
|
|
"V8_CONTEXT_SNAPSHOT_FILENAME=\"$v8_context_snapshot_filename\"",
|
|
]
|
|
}
|
|
}
|
|
|
|
if (use_v8_context_snapshot) {
|
|
if (is_android && enable_java_templates) {
|
|
android_assets("v8_context_snapshot_assets") {
|
|
deps = [ ":v8_context_snapshot" ]
|
|
default_toolchain_root_out_dir =
|
|
get_label_info(":v8_context_snapshot_generator($default_toolchain)",
|
|
"root_out_dir")
|
|
snapshot_file =
|
|
"$default_toolchain_root_out_dir/$v8_context_snapshot_filename"
|
|
renaming_sources = [ snapshot_file ]
|
|
renaming_destinations = [ "$v8_context_snapshot_filename" ]
|
|
disable_compression = true
|
|
}
|
|
}
|
|
|
|
if (v8_snapshot_toolchain == current_toolchain) {
|
|
action("generate_v8_context_snapshot") {
|
|
script = "//build/gn_run_binary.py"
|
|
|
|
# When cross compiling this target runs in a toolchain other than the
|
|
# default_toolchain. Code depending on this expect the snapshot to be
|
|
# generated in root_out_dir for the default toolchain.
|
|
default_toolchain_root_out_dir =
|
|
get_label_info(":v8_context_snapshot_generator($default_toolchain)",
|
|
"root_out_dir")
|
|
output_file =
|
|
"$default_toolchain_root_out_dir/$v8_context_snapshot_filename"
|
|
output_path = rebase_path(output_file, root_build_dir)
|
|
|
|
args = [
|
|
"./" + rebase_path(get_label_info(":v8_context_snapshot_generator",
|
|
"root_out_dir") +
|
|
"/v8_context_snapshot_generator",
|
|
root_build_dir),
|
|
"--output_file=$output_path",
|
|
]
|
|
|
|
deps = [ ":v8_context_snapshot_generator" ]
|
|
|
|
# TODO(sky): figure out why this doesn't work on android cross compile.
|
|
# In the case of compiling for the snapshot `shlib_extension` is ".so"
|
|
# (which is expected), but on disk ".cr.so" is generate, which ends up
|
|
# causing gn to fail.
|
|
if (is_component_build && target_os != "android") {
|
|
# In the component build mode, the snapshot should be updated when any
|
|
# of the generator executable or the shared libraries get updated. Note
|
|
# that it's possible that some of the shared libraries are updated
|
|
# without having the executable updated.
|
|
inputs = [
|
|
"$root_out_dir/${shlib_prefix}blink_core${shlib_extension}",
|
|
"$root_out_dir/${shlib_prefix}blink_modules${shlib_extension}",
|
|
"$root_out_dir/${shlib_prefix}blink_platform${shlib_extension}",
|
|
"$root_out_dir/${shlib_prefix}v8${shlib_extension}",
|
|
]
|
|
|
|
deps += [
|
|
"//third_party/blink/renderer/bindings:v8_context_snapshot_influential_libs",
|
|
"//v8",
|
|
]
|
|
}
|
|
|
|
outputs = [ output_file ]
|
|
}
|
|
|
|
executable("v8_context_snapshot_generator") {
|
|
sources = [ "v8_context_snapshot_generator.cc" ]
|
|
|
|
deps = [
|
|
"//gin:gin",
|
|
"//mojo/core/embedder",
|
|
"//services/service_manager/public/cpp",
|
|
"//third_party/blink/public:blink",
|
|
"//v8",
|
|
]
|
|
|
|
if (is_linux) {
|
|
configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
|
|
}
|
|
|
|
configs += [
|
|
"//v8:external_startup_data",
|
|
":disable_icf",
|
|
]
|
|
}
|
|
}
|
|
|
|
# This config disables a link time optimization "ICF", which may merge
|
|
# different functions into one if the function signature and body of them are
|
|
# identical.
|
|
#
|
|
# ICF breaks 1:1 mappings of the external references for V8 snapshot, so we
|
|
# disable it while taking a V8 snapshot.
|
|
config("disable_icf") {
|
|
visibility = [ ":*" ] # Only targets in this file can depend on this.
|
|
if (is_win) {
|
|
ldflags = [ "/OPT:NOICF" ] # link.exe, but also lld-link.exe.
|
|
} else if (is_apple && !use_lld) {
|
|
ldflags = [ "-Wl,-no_deduplicate" ] # ld64.
|
|
} else if (use_gold || use_lld) {
|
|
ldflags = [ "-Wl,--icf=none" ]
|
|
}
|
|
}
|
|
}
|