• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 the V8 project authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/gclient_args.gni")
6import("//build/config/sanitizers/sanitizers.gni")
7import("//build/config/v8_target_cpu.gni")
8import("release_branch_toggle.gni")
9import("split_static_library.gni")
10
11declare_args() {
12  # Set flags for tracking code coverage. Uses gcov with gcc and sanitizer
13  # coverage with clang.
14  v8_code_coverage = false
15
16  # Includes files needed for correctness fuzzing.
17  v8_correctness_fuzzer = false
18
19  # Adds additional compile target for building multiple architectures at once.
20  v8_multi_arch_build = false
21
22  # Indicate if valgrind was fetched as a custom deps to make it available on
23  # swarming.
24  v8_has_valgrind = false
25
26  # Indicate if gcmole was fetched as a hook to make it available on swarming.
27  v8_gcmole = false
28
29  # Turns on compiler optimizations in V8 in Debug build.
30  v8_optimized_debug = true
31
32  # Support for backtrace_symbols on linux.
33  v8_enable_backtrace = ""
34
35  # Use external files for startup data blobs:
36  # the JS builtins sources and the start snapshot.
37  v8_use_external_startup_data = ""
38
39  # Enable ECMAScript Internationalization API. Enabling this feature will
40  # add a dependency on the ICU library.
41  v8_enable_i18n_support = true
42
43  # Use static libraries instead of source_sets.
44  v8_static_library = false
45
46  # Enable monolithic static library for embedders.
47  v8_monolithic = false
48
49  # Expose symbols for dynamic linking.
50  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  # Enable WebAssembly debugging via GDB-remote protocol.
59  v8_enable_wasm_gdb_remote_debugging = false
60
61  # Lite mode disables a number of performance optimizations to reduce memory
62  # at the cost of performance.
63  # Sets -DV8_LITE_MODE.
64  v8_enable_lite_mode = false
65
66  # Include support for WebAssembly. If disabled, the 'WebAssembly' global
67  # will not be available, and embedder APIs to generate WebAssembly modules
68  # will fail. Also, asm.js will not be translated to WebAssembly and will be
69  # executed as standard JavaScript instead.
70  v8_enable_webassembly = ""
71
72  # Enable runtime call stats.
73  v8_enable_runtime_call_stats = !is_on_release_branch
74
75  # Add fuzzilli fuzzer support.
76  v8_fuzzilli = false
77
78  # Scan the call stack conservatively during garbage collection.
79  v8_enable_conservative_stack_scanning = false
80
81  v8_enable_google_benchmark = false
82
83  cppgc_is_standalone = false
84
85  # Enable object names in cppgc for debug purposes.
86  cppgc_enable_object_names = false
87
88  # Enable young generation in cppgc.
89  cppgc_enable_young_generation = false
90
91  # Enable advanced BigInt algorithms, costing about 10-30 KB binary size
92  # depending on platform. Disabled on Android to save binary size.
93  v8_advanced_bigint_algorithms = !is_android
94}
95
96if (v8_use_external_startup_data == "") {
97  # If not specified as a gn arg, use external startup data by default if
98  # we're not on ios.
99  v8_use_external_startup_data = !is_ios
100}
101
102if (v8_enable_backtrace == "") {
103  v8_enable_backtrace = is_debug && !v8_optimized_debug
104}
105
106# If chromium is configured to use the perfetto client library, v8 should also
107# use perfetto for tracing.
108if (build_with_chromium && use_perfetto_client_library) {
109  v8_use_perfetto = true
110}
111
112# WebAssembly is enabled by default, except in lite mode.
113if (v8_enable_webassembly == "") {
114  v8_enable_webassembly = !v8_enable_lite_mode
115}
116assert(!(v8_enable_webassembly && v8_enable_lite_mode),
117       "Webassembly is not available in lite mode.")
118
119# Points to // in v8 stand-alone or to //v8/ in chromium. We need absolute
120# paths for all configs in templates as they are shared in different
121# subdirectories.
122v8_path_prefix = get_path_info("../", "abspath")
123
124v8_inspector_js_protocol = v8_path_prefix + "/include/js_protocol.pdl"
125
126###############################################################################
127# Templates
128#
129
130# Common configs to remove or add in all v8 targets.
131v8_remove_configs = []
132v8_add_configs = [
133  v8_path_prefix + ":features",
134  v8_path_prefix + ":toolchain",
135]
136
137if (is_debug && !v8_optimized_debug) {
138  v8_remove_configs += [ "//build/config/compiler:default_optimization" ]
139  v8_add_configs += [ "//build/config/compiler:no_optimize" ]
140} else {
141  v8_remove_configs += [ "//build/config/compiler:default_optimization" ]
142
143  # TODO(crbug.com/621335) Rework this so that we don't have the confusion
144  # between "optimize_speed" and "optimize_max".
145  if (((is_posix && !is_android) || is_fuchsia) && !using_sanitizer) {
146    v8_add_configs += [ "//build/config/compiler:optimize_speed" ]
147  } else {
148    v8_add_configs += [ "//build/config/compiler:optimize_max" ]
149  }
150}
151
152if (!is_debug) {
153  v8_remove_configs += [
154    # Too much performance impact, unclear security benefit.
155    "//build/config/compiler:default_init_stack_vars",
156  ]
157}
158
159if (v8_code_coverage && !is_clang) {
160  v8_add_configs += [
161    v8_path_prefix + ":v8_gcov_coverage_cflags",
162    v8_path_prefix + ":v8_gcov_coverage_ldflags",
163  ]
164}
165
166if (v8_symbol_level != symbol_level) {
167  v8_remove_configs += [ "//build/config/compiler:default_symbols" ]
168  if (v8_symbol_level == 0) {
169    v8_add_configs += [ "//build/config/compiler:no_symbols" ]
170  } else if (v8_symbol_level == 1) {
171    v8_add_configs += [ "//build/config/compiler:minimal_symbols" ]
172  } else if (v8_symbol_level == 2) {
173    v8_add_configs += [ "//build/config/compiler:symbols" ]
174  } else {
175    assert(false)
176  }
177}
178
179if ((is_posix || is_fuchsia) &&
180    (v8_enable_backtrace || v8_monolithic || v8_expose_symbols)) {
181  v8_remove_configs += [ "//build/config/gcc:symbol_visibility_hidden" ]
182  v8_add_configs += [ "//build/config/gcc:symbol_visibility_default" ]
183}
184
185# On MIPS gcc_target_rpath and ldso_path might be needed for all builds.
186if (target_cpu == "mipsel" || target_cpu == "mips64el" ||
187    target_cpu == "mips" || target_cpu == "mips64") {
188  v8_add_configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
189}
190
191if (!build_with_chromium && is_clang) {
192  v8_remove_configs += [ "//build/config/clang:find_bad_constructs" ]
193}
194
195# All templates should be kept in sync.
196template("v8_source_set") {
197  if (defined(invoker.split_count) && invoker.split_count > 1 &&
198      defined(v8_static_library) && v8_static_library && is_win) {
199    link_target_type = "split_static_library"
200  } else if (defined(v8_static_library) && v8_static_library) {
201    link_target_type = "static_library"
202  } else {
203    link_target_type = "source_set"
204  }
205  target(link_target_type, target_name) {
206    forward_variables_from(invoker,
207                           "*",
208                           [
209                             "configs",
210                             "remove_configs",
211                           ])
212    configs -= v8_remove_configs
213    configs += v8_add_configs
214    if (defined(invoker.remove_configs)) {
215      configs -= invoker.remove_configs
216    }
217    configs += invoker.configs
218  }
219}
220
221template("v8_header_set") {
222  source_set(target_name) {
223    forward_variables_from(invoker, "*", [ "configs" ])
224    configs -= v8_remove_configs
225    configs += v8_add_configs
226    configs += invoker.configs
227  }
228}
229
230template("v8_executable") {
231  executable(target_name) {
232    forward_variables_from(invoker,
233                           "*",
234                           [
235                             "configs",
236                             "remove_configs",
237                           ])
238    configs -= v8_remove_configs
239    configs += v8_add_configs
240    if (defined(invoker.remove_configs)) {
241      configs -= invoker.remove_configs
242    }
243    configs += invoker.configs
244    if (is_linux || is_chromeos) {
245      # For enabling ASLR.
246      ldflags = [ "-pie" ]
247    }
248    if (defined(testonly) && testonly && v8_code_coverage) {
249      # Only add code coverage cflags for non-test files for performance
250      # reasons.
251      if (is_clang) {
252        configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
253        configs +=
254            [ "//build/config/sanitizers:default_sanitizer_flags_but_coverage" ]
255      } else {
256        configs -= [ v8_path_prefix + ":v8_gcov_coverage_cflags" ]
257      }
258    }
259    deps += [ v8_path_prefix + ":v8_dump_build_config" ]
260  }
261}
262
263template("v8_component") {
264  component(target_name) {
265    forward_variables_from(invoker,
266                           "*",
267                           [
268                             "configs",
269                             "remove_configs",
270                           ])
271    configs -= v8_remove_configs
272    configs += v8_add_configs
273    if (defined(invoker.remove_configs)) {
274      configs -= invoker.remove_configs
275    }
276    configs += invoker.configs
277  }
278}
279
280template("v8_shared_library") {
281  shared_library(target_name) {
282    forward_variables_from(invoker,
283                           "*",
284                           [
285                             "configs",
286                             "remove_configs",
287                           ])
288    configs -= v8_remove_configs
289    configs += v8_add_configs
290    if (defined(invoker.remove_configs)) {
291      configs -= invoker.remove_configs
292    }
293    if (defined(invoker.configs)) {
294      configs += invoker.configs
295    }
296  }
297}
298
299template("v8_static_library") {
300  static_library(target_name) {
301    complete_static_lib = true
302    forward_variables_from(invoker, "*", [ "configs" ])
303    configs -= v8_remove_configs
304    configs -= [ "//build/config/compiler:thin_archive" ]
305    configs += v8_add_configs
306    configs += invoker.configs
307  }
308}
309