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 (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 == "x64") { 70 # This is a cross-compile from an x64 host to either a non-Intel target 71 # cpu or a different target OS. Clang will always be used by default on the 72 # host, unless this is a ChromeOS build, in which case the same toolchain 73 # (Clang or GCC) will be used for target and host by default. 74 if (is_chromeos && !is_clang) { 75 _clang = "" 76 } else { 77 _clang = "clang_" 78 } 79 80 if (v8_current_cpu == "x64" || v8_current_cpu == "x86") { 81 _cpus = v8_current_cpu 82 } else if (v8_current_cpu == "arm64" || v8_current_cpu == "mips64el") { 83 if (is_win && v8_current_cpu == "arm64") { 84 # set _cpus to blank for Windows ARM64 so host_toolchain could be 85 # selected as snapshot toolchain later. 86 _cpus = "" 87 } else { 88 _cpus = "x64_v8_${v8_current_cpu}" 89 } 90 } else if (v8_current_cpu == "arm" || v8_current_cpu == "mipsel") { 91 _cpus = "x86_v8_${v8_current_cpu}" 92 } else { 93 # This branch should not be reached; leave _cpus blank so the assert 94 # below will fail. 95 _cpus = "" 96 } 97 98 if (_cpus != "") { 99 v8_snapshot_toolchain = "//build/toolchain/${host_os}:${_clang}${_cpus}" 100 } else if (is_win && v8_current_cpu == "arm64") { 101 # cross compile Windows arm64 with host toolchain. 102 v8_snapshot_toolchain = host_toolchain 103 } 104 } 105} 106 107assert(v8_snapshot_toolchain != "", 108 "Do not know how to build a snapshot for $current_toolchain " + 109 "on $host_os $host_cpu") 110 111# We reuse the snapshot toolchain for building torque and other generators to 112# avoid building v8_libbase on the host more than once. On mips with big endian, 113# the snapshot toolchain is the target toolchain and, hence, can't be used. 114v8_generator_toolchain = v8_snapshot_toolchain 115if (host_cpu == "x64" && 116 (v8_current_cpu == "mips" || v8_current_cpu == "mips64")) { 117 v8_generator_toolchain = "//build/toolchain/linux:clang_x64" 118} 119