BUILD.gn 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. # Copyright (c) 2014 The Native Client Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/nacl/config.gni")
  5. import("//build/config/sysroot.gni")
  6. import("//build/toolchain/nacl_toolchain.gni")
  7. # Add the toolchain revision as a preprocessor define so that sources are
  8. # rebuilt when a toolchain is updated.
  9. # Idea we could use the toolchain deps feature, but currently that feature is
  10. # bugged and does not trigger a rebuild.
  11. # https://code.google.com/p/chromium/issues/detail?id=431880
  12. # Calls to get the toolchain revision are relatively slow, so do them all in a
  13. # single batch to amortize python startup, etc.
  14. revisions = exec_script("//native_client/build/get_toolchain_revision.py",
  15. [
  16. "nacl_x86_glibc",
  17. "nacl_arm_glibc",
  18. "pnacl_newlib",
  19. "saigo_newlib",
  20. ],
  21. "trim list lines")
  22. nacl_x86_glibc_rev = revisions[0]
  23. nacl_arm_glibc_rev = revisions[1]
  24. pnacl_newlib_rev = revisions[2]
  25. saigo_newlib_rev = revisions[3]
  26. if (host_os == "win") {
  27. toolsuffix = ".exe"
  28. } else {
  29. toolsuffix = ""
  30. }
  31. # The PNaCl toolchain tools are all wrapper scripts rather than binary
  32. # executables. On POSIX systems, nobody cares what kind of executable
  33. # file you are. But on Windows, scripts (.bat files) cannot be run
  34. # directly and need the Windows shell (cmd.exe) specified explicily.
  35. if (host_os == "win") {
  36. # NOTE! The //build/toolchain/gcc_*_wrapper.py scripts recognize
  37. # this exact prefix string, so they must be updated if this string
  38. # is changed in any way.
  39. scriptprefix = "cmd /c call "
  40. scriptsuffix = ".bat"
  41. } else {
  42. scriptprefix = ""
  43. scriptsuffix = ""
  44. }
  45. # When the compilers are run via goma, rbe or ccache rather than directly by
  46. # GN/Ninja, the rbe/goma/ccache wrapper handles .bat files but gets confused
  47. # by being given the scriptprefix.
  48. if (host_os == "win" && !use_goma && !use_remoteexec && cc_wrapper == "") {
  49. compiler_scriptprefix = scriptprefix
  50. } else {
  51. compiler_scriptprefix = ""
  52. }
  53. template("pnacl_toolchain") {
  54. assert(defined(invoker.executable_extension),
  55. "Must define executable_extension")
  56. nacl_toolchain(target_name) {
  57. toolchain_package = "pnacl_newlib"
  58. toolchain_revision = pnacl_newlib_rev
  59. toolprefix =
  60. rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/pnacl-",
  61. root_build_dir)
  62. if (host_os == "win") {
  63. # Flip the slashes so that copy/paste of the commands works.
  64. # This is also done throughout build\toolchain\win\BUILD.gn
  65. toolprefix = string_replace(toolprefix, "/", "\\")
  66. }
  67. cc = compiler_scriptprefix + toolprefix + "clang" + scriptsuffix
  68. cxx = compiler_scriptprefix + toolprefix + "clang++" + scriptsuffix
  69. ar = toolprefix + "ar" + scriptsuffix
  70. readelf = scriptprefix + toolprefix + "readelf" + scriptsuffix
  71. nm = scriptprefix + toolprefix + "nm" + scriptsuffix
  72. if (defined(invoker.strip)) {
  73. strip = scriptprefix + toolprefix + invoker.strip + scriptsuffix
  74. }
  75. forward_variables_from(invoker,
  76. [
  77. "executable_extension",
  78. "is_clang_analysis_supported",
  79. "extra_cppflags",
  80. ])
  81. # Note this is not the usual "ld = cxx" because "ld" uses are
  82. # never run via goma, so this needs scriptprefix.
  83. ld = scriptprefix + toolprefix + "clang++" + scriptsuffix
  84. toolchain_args = {
  85. is_clang = true
  86. current_cpu = "pnacl"
  87. use_lld = false
  88. }
  89. }
  90. }
  91. pnacl_toolchain("newlib_pnacl") {
  92. executable_extension = ".pexe"
  93. # The pnacl-finalize tool turns a .pexe.debug file into a .pexe file.
  94. # It's very similar in purpose to the traditional "strip" utility: it
  95. # turns what comes out of the linker into what you actually want to
  96. # distribute and run. PNaCl doesn't have a "strip"-like utility that
  97. # you ever actually want to use other than pnacl-finalize, so just
  98. # make pnacl-finalize the strip tool rather than adding an additional
  99. # step like "postlink" to run pnacl-finalize.
  100. strip = "finalize"
  101. }
  102. template("nacl_glibc_toolchain") {
  103. toolchain_cpu = target_name
  104. assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  105. assert(defined(invoker.toolchain_package), "Must define toolchain_package")
  106. assert(defined(invoker.toolchain_revision), "Must define toolchain_revision")
  107. forward_variables_from(invoker,
  108. [
  109. "toolchain_package",
  110. "toolchain_revision",
  111. ])
  112. toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
  113. invoker.toolchain_tuple + "-",
  114. root_build_dir)
  115. if (host_os == "win") {
  116. # Flip the slashes so that copy/paste of the commands works.
  117. # This is also done throughout build\toolchain\win\BUILD.gn
  118. toolprefix = string_replace(toolprefix, "/", "\\")
  119. }
  120. nacl_toolchain("glibc_" + toolchain_cpu) {
  121. cc = toolprefix + "gcc" + toolsuffix
  122. cxx = toolprefix + "g++" + toolsuffix
  123. ar = toolprefix + "ar" + toolsuffix
  124. ld = cxx
  125. readelf = toolprefix + "readelf" + toolsuffix
  126. nm = toolprefix + "nm" + toolsuffix
  127. strip = toolprefix + "strip" + toolsuffix
  128. toolchain_args = {
  129. current_cpu = toolchain_cpu
  130. # reclient does not support gcc.
  131. use_remoteexec = false
  132. is_clang = false
  133. is_nacl_glibc = true
  134. use_lld = false
  135. }
  136. }
  137. }
  138. nacl_glibc_toolchain("x86") {
  139. toolchain_package = "nacl_x86_glibc"
  140. toolchain_revision = nacl_x86_glibc_rev
  141. # Rely on the :compiler_cpu_abi config adding the -m32 flag here rather
  142. # than using the i686-nacl binary directly. This is a because i686-nacl-gcc
  143. # is a shell script wrapper around x86_64-nacl-gcc and goma has trouble with
  144. # compiler executables that are shell scripts (so the i686 'compiler' is not
  145. # currently in goma).
  146. toolchain_tuple = "x86_64-nacl"
  147. }
  148. nacl_glibc_toolchain("x64") {
  149. toolchain_package = "nacl_x86_glibc"
  150. toolchain_revision = nacl_x86_glibc_rev
  151. toolchain_tuple = "x86_64-nacl"
  152. }
  153. nacl_glibc_toolchain("arm") {
  154. toolchain_package = "nacl_arm_glibc"
  155. toolchain_revision = nacl_arm_glibc_rev
  156. toolchain_tuple = "arm-nacl"
  157. }
  158. template("nacl_clang_toolchain") {
  159. toolchain_cpu = target_name
  160. assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  161. toolchain_package = "pnacl_newlib"
  162. toolchain_revision = pnacl_newlib_rev
  163. toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
  164. invoker.toolchain_tuple + "-",
  165. root_build_dir)
  166. if (host_os == "win") {
  167. # Flip the slashes so that copy/paste of the commands works.
  168. # This is also done throughout build\toolchain\win\BUILD.gn
  169. toolprefix = string_replace(toolprefix, "/", "\\")
  170. }
  171. nacl_toolchain("clang_newlib_" + toolchain_cpu) {
  172. cc = toolprefix + "clang" + toolsuffix
  173. cxx = toolprefix + "clang++" + toolsuffix
  174. ar = toolprefix + "ar" + toolsuffix
  175. ld = cxx
  176. readelf = toolprefix + "readelf" + toolsuffix
  177. nm = toolprefix + "nm" + toolsuffix
  178. strip = toolprefix + "strip" + toolsuffix
  179. toolchain_args = {
  180. current_cpu = toolchain_cpu
  181. is_clang = true
  182. use_lld = false
  183. }
  184. }
  185. }
  186. template("nacl_irt_toolchain") {
  187. toolchain_cpu = target_name
  188. assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  189. toolchain_package = "saigo_newlib"
  190. toolchain_revision = saigo_newlib_rev
  191. toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
  192. invoker.toolchain_tuple + "-",
  193. root_build_dir)
  194. if (host_os == "win") {
  195. # Flip the slashes so that copy/paste of the commands works.
  196. # This is also done throughout build\toolchain\win\BUILD.gn
  197. toolprefix = string_replace(toolprefix, "/", "\\")
  198. }
  199. link_irt = rebase_path("//native_client/build/link_irt.py", root_build_dir)
  200. tls_edit_label =
  201. "//native_client/src/tools/tls_edit:tls_edit($host_toolchain)"
  202. host_toolchain_out_dir =
  203. rebase_path(get_label_info(tls_edit_label, "root_out_dir"),
  204. root_build_dir)
  205. tls_edit = "${host_toolchain_out_dir}/tls_edit"
  206. nacl_toolchain("irt_" + toolchain_cpu) {
  207. cc = toolprefix + "clang" + toolsuffix
  208. cxx = toolprefix + "clang++" + toolsuffix
  209. ar = toolprefix + "ar" + toolsuffix
  210. readelf = toolprefix + "readelf" + toolsuffix
  211. nm = toolprefix + "nm" + toolsuffix
  212. strip = toolprefix + "strip" + toolsuffix
  213. # Some IRT implementations (notably, Chromium's) contain C++ code,
  214. # so we need to link w/ the C++ linker.
  215. ld = "${python_path} ${link_irt} --tls-edit=${tls_edit} --link-cmd=${cxx} --readelf-cmd=${readelf}"
  216. toolchain_args = {
  217. current_cpu = toolchain_cpu
  218. is_clang = true
  219. use_lld = false
  220. is_nacl_saigo = true
  221. }
  222. # TODO(ncbray): depend on link script
  223. deps = [ tls_edit_label ]
  224. }
  225. }
  226. template("nacl_clang_toolchains") {
  227. assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  228. nacl_clang_toolchain(target_name) {
  229. toolchain_tuple = invoker.toolchain_tuple
  230. }
  231. nacl_irt_toolchain(target_name) {
  232. toolchain_tuple = invoker.toolchain_tuple
  233. }
  234. }
  235. nacl_clang_toolchains("x86") {
  236. # Rely on :compiler_cpu_abi adding -m32. See nacl_x86_glibc above.
  237. toolchain_tuple = "x86_64-nacl"
  238. }
  239. nacl_clang_toolchains("x64") {
  240. toolchain_tuple = "x86_64-nacl"
  241. }
  242. nacl_clang_toolchains("arm") {
  243. toolchain_tuple = "arm-nacl"
  244. }
  245. nacl_clang_toolchains("mipsel") {
  246. toolchain_tuple = "mipsel-nacl"
  247. }