js2c_toolchain.gni 2.7 KB

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