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/jumbo.gni") 6import("//build/config/sanitizers/sanitizers.gni") 7import("//build/config/v8_target_cpu.gni") 8import("//build/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 # Enable the snapshot feature, for fast context creation. 35 # http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html 36 # TODO(thakis): Make snapshots work in 64-bit win/cross builds, 37 # https://803591 38 v8_use_snapshot = !(is_win && host_os != "win" && target_cpu == "x64") 39 40 # Enable several snapshots side-by-side (e.g. default and for trusted code). 41 v8_use_multi_snapshots = false 42 43 # Use external files for startup data blobs: 44 # the JS builtins sources and the start snapshot. 45 v8_use_external_startup_data = "" 46 47 # Enable ECMAScript Internationalization API. Enabling this feature will 48 # add a dependency on the ICU library. 49 v8_enable_i18n_support = true 50 51 # Use static libraries instead of source_sets. 52 v8_static_library = false 53 54 # Enable monolithic static library for embedders. 55 v8_monolithic = false 56} 57 58if (v8_use_external_startup_data == "") { 59 # If not specified as a gn arg, use external startup data by default if 60 # a snapshot is used and if we're not on ios. 61 v8_use_external_startup_data = v8_use_snapshot && !is_ios 62} 63 64if (v8_use_multi_snapshots) { 65 # Silently disable multi snapshots if they're incompatible with the current 66 # build configuration. This allows us to set v8_use_multi_snapshots=true on 67 # all bots, and e.g. no-snapshot bots will automatically do the right thing. 68 v8_use_multi_snapshots = 69 v8_use_external_startup_data && !build_with_chromium && !use_jumbo_build 70} 71 72if (v8_enable_backtrace == "") { 73 v8_enable_backtrace = is_debug && !v8_optimized_debug 74} 75 76# Points to // in v8 stand-alone or to //v8/ in chromium. We need absolute 77# paths for all configs in templates as they are shared in different 78# subdirectories. 79v8_path_prefix = get_path_info("../", "abspath") 80 81v8_inspector_js_protocol = v8_path_prefix + "/src/inspector/js_protocol.json" 82 83############################################################################### 84# Templates 85# 86 87# Common configs to remove or add in all v8 targets. 88v8_remove_configs = [] 89v8_add_configs = [ 90 v8_path_prefix + ":features", 91 v8_path_prefix + ":toolchain", 92] 93 94if (is_debug && !v8_optimized_debug) { 95 v8_remove_configs += [ "//build/config/compiler:default_optimization" ] 96 v8_add_configs += [ "//build/config/compiler:no_optimize" ] 97} else { 98 v8_remove_configs += [ "//build/config/compiler:default_optimization" ] 99 100 # TODO(crbug.com/621335) Rework this so that we don't have the confusion 101 # between "optimize_speed" and "optimize_max". 102 if (((is_posix && !is_android) || is_fuchsia) && !using_sanitizer) { 103 v8_add_configs += [ "//build/config/compiler:optimize_speed" ] 104 } else { 105 v8_add_configs += [ "//build/config/compiler:optimize_max" ] 106 } 107} 108 109if (v8_code_coverage && !is_clang) { 110 v8_add_configs += [ 111 v8_path_prefix + ":v8_gcov_coverage_cflags", 112 v8_path_prefix + ":v8_gcov_coverage_ldflags", 113 ] 114} 115 116if ((is_posix || is_fuchsia) && (v8_enable_backtrace || v8_monolithic)) { 117 v8_remove_configs += [ "//build/config/gcc:symbol_visibility_hidden" ] 118 v8_add_configs += [ "//build/config/gcc:symbol_visibility_default" ] 119} 120 121# On MIPS gcc_target_rpath and ldso_path might be needed for all builds. 122if (target_cpu == "mipsel" || target_cpu == "mips64el" || 123 target_cpu == "mips" || target_cpu == "mips64") { 124 v8_add_configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 125} 126 127if (!build_with_chromium && is_clang) { 128 v8_remove_configs += [ "//build/config/clang:find_bad_constructs" ] 129} 130 131# All templates should be kept in sync. 132template("v8_source_set") { 133 if (defined(invoker.split_count) && invoker.split_count > 1 && 134 defined(v8_static_library) && v8_static_library && is_win) { 135 link_target_type = "split_static_library" 136 } else if (defined(v8_static_library) && v8_static_library) { 137 link_target_type = "static_library" 138 } else { 139 if (use_jumbo_build) { 140 link_target_type = "jumbo_source_set" 141 } else { 142 link_target_type = "source_set" 143 } 144 } 145 target(link_target_type, target_name) { 146 forward_variables_from(invoker, "*", [ "configs" ]) 147 configs += invoker.configs 148 configs -= v8_remove_configs 149 configs += v8_add_configs 150 } 151} 152 153template("v8_header_set") { 154 jumbo_source_set(target_name) { 155 forward_variables_from(invoker, "*", [ "configs" ]) 156 configs += invoker.configs 157 configs -= v8_remove_configs 158 configs += v8_add_configs 159 } 160} 161 162template("v8_executable") { 163 executable(target_name) { 164 forward_variables_from(invoker, 165 "*", 166 [ 167 "configs", 168 "remove_configs", 169 ]) 170 if (defined(invoker.remove_configs)) { 171 configs -= invoker.remove_configs 172 } 173 configs += invoker.configs 174 configs -= v8_remove_configs 175 configs += v8_add_configs 176 if (is_linux) { 177 # For enabling ASLR. 178 ldflags = [ "-pie" ] 179 } 180 if (defined(testonly) && testonly && v8_code_coverage) { 181 # Only add code coverage cflags for non-test files for performance 182 # reasons. 183 if (is_clang) { 184 configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ] 185 configs += 186 [ "//build/config/sanitizers:default_sanitizer_flags_but_coverage" ] 187 } else { 188 configs -= [ v8_path_prefix + ":v8_gcov_coverage_cflags" ] 189 } 190 } 191 deps += [ v8_path_prefix + ":v8_dump_build_config" ] 192 } 193} 194 195template("v8_component") { 196 component(target_name) { 197 forward_variables_from(invoker, "*", [ "configs" ]) 198 configs += invoker.configs 199 configs -= v8_remove_configs 200 configs += v8_add_configs 201 } 202} 203 204template("v8_static_library") { 205 static_library(target_name) { 206 complete_static_lib = true 207 forward_variables_from(invoker, "*", [ "configs" ]) 208 configs += invoker.configs 209 configs -= v8_remove_configs 210 configs -= [ "//build/config/compiler:thin_archive" ] 211 configs += v8_add_configs 212 } 213} 214