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("split_static_library.gni") 9 10declare_args() { 11 # Set flags for tracking code coverage. Uses gcov with gcc and sanitizer 12 # coverage with clang. 13 v8_code_coverage = false 14 15 # Includes files needed for correctness fuzzing. 16 v8_correctness_fuzzer = false 17 18 # Adds additional compile target for building multiple architectures at once. 19 v8_multi_arch_build = false 20 21 # Indicate if valgrind was fetched as a custom deps to make it available on 22 # swarming. 23 v8_has_valgrind = false 24 25 # Indicate if gcmole was fetched as a hook to make it available on swarming. 26 v8_gcmole = false 27 28 # Turns on compiler optimizations in V8 in Debug build. 29 v8_optimized_debug = true 30 31 # Support for backtrace_symbols on linux. 32 v8_enable_backtrace = "" 33 34 # This flag is deprecated and is now available through the inspector interface 35 # as an argument to profiler's method `takeHeapSnapshot`. 36 v8_enable_raw_heap_snapshots = false 37 38 # Enable several snapshots side-by-side (e.g. default and for trusted code). 39 v8_use_multi_snapshots = false 40 41 # Use external files for startup data blobs: 42 # the JS builtins sources and the start snapshot. 43 v8_use_external_startup_data = "" 44 45 # Enable ECMAScript Internationalization API. Enabling this feature will 46 # add a dependency on the ICU library. 47 v8_enable_i18n_support = true 48 49 # Use static libraries instead of source_sets. 50 v8_static_library = false 51 52 # Enable monolithic static library for embedders. 53 v8_monolithic = false 54 55 # Expose symbols for dynamic linking. 56 v8_expose_symbols = false 57 58 # Implement tracing using Perfetto (https://perfetto.dev). 59 v8_use_perfetto = false 60 61 # Override global symbol level setting for v8. 62 v8_symbol_level = symbol_level 63 64 # Enable WebAssembly debugging via GDB-remote protocol. 65 v8_enable_wasm_gdb_remote_debugging = false 66 67 # Add fuzzilli fuzzer support. 68 v8_fuzzilli = false 69 70 # Scan the call stack conservatively during garbage collection. 71 v8_enable_conservative_stack_scanning = false 72 73 v8_enable_google_benchmark = checkout_google_benchmark 74} 75 76if (v8_use_external_startup_data == "") { 77 # If not specified as a gn arg, use external startup data by default if 78 # we're not on ios. 79 v8_use_external_startup_data = !is_ios 80} 81 82if (v8_use_multi_snapshots) { 83 # Silently disable multi snapshots if they're incompatible with the current 84 # build configuration. This allows us to set v8_use_multi_snapshots=true on 85 # all bots, and e.g. no-snapshot bots will automatically do the right thing. 86 v8_use_multi_snapshots = v8_use_external_startup_data && !build_with_chromium 87} 88 89if (v8_enable_backtrace == "") { 90 v8_enable_backtrace = is_debug && !v8_optimized_debug 91} 92 93# If chromium is configured to use the perfetto client library, v8 should also 94# use perfetto for tracing. 95if (build_with_chromium && use_perfetto_client_library) { 96 v8_use_perfetto = true 97} 98 99# Points to // in v8 stand-alone or to //v8/ in chromium. We need absolute 100# paths for all configs in templates as they are shared in different 101# subdirectories. 102v8_path_prefix = get_path_info("../", "abspath") 103 104v8_inspector_js_protocol = v8_path_prefix + "/include/js_protocol.pdl" 105 106############################################################################### 107# Templates 108# 109 110# Common configs to remove or add in all v8 targets. 111v8_remove_configs = [] 112v8_add_configs = [ 113 v8_path_prefix + ":features", 114 v8_path_prefix + ":toolchain", 115] 116 117if (is_debug && !v8_optimized_debug) { 118 v8_remove_configs += [ "//build/config/compiler:default_optimization" ] 119 v8_add_configs += [ "//build/config/compiler:no_optimize" ] 120} else { 121 v8_remove_configs += [ "//build/config/compiler:default_optimization" ] 122 123 # TODO(crbug.com/621335) Rework this so that we don't have the confusion 124 # between "optimize_speed" and "optimize_max". 125 if (((is_posix && !is_android) || is_fuchsia) && !using_sanitizer) { 126 v8_add_configs += [ "//build/config/compiler:optimize_speed" ] 127 } else { 128 v8_add_configs += [ "//build/config/compiler:optimize_max" ] 129 } 130} 131 132if (!is_debug) { 133 v8_remove_configs += [ 134 # Too much performance impact, unclear security benefit. 135 "//build/config/compiler:default_init_stack_vars", 136 ] 137} 138 139if (v8_code_coverage && !is_clang) { 140 v8_add_configs += [ 141 v8_path_prefix + ":v8_gcov_coverage_cflags", 142 v8_path_prefix + ":v8_gcov_coverage_ldflags", 143 ] 144} 145 146if (v8_symbol_level != symbol_level) { 147 v8_remove_configs += [ "//build/config/compiler:default_symbols" ] 148 if (v8_symbol_level == 0) { 149 v8_add_configs += [ "//build/config/compiler:no_symbols" ] 150 } else if (v8_symbol_level == 1) { 151 v8_add_configs += [ "//build/config/compiler:minimal_symbols" ] 152 } else if (v8_symbol_level == 2) { 153 v8_add_configs += [ "//build/config/compiler:symbols" ] 154 } else { 155 assert(false) 156 } 157} 158 159if ((is_posix || is_fuchsia) && 160 (v8_enable_backtrace || v8_monolithic || v8_expose_symbols)) { 161 v8_remove_configs += [ "//build/config/gcc:symbol_visibility_hidden" ] 162 v8_add_configs += [ "//build/config/gcc:symbol_visibility_default" ] 163} 164 165# On MIPS gcc_target_rpath and ldso_path might be needed for all builds. 166if (target_cpu == "mipsel" || target_cpu == "mips64el" || 167 target_cpu == "mips" || target_cpu == "mips64") { 168 v8_add_configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 169} 170 171if (!build_with_chromium && is_clang) { 172 v8_remove_configs += [ "//build/config/clang:find_bad_constructs" ] 173} 174 175# All templates should be kept in sync. 176template("v8_source_set") { 177 if (defined(invoker.split_count) && invoker.split_count > 1 && 178 defined(v8_static_library) && v8_static_library && is_win) { 179 link_target_type = "split_static_library" 180 } else if (defined(v8_static_library) && v8_static_library) { 181 link_target_type = "static_library" 182 } else { 183 link_target_type = "source_set" 184 } 185 target(link_target_type, target_name) { 186 forward_variables_from(invoker, 187 "*", 188 [ 189 "configs", 190 "remove_configs", 191 ]) 192 configs -= v8_remove_configs 193 configs += v8_add_configs 194 if (defined(invoker.remove_configs)) { 195 configs -= invoker.remove_configs 196 } 197 configs += invoker.configs 198 } 199} 200 201template("v8_header_set") { 202 source_set(target_name) { 203 forward_variables_from(invoker, "*", [ "configs" ]) 204 configs -= v8_remove_configs 205 configs += v8_add_configs 206 configs += invoker.configs 207 } 208} 209 210template("v8_executable") { 211 executable(target_name) { 212 forward_variables_from(invoker, 213 "*", 214 [ 215 "configs", 216 "remove_configs", 217 ]) 218 configs -= v8_remove_configs 219 configs += v8_add_configs 220 if (defined(invoker.remove_configs)) { 221 configs -= invoker.remove_configs 222 } 223 configs += invoker.configs 224 if (is_linux || is_chromeos) { 225 # For enabling ASLR. 226 ldflags = [ "-pie" ] 227 } 228 if (defined(testonly) && testonly && v8_code_coverage) { 229 # Only add code coverage cflags for non-test files for performance 230 # reasons. 231 if (is_clang) { 232 configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ] 233 configs += 234 [ "//build/config/sanitizers:default_sanitizer_flags_but_coverage" ] 235 } else { 236 configs -= [ v8_path_prefix + ":v8_gcov_coverage_cflags" ] 237 } 238 } 239 deps += [ v8_path_prefix + ":v8_dump_build_config" ] 240 } 241} 242 243template("v8_component") { 244 component(target_name) { 245 forward_variables_from(invoker, 246 "*", 247 [ 248 "configs", 249 "remove_configs", 250 ]) 251 configs -= v8_remove_configs 252 configs += v8_add_configs 253 if (defined(invoker.remove_configs)) { 254 configs -= invoker.remove_configs 255 } 256 configs += invoker.configs 257 } 258} 259 260template("v8_shared_library") { 261 shared_library(target_name) { 262 forward_variables_from(invoker, 263 "*", 264 [ 265 "configs", 266 "remove_configs", 267 ]) 268 configs -= v8_remove_configs 269 configs += v8_add_configs 270 if (defined(invoker.remove_configs)) { 271 configs -= invoker.remove_configs 272 } 273 if (defined(invoker.configs)) { 274 configs += invoker.configs 275 } 276 } 277} 278 279template("v8_static_library") { 280 static_library(target_name) { 281 complete_static_lib = true 282 forward_variables_from(invoker, "*", [ "configs" ]) 283 configs -= v8_remove_configs 284 configs -= [ "//build/config/compiler:thin_archive" ] 285 configs += v8_add_configs 286 configs += invoker.configs 287 } 288} 289