File: BUILD.gn

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (127 lines) | stat: -rw-r--r-- 4,328 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 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("//tools/v8_context_snapshot/v8_context_snapshot.gni")

import("//build/buildflag_header.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" ]
    if (!is_android) {
      data = [ "$root_out_dir/$v8_context_snapshot_filename" ]
    }
  }
}

buildflag_header("buildflags") {
  header = "buildflags.h"
  flags = [
    "USE_V8_CONTEXT_SNAPSHOT=$use_v8_context_snapshot",
    "INCLUDE_BOTH_V8_SNAPSHOTS=$include_both_v8_snapshots",
    "V8_CONTEXT_SNAPSHOT_FILENAME=\"$v8_context_snapshot_filename\"",
  ]
}

if (use_v8_context_snapshot) {
  action("generate_v8_context_snapshot") {
    script = "//build/gn_run_binary.py"

    snapshot_blob_file = "$root_out_dir/snapshot_blob.bin"
    snapshot_blob_path = rebase_path(snapshot_blob_file, root_build_dir)

    # All invocations of `v8_context_snapshot_generator`, whatever the
    # toolchain, write their result into the root build dir.
    output_file = "$root_build_dir/$v8_context_snapshot_filename"
    output_path = rebase_path(output_file, root_build_dir)

    args = [
      "./" + rebase_path(
              get_label_info(
                      ":v8_context_snapshot_generator($v8_snapshot_toolchain)",
                      "root_out_dir") + "/v8_context_snapshot_generator",
              root_build_dir),
      "--snapshot_blob=$snapshot_blob_path",
      "--output_file=$output_path",
    ]

    sources = [ "$root_out_dir/snapshot_blob.bin" ]
    deps = [
      ":v8_context_snapshot_generator($v8_snapshot_toolchain)",
      "//v8:run_mksnapshot_default",
    ]

    # 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 ]
  }

  if (v8_snapshot_toolchain == current_toolchain) {
    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",
      ]

      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_lld) {
      ldflags = [ "-Wl,--icf=none" ]
    }
  }
}