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 28 import("//build/config/v8_target_cpu.gni") 29 30 declare_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 52 if (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 == "win" && host_os == "mac" && is_clang) { 64 # This is a mac -> win cross-compile, which is only supported w/ clang. 65 v8_snapshot_toolchain = "//build/toolchain/mac:clang_${v8_current_cpu}" 66 } else if (host_cpu == "x64") { 67 # This is a cross-compile from an x64 host to either a non-Intel target 68 # cpu or a different target OS. Clang will always be used by default on the 69 # host, unless this is a ChromeOS build, in which case the same toolchain 70 # (Clang or GCC) will be used for target and host by default. 71 if (is_chromeos && !is_clang) { 72 _clang = "" 73 } else { 74 _clang = "clang_" 75 } 76 77 if (v8_current_cpu == "x64" || v8_current_cpu == "x86") { 78 _cpus = v8_current_cpu 79 } else if (v8_current_cpu == "arm64" || v8_current_cpu == "mips64el") { 80 _cpus = "x64_v8_${v8_current_cpu}" 81 } else if (v8_current_cpu == "arm" || v8_current_cpu == "mipsel") { 82 _cpus = "x86_v8_${v8_current_cpu}" 83 } else { 84 # This branch should not be reached; leave _cpus blank so the assert 85 # below will fail. 86 _cpus = "" 87 } 88 89 if (_cpus != "") { 90 v8_snapshot_toolchain = "//build/toolchain/${host_os}:${_clang}${_cpus}" 91 } 92 } 93 } 94 95 assert(v8_snapshot_toolchain != "", 96 "Do not know how to build a snapshot for $current_toolchain " + 97 "on $host_os $host_cpu") 98