v8.gni 7.39 KB
Newer Older
1 2 3 4
# Copyright 2016 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

5
import("//build/config/jumbo.gni")
6
import("//build/config/sanitizers/sanitizers.gni")
7
import("//build/config/v8_target_cpu.gni")
8
import("//build/split_static_library.gni")
9

10
declare_args() {
11 12 13 14
  # Set flags for tracking code coverage. Uses gcov with gcc and sanitizer
  # coverage with clang.
  v8_code_coverage = false

15 16 17
  # Includes files needed for correctness fuzzing.
  v8_correctness_fuzzer = false

18 19 20
  # Adds additional compile target for building multiple architectures at once.
  v8_multi_arch_build = false

21 22 23 24
  # Indicate if valgrind was fetched as a custom deps to make it available on
  # swarming.
  v8_has_valgrind = false

25 26 27
  # Indicate if gcmole was fetched as a hook to make it available on swarming.
  v8_gcmole = false

28 29 30
  # Turns on compiler optimizations in V8 in Debug build.
  v8_optimized_debug = true

31 32 33
  # Support for backtrace_symbols on linux.
  v8_enable_backtrace = ""

34
  # Enables raw heap snapshots containing internals. Used for debugging memory
35
  # on platform and embedder level.
36 37
  v8_enable_raw_heap_snapshots = false

machenbach's avatar
machenbach committed
38
  # Enable the snapshot feature, for fast context creation.
39
  # https://v8.dev/blog/custom-startup-snapshots
40 41
  # TODO(thakis): Make snapshots work in 64-bit win/cross builds,
  # https://803591
42 43 44 45
  # On Mac hosts, 32-bit builds targeting Windows can't use snapshots, see
  # https://crbug.com/794838
  v8_use_snapshot = !(is_win && host_os != "win" && target_cpu == "x64") &&
                    !(is_win && host_os == "mac" && target_cpu == "x86")
machenbach's avatar
machenbach committed
46

47
  # Enable several snapshots side-by-side (e.g. default and for trusted code).
48
  v8_use_multi_snapshots = false
49

machenbach's avatar
machenbach committed
50 51
  # Use external files for startup data blobs:
  # the JS builtins sources and the start snapshot.
52
  v8_use_external_startup_data = ""
53 54 55 56

  # Enable ECMAScript Internationalization API. Enabling this feature will
  # add a dependency on the ICU library.
  v8_enable_i18n_support = true
57

58 59
  # Use static libraries instead of source_sets.
  v8_static_library = false
60 61 62

  # Enable monolithic static library for embedders.
  v8_monolithic = false
63 64 65

  # Expose symbols for dynamic linking.
  v8_expose_symbols = false
66 67 68 69 70 71
}

if (v8_use_external_startup_data == "") {
  # If not specified as a gn arg, use external startup data by default if
  # a snapshot is used and if we're not on ios.
  v8_use_external_startup_data = v8_use_snapshot && !is_ios
72
}
73

74 75 76 77
if (v8_use_multi_snapshots) {
  # Silently disable multi snapshots if they're incompatible with the current
  # build configuration. This allows us to set v8_use_multi_snapshots=true on
  # all bots, and e.g. no-snapshot bots will automatically do the right thing.
78 79
  v8_use_multi_snapshots =
      v8_use_external_startup_data && !build_with_chromium && !use_jumbo_build
80 81
}

82
if (v8_enable_backtrace == "") {
83
  v8_enable_backtrace = is_debug && !v8_optimized_debug
84 85
}

86 87 88
# Points to // in v8 stand-alone or to //v8/ in chromium. We need absolute
# paths for all configs in templates as they are shared in different
# subdirectories.
89
v8_path_prefix = get_path_info("../", "abspath")
90

91
v8_inspector_js_protocol = v8_path_prefix + "/src/inspector/js_protocol.pdl"
92 93 94 95 96

###############################################################################
# Templates
#

97
# Common configs to remove or add in all v8 targets.
98
v8_remove_configs = []
99 100 101
v8_add_configs = [
  v8_path_prefix + ":features",
  v8_path_prefix + ":toolchain",
102 103
]

104 105 106 107 108 109 110 111 112 113 114 115 116 117
if (is_debug && !v8_optimized_debug) {
  v8_remove_configs += [ "//build/config/compiler:default_optimization" ]
  v8_add_configs += [ "//build/config/compiler:no_optimize" ]
} else {
  v8_remove_configs += [ "//build/config/compiler:default_optimization" ]

  # TODO(crbug.com/621335) Rework this so that we don't have the confusion
  # between "optimize_speed" and "optimize_max".
  if (((is_posix && !is_android) || is_fuchsia) && !using_sanitizer) {
    v8_add_configs += [ "//build/config/compiler:optimize_speed" ]
  } else {
    v8_add_configs += [ "//build/config/compiler:optimize_max" ]
  }
}
118

119 120 121 122 123 124 125
if (v8_code_coverage && !is_clang) {
  v8_add_configs += [
    v8_path_prefix + ":v8_gcov_coverage_cflags",
    v8_path_prefix + ":v8_gcov_coverage_ldflags",
  ]
}

126 127
if ((is_posix || is_fuchsia) &&
    (v8_enable_backtrace || v8_monolithic || v8_expose_symbols)) {
128 129 130 131
  v8_remove_configs += [ "//build/config/gcc:symbol_visibility_hidden" ]
  v8_add_configs += [ "//build/config/gcc:symbol_visibility_default" ]
}

132 133 134 135 136 137
# On MIPS gcc_target_rpath and ldso_path might be needed for all builds.
if (target_cpu == "mipsel" || target_cpu == "mips64el" ||
    target_cpu == "mips" || target_cpu == "mips64") {
  v8_add_configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
}

138 139 140 141
if (!build_with_chromium && is_clang) {
  v8_remove_configs += [ "//build/config/clang:find_bad_constructs" ]
}

142 143
# All templates should be kept in sync.
template("v8_source_set") {
144 145
  if (defined(invoker.split_count) && invoker.split_count > 1 &&
      defined(v8_static_library) && v8_static_library && is_win) {
146
    link_target_type = "jumbo_split_static_library"
147
  } else if (defined(v8_static_library) && v8_static_library) {
148
    link_target_type = "jumbo_static_library"
149
  } else {
150
    link_target_type = "jumbo_source_set"
151 152
  }
  target(link_target_type, target_name) {
153 154 155 156 157 158
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
159 160
    configs -= v8_remove_configs
    configs += v8_add_configs
161 162 163
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
164
    configs += invoker.configs
165 166 167
  }
}

168
template("v8_header_set") {
169
  jumbo_source_set(target_name) {
170 171 172
    forward_variables_from(invoker, "*", [ "configs" ])
    configs -= v8_remove_configs
    configs += v8_add_configs
173
    configs += invoker.configs
174 175 176
  }
}

177 178
template("v8_executable") {
  executable(target_name) {
179 180 181 182 183 184
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
185 186
    configs -= v8_remove_configs
    configs += v8_add_configs
187 188 189
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
190
    configs += invoker.configs
191 192 193
    if (is_linux) {
      # For enabling ASLR.
      ldflags = [ "-pie" ]
194
    }
195
    if (defined(testonly) && testonly && v8_code_coverage) {
196 197
      # Only add code coverage cflags for non-test files for performance
      # reasons.
198 199
      if (is_clang) {
        configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
200 201
        configs +=
            [ "//build/config/sanitizers:default_sanitizer_flags_but_coverage" ]
202 203 204
      } else {
        configs -= [ v8_path_prefix + ":v8_gcov_coverage_cflags" ]
      }
205
    }
206
    deps += [ v8_path_prefix + ":v8_dump_build_config" ]
207 208 209 210 211 212
  }
}

template("v8_component") {
  component(target_name) {
    forward_variables_from(invoker, "*", [ "configs" ])
213 214
    configs -= v8_remove_configs
    configs += v8_add_configs
215
    configs += invoker.configs
216 217
  }
}
218 219 220 221 222 223

template("v8_static_library") {
  static_library(target_name) {
    complete_static_lib = true
    forward_variables_from(invoker, "*", [ "configs" ])
    configs -= v8_remove_configs
224
    configs -= [ "//build/config/compiler:thin_archive" ]
225
    configs += v8_add_configs
226
    configs += invoker.configs
227 228
  }
}