v8.gni 9.86 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/gclient_args.gni")
6
import("//build/config/sanitizers/sanitizers.gni")
7
import("//build/config/v8_target_cpu.gni")
8
import("release_branch_toggle.gni")
9
import("split_static_library.gni")
10

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

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

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

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

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

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

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

machenbach's avatar
machenbach committed
35 36
  # Use external files for startup data blobs:
  # the JS builtins sources and the start snapshot.
37
  v8_use_external_startup_data = ""
38 39 40 41

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

43 44
  # Use static libraries instead of source_sets.
  v8_static_library = false
45 46 47

  # Enable monolithic static library for embedders.
  v8_monolithic = false
48 49 50

  # Expose symbols for dynamic linking.
  v8_expose_symbols = false
51

52
  # Implement tracing using Perfetto (https://perfetto.dev).
53
  v8_use_perfetto = false
54

55
  # Override global symbol level setting for v8.
56
  v8_symbol_level = symbol_level
57 58 59

  # Enable WebAssembly debugging via GDB-remote protocol.
  v8_enable_wasm_gdb_remote_debugging = false
60

61 62 63 64 65
  # Lite mode disables a number of performance optimizations to reduce memory
  # at the cost of performance.
  # Sets -DV8_LITE_MODE.
  v8_enable_lite_mode = false

66 67 68 69
  # Include support for WebAssembly. If disabled, the 'WebAssembly' global
  # will not be available, and embedder APIs to generate WebAssembly modules
  # will fail. Also, asm.js will not be translated to WebAssembly and will be
  # executed as standard JavaScript instead.
70
  v8_enable_webassembly = ""
71

72 73 74
  # Enable 256-bit long vector re-vectorization pass in WASM compilation pipeline.
  v8_enable_wasm_simd256_revec = false

75
  # Enable runtime call stats.
76
  v8_enable_runtime_call_stats = !is_on_release_branch
77

78 79
  # Add fuzzilli fuzzer support.
  v8_fuzzilli = false
80

81 82 83
  # Scan the call stack conservatively during garbage collection.
  v8_enable_conservative_stack_scanning = false

84 85 86
  # Use the object start bitmap for inner pointer resolution.
  v8_enable_inner_pointer_resolution_osb = false

87 88 89
  # Use the marking bitmap for inner pointer resolution.
  v8_enable_inner_pointer_resolution_mb = false

90
  v8_enable_google_benchmark = false
Omer Katz's avatar
Omer Katz committed
91 92

  cppgc_is_standalone = false
93

94 95 96
  # Enable object names in cppgc for debug purposes.
  cppgc_enable_object_names = false

97 98 99
  # Enable young generation in cppgc.
  cppgc_enable_young_generation = false

100 101 102
  # Enable pointer compression in cppgc.
  cppgc_enable_pointer_compression = false

103 104 105
  # Enable advanced BigInt algorithms, costing about 10-30 KB binary size
  # depending on platform. Disabled on Android to save binary size.
  v8_advanced_bigint_algorithms = !is_android
106 107 108 109
}

if (v8_use_external_startup_data == "") {
  # If not specified as a gn arg, use external startup data by default if
110 111
  # we're not on ios.
  v8_use_external_startup_data = !is_ios
112
}
113

114
if (v8_enable_backtrace == "") {
115
  v8_enable_backtrace = is_debug && !v8_optimized_debug
116 117
}

118 119 120 121 122 123
# If chromium is configured to use the perfetto client library, v8 should also
# use perfetto for tracing.
if (build_with_chromium && use_perfetto_client_library) {
  v8_use_perfetto = true
}

124 125 126 127 128 129 130
# WebAssembly is enabled by default, except in lite mode.
if (v8_enable_webassembly == "") {
  v8_enable_webassembly = !v8_enable_lite_mode
}
assert(!(v8_enable_webassembly && v8_enable_lite_mode),
       "Webassembly is not available in lite mode.")

131 132 133
# 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.
134
v8_path_prefix = get_path_info("../", "abspath")
135

136
v8_inspector_js_protocol = v8_path_prefix + "/include/js_protocol.pdl"
137 138 139 140 141

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

142
# Common configs to remove or add in all v8 targets.
143
v8_remove_configs = []
144 145 146
v8_add_configs = [
  v8_path_prefix + ":features",
  v8_path_prefix + ":toolchain",
147 148
]

149 150 151 152 153 154 155 156
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".
157
  if ((is_posix && !is_android) && !using_sanitizer) {
158 159 160 161 162
    v8_add_configs += [ "//build/config/compiler:optimize_speed" ]
  } else {
    v8_add_configs += [ "//build/config/compiler:optimize_max" ]
  }
}
163

164 165 166 167 168 169 170
if (!is_debug) {
  v8_remove_configs += [
    # Too much performance impact, unclear security benefit.
    "//build/config/compiler:default_init_stack_vars",
  ]
}

171 172 173 174 175 176 177
if (v8_code_coverage && !is_clang) {
  v8_add_configs += [
    v8_path_prefix + ":v8_gcov_coverage_cflags",
    v8_path_prefix + ":v8_gcov_coverage_ldflags",
  ]
}

178 179 180 181 182 183 184 185 186 187 188 189 190
if (v8_symbol_level != symbol_level) {
  v8_remove_configs += [ "//build/config/compiler:default_symbols" ]
  if (v8_symbol_level == 0) {
    v8_add_configs += [ "//build/config/compiler:no_symbols" ]
  } else if (v8_symbol_level == 1) {
    v8_add_configs += [ "//build/config/compiler:minimal_symbols" ]
  } else if (v8_symbol_level == 2) {
    v8_add_configs += [ "//build/config/compiler:symbols" ]
  } else {
    assert(false)
  }
}

191 192
if ((is_posix || is_fuchsia) &&
    (v8_enable_backtrace || v8_monolithic || v8_expose_symbols)) {
193 194 195 196
  v8_remove_configs += [ "//build/config/gcc:symbol_visibility_hidden" ]
  v8_add_configs += [ "//build/config/gcc:symbol_visibility_default" ]
}

197 198 199 200 201 202
# 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" ]
}

203 204 205 206
if (!build_with_chromium && is_clang) {
  v8_remove_configs += [ "//build/config/clang:find_bad_constructs" ]
}

207 208
# All templates should be kept in sync.
template("v8_source_set") {
209 210
  if (defined(invoker.split_count) && invoker.split_count > 1 &&
      defined(v8_static_library) && v8_static_library && is_win) {
211
    link_target_type = "split_static_library"
212
  } else if (defined(v8_static_library) && v8_static_library) {
213
    link_target_type = "static_library"
214
  } else {
215
    link_target_type = "source_set"
216 217
  }
  target(link_target_type, target_name) {
218 219 220 221 222 223
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
224 225
    configs -= v8_remove_configs
    configs += v8_add_configs
226 227 228
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
229
    configs += invoker.configs
230 231 232
  }
}

233
template("v8_header_set") {
234
  source_set(target_name) {
235 236 237
    forward_variables_from(invoker, "*", [ "configs" ])
    configs -= v8_remove_configs
    configs += v8_add_configs
238
    configs += invoker.configs
239 240 241
  }
}

242 243
template("v8_executable") {
  executable(target_name) {
244 245 246 247 248 249
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
250 251
    configs -= v8_remove_configs
    configs += v8_add_configs
252 253 254
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
255
    configs += invoker.configs
256
    if (is_linux || is_chromeos) {
257 258
      # For enabling ASLR.
      ldflags = [ "-pie" ]
259
    }
260
    if (defined(testonly) && testonly && v8_code_coverage) {
261 262
      # Only add code coverage cflags for non-test files for performance
      # reasons.
263 264
      if (is_clang) {
        configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
265 266
        configs +=
            [ "//build/config/sanitizers:default_sanitizer_flags_but_coverage" ]
267 268 269
      } else {
        configs -= [ v8_path_prefix + ":v8_gcov_coverage_cflags" ]
      }
270
    }
271
    deps += [ v8_path_prefix + ":v8_dump_build_config" ]
272 273 274 275 276
  }
}

template("v8_component") {
  component(target_name) {
277 278 279 280 281 282
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
283 284
    configs -= v8_remove_configs
    configs += v8_add_configs
285 286 287
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
288
    configs += invoker.configs
289 290
  }
}
291

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
template("v8_shared_library") {
  shared_library(target_name) {
    forward_variables_from(invoker,
                           "*",
                           [
                             "configs",
                             "remove_configs",
                           ])
    configs -= v8_remove_configs
    configs += v8_add_configs
    if (defined(invoker.remove_configs)) {
      configs -= invoker.remove_configs
    }
    if (defined(invoker.configs)) {
      configs += invoker.configs
    }
  }
}

311 312 313 314 315
template("v8_static_library") {
  static_library(target_name) {
    complete_static_lib = true
    forward_variables_from(invoker, "*", [ "configs" ])
    configs -= v8_remove_configs
316
    configs -= [ "//build/config/compiler:thin_archive" ]
317
    configs += v8_add_configs
318
    configs += invoker.configs
319 320
  }
}