snapshot_toolchain.gni 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Copyright 2015 the V8 project authors. All rights reserved.
  2. # Redistribution and use in source and binary forms, with or without
  3. # modification, are permitted provided that the following conditions are
  4. # met:
  5. #
  6. # * Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # * Redistributions in binary form must reproduce the above
  9. # copyright notice, this list of conditions and the following
  10. # disclaimer in the documentation and/or other materials provided
  11. # with the distribution.
  12. # * Neither the name of Google Inc. nor the names of its
  13. # contributors may be used to endorse or promote products derived
  14. # from this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. import("//build/config/v8_target_cpu.gni")
  28. declare_args() {
  29. # The v8 snapshot needs to be built by code that is compiled with a
  30. # toolchain that matches the bit-width of the target CPU, but runs on
  31. # the host.
  32. v8_snapshot_toolchain = ""
  33. }
  34. # Try to infer the appropriate snapshot toolchain for the v8_current_cpu
  35. # where possible.
  36. #
  37. # Assume that v8_target_cpu (and hence v8_current_cpu) has been validated
  38. # as supported on the current host CPU and OS in v8_target_cpu.gni. The
  39. # logic below is complicated enough without also needing to do input
  40. # validation.
  41. #
  42. # There are test cases for this code posted as an attachment to
  43. # https://crbug.com/625353.
  44. #
  45. # TODO(GYP): Currently only regular (non-cross) compiles, and cross-compiles
  46. # from x64 hosts to Intel, ARM, or MIPS targets, are implemented. Add support
  47. # for the other supported configurations.
  48. if (v8_snapshot_toolchain == "") {
  49. if (current_os == host_os && current_cpu == host_cpu) {
  50. # This is not a cross-compile, so build the snapshot with the current
  51. # toolchain.
  52. v8_snapshot_toolchain = current_toolchain
  53. } else if (current_os == host_os && current_cpu == "x86" &&
  54. host_cpu == "x64") {
  55. # This is an x64 -> x86 cross-compile, but x64 hosts can usually run x86
  56. # binaries built for the same OS, so build the snapshot with the current
  57. # toolchain here, too.
  58. v8_snapshot_toolchain = current_toolchain
  59. } else if (current_os == host_os && host_cpu == "arm64" &&
  60. current_cpu == "arm") {
  61. # Trying to compile 32-bit arm on arm64. Good luck!
  62. v8_snapshot_toolchain = current_toolchain
  63. } else if (host_cpu == "x64" &&
  64. (v8_current_cpu == "mips" || v8_current_cpu == "mips64")) {
  65. # We don't support snapshot generation for big-endian targets,
  66. # therefore snapshots will need to be built using native mksnapshot
  67. # in combination with qemu
  68. v8_snapshot_toolchain = current_toolchain
  69. } else if (host_cpu == "arm64" && current_cpu == "x64") {
  70. # Cross-build from arm64 to intel (likely on an Apple Silicon mac).
  71. v8_snapshot_toolchain =
  72. "//build/toolchain/${host_os}:clang_arm64_v8_$v8_current_cpu"
  73. } else if (host_cpu == "x64") {
  74. # This is a cross-compile from an x64 host to either a non-Intel target
  75. # cpu or a different target OS. Clang will always be used by default on the
  76. # host, unless this is a ChromeOS build, in which case the same toolchain
  77. # (Clang or GCC) will be used for target and host by default.
  78. if (is_chromeos && !is_clang) {
  79. _clang = ""
  80. } else {
  81. _clang = "clang_"
  82. }
  83. if (v8_current_cpu == "x64" || v8_current_cpu == "x86") {
  84. _cpus = v8_current_cpu
  85. } else if (v8_current_cpu == "arm64" || v8_current_cpu == "mips64el" ||
  86. v8_current_cpu == "riscv64" || v8_current_cpu == "loong64") {
  87. if (is_win && v8_current_cpu == "arm64") {
  88. # set _cpus to blank for Windows ARM64 so host_toolchain could be
  89. # selected as snapshot toolchain later.
  90. _cpus = ""
  91. } else {
  92. _cpus = "x64_v8_${v8_current_cpu}"
  93. }
  94. } else if (v8_current_cpu == "arm" || v8_current_cpu == "mipsel") {
  95. _cpus = "x86_v8_${v8_current_cpu}"
  96. } else {
  97. # This branch should not be reached; leave _cpus blank so the assert
  98. # below will fail.
  99. _cpus = ""
  100. }
  101. if (_cpus != "") {
  102. v8_snapshot_toolchain = "//build/toolchain/${host_os}:${_clang}${_cpus}"
  103. } else if (is_win && v8_current_cpu == "arm64") {
  104. # cross compile Windows arm64 with host toolchain.
  105. v8_snapshot_toolchain = host_toolchain
  106. }
  107. }
  108. }
  109. assert(v8_snapshot_toolchain != "",
  110. "Do not know how to build a snapshot for $current_toolchain " +
  111. "on $host_os $host_cpu")
  112. # We reuse the snapshot toolchain for building torque and other generators to
  113. # avoid building v8_libbase on the host more than once. On mips with big endian,
  114. # the snapshot toolchain is the target toolchain and, hence, can't be used.
  115. v8_generator_toolchain = v8_snapshot_toolchain
  116. if (host_cpu == "x64" &&
  117. (v8_current_cpu == "mips" || v8_current_cpu == "mips64")) {
  118. v8_generator_toolchain = "//build/toolchain/linux:clang_x64"
  119. }