• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
28import("//build/config/v8_target_cpu.gni")
29
30declare_args() {
31  # The v8 snapshot needs to be built by code that is compiled with a
32  # toolchain that matches the bit-width of the target CPU, but runs on
33  # the host.
34  v8_snapshot_toolchain = ""
35}
36
37# Try to infer the appropriate snapshot toolchain for the v8_current_cpu
38# where possible.
39#
40# Assume that v8_target_cpu (and hence v8_current_cpu) has been validated
41# as supported on the current host CPU and OS in v8_target_cpu.gni. The
42# logic below is complicated enough without also needing to do input
43# validation.
44#
45# There are test cases for this code posted as an attachment to
46# https://crbug.com/625353.
47#
48# TODO(GYP): Currently only regular (non-cross) compiles, and cross-compiles
49# from x64 hosts to Intel, ARM, or MIPS targets, are implemented. Add support
50# for the other supported configurations.
51
52if (v8_snapshot_toolchain == "") {
53  if (current_os == host_os && current_cpu == host_cpu) {
54    # This is not a cross-compile, so build the snapshot with the current
55    # toolchain.
56    v8_snapshot_toolchain = current_toolchain
57  } else if (current_os == host_os && current_cpu == "x86" &&
58             host_cpu == "x64") {
59    # This is an x64 -> x86 cross-compile, but x64 hosts can usually run x86
60    # binaries built for the same OS, so build the snapshot with the current
61    # toolchain here, too.
62    v8_snapshot_toolchain = current_toolchain
63  } else if (current_os == host_os && host_cpu == "arm64" &&
64             current_cpu == "arm") {
65    # Trying to compile 32-bit arm on arm64. Good luck!
66    v8_snapshot_toolchain = current_toolchain
67  } else if (host_cpu == "x64" &&
68             (v8_current_cpu == "mips" || v8_current_cpu == "mips64")) {
69    # We don't support snapshot generation for big-endian targets,
70    # therefore snapshots will need to be built using native mksnapshot
71    # in combination with qemu
72    v8_snapshot_toolchain = current_toolchain
73  } else if (host_cpu == "arm64" && current_cpu == "x64") {
74    # Cross-build from arm64 to intel (likely on an Apple Silicon mac).
75    v8_snapshot_toolchain =
76        "//build/toolchain/${host_os}:clang_arm64_v8_$v8_current_cpu"
77  } else if (host_cpu == "x64") {
78    # This is a cross-compile from an x64 host to either a non-Intel target
79    # cpu or a different target OS. Clang will always be used by default on the
80    # host, unless this is a ChromeOS build, in which case the same toolchain
81    # (Clang or GCC) will be used for target and host by default.
82    if (is_chromeos && !is_clang) {
83      _clang = ""
84    } else {
85      _clang = "clang_"
86    }
87
88    if (v8_current_cpu == "x64" || v8_current_cpu == "x86") {
89      _cpus = v8_current_cpu
90    } else if (v8_current_cpu == "arm64" || v8_current_cpu == "mips64el" ||
91               v8_current_cpu == "riscv64" || v8_current_cpu == "loong64") {
92      if (is_win && v8_current_cpu == "arm64") {
93        # set _cpus to blank for Windows ARM64 so host_toolchain could be
94        # selected as snapshot toolchain later.
95        _cpus = ""
96      } else {
97        _cpus = "x64_v8_${v8_current_cpu}"
98      }
99    } else if (v8_current_cpu == "arm" || v8_current_cpu == "mipsel") {
100      _cpus = "x86_v8_${v8_current_cpu}"
101    } else {
102      # This branch should not be reached; leave _cpus blank so the assert
103      # below will fail.
104      _cpus = ""
105    }
106
107    if (_cpus != "") {
108      v8_snapshot_toolchain = "//build/toolchain/${host_os}:${_clang}${_cpus}"
109    } else if (is_win && v8_current_cpu == "arm64") {
110      # cross compile Windows arm64 with host toolchain.
111      v8_snapshot_toolchain = host_toolchain
112    }
113  }
114}
115
116assert(v8_snapshot_toolchain != "",
117       "Do not know how to build a snapshot for $current_toolchain " +
118           "on $host_os $host_cpu")
119
120# We reuse the snapshot toolchain for building torque and other generators to
121# avoid building v8_libbase on the host more than once. On mips with big endian,
122# the snapshot toolchain is the target toolchain and, hence, can't be used.
123v8_generator_toolchain = v8_snapshot_toolchain
124if (host_cpu == "x64" &&
125    (v8_current_cpu == "mips" || v8_current_cpu == "mips64")) {
126  v8_generator_toolchain = "//build/toolchain/linux:clang_x64"
127}
128