|
| 1 | +# Copyright (c) 2023 Microsoft, GmbH |
| 2 | +# Use of this source code is governed by the MIT license that can be |
| 3 | +# found in the LICENSE file. |
| 4 | + |
| 5 | +declare_args() { |
| 6 | + electron_js2c_toolchain = "" |
| 7 | +} |
| 8 | + |
| 9 | +if (electron_js2c_toolchain == "") { |
| 10 | + if (current_os == host_os && current_cpu == host_cpu) { |
| 11 | + # This is not a cross-compile, so build the snapshot with the current |
| 12 | + # toolchain. |
| 13 | + electron_js2c_toolchain = current_toolchain |
| 14 | + } else if (current_os == host_os && current_cpu == "x86" && |
| 15 | + host_cpu == "x64") { |
| 16 | + # This is an x64 -> x86 cross-compile, but x64 hosts can usually run x86 |
| 17 | + # binaries built for the same OS, so build the snapshot with the current |
| 18 | + # toolchain here, too. |
| 19 | + electron_js2c_toolchain = current_toolchain |
| 20 | + } else if (current_os == host_os && host_cpu == "arm64" && |
| 21 | + current_cpu == "arm") { |
| 22 | + # Trying to compile 32-bit arm on arm64. Good luck! |
| 23 | + electron_js2c_toolchain = current_toolchain |
| 24 | + } else if (host_cpu == current_cpu) { |
| 25 | + # Cross-build from same ISA on one OS to another. For example: |
| 26 | + # * targeting win/x64 on a linux/x64 host |
| 27 | + # * targeting win/arm64 on a mac/arm64 host |
| 28 | + electron_js2c_toolchain = host_toolchain |
| 29 | + } else if (host_cpu == "arm64" && current_cpu == "x64") { |
| 30 | + # Cross-build from arm64 to intel (likely on an Apple Silicon mac). |
| 31 | + electron_js2c_toolchain = |
| 32 | + "//build/toolchain/${host_os}:clang_arm64_v8_$current_cpu" |
| 33 | + } else if (host_cpu == "x64") { |
| 34 | + # This is a cross-compile from an x64 host to either a non-Intel target |
| 35 | + # cpu or to 32-bit x86 on a different target OS. |
| 36 | + |
| 37 | + assert(current_cpu != "x64", "handled by host_cpu == current_cpu branch") |
| 38 | + if (current_cpu == "x86") { |
| 39 | + _cpus = current_cpu |
| 40 | + } else if (current_cpu == "arm64") { |
| 41 | + if (is_win) { |
| 42 | + # set _cpus to blank for Windows ARM64 so host_toolchain could be |
| 43 | + # selected as snapshot toolchain later. |
| 44 | + _cpus = "" |
| 45 | + } else { |
| 46 | + _cpus = "x64_v8_${current_cpu}" |
| 47 | + } |
| 48 | + } else if (current_cpu == "arm") { |
| 49 | + _cpus = "x86_v8_${current_cpu}" |
| 50 | + } else { |
| 51 | + # This branch should not be reached; leave _cpus blank so the assert |
| 52 | + # below will fail. |
| 53 | + _cpus = "" |
| 54 | + } |
| 55 | + |
| 56 | + if (_cpus != "") { |
| 57 | + electron_js2c_toolchain = "//build/toolchain/${host_os}:clang_${_cpus}" |
| 58 | + } else if (is_win && current_cpu == "arm64") { |
| 59 | + # cross compile Windows arm64 with host toolchain. |
| 60 | + electron_js2c_toolchain = host_toolchain |
| 61 | + } |
| 62 | + } else if (host_cpu == "arm64" && current_cpu == "arm64" && |
| 63 | + host_os == "mac") { |
| 64 | + # cross compile iOS arm64 with host_toolchain |
| 65 | + electron_js2c_toolchain = host_toolchain |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +assert(electron_js2c_toolchain != "", |
| 70 | + "Do not know how to build js2c for $current_toolchain " + |
| 71 | + "on $host_os $host_cpu") |
0 commit comments