v8.gni 9.5 KB

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