Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 1 | declare_args() { |
| 2 | host_ar = ar |
| 3 | host_cc = cc |
| 4 | host_cxx = cxx |
| 5 | |
| 6 | if (is_android) { |
| 7 | if (host_os == "win") { |
| 8 | target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe" |
| 9 | target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe" |
| 10 | target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe" |
| 11 | } else { |
| 12 | target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar" |
| 13 | target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" |
| 14 | target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" |
| 15 | } |
| 16 | } else { |
| 17 | target_ar = ar |
| 18 | target_cc = cc |
| 19 | target_cxx = cxx |
| 20 | } |
| 21 | |
| 22 | cc_wrapper = "" |
| 23 | } |
| 24 | |
| 25 | if (host_os == "win") { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 26 | stamp = "cmd.exe /c echo >" |
| 27 | } else { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 28 | stamp = "touch" |
| 29 | } |
| 30 | |
| 31 | toolchain("msvc") { |
| 32 | lib_dir_switch = "/LIBPATH:" |
| 33 | |
| 34 | if (msvc == 2015) { |
Kaloyan Donev | f7466bd | 2018-03-16 14:45:35 +0200 | [diff] [blame] | 35 | if (target_cpu == "x86") { |
Brian Osman | b2a0025 | 2018-12-10 10:10:55 -0500 | [diff] [blame] | 36 | bin = "$win_vc/bin" |
Kaloyan Donev | f7466bd | 2018-03-16 14:45:35 +0200 | [diff] [blame] | 37 | } else { |
Brian Osman | b2a0025 | 2018-12-10 10:10:55 -0500 | [diff] [blame] | 38 | bin = "$win_vc/bin/amd64" |
Kaloyan Donev | f7466bd | 2018-03-16 14:45:35 +0200 | [diff] [blame] | 39 | } |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 40 | } else { |
Brian Osman | b2a0025 | 2018-12-10 10:10:55 -0500 | [diff] [blame] | 41 | bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu" |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | env_setup = "" |
| 45 | if (target_cpu == "x86") { |
| 46 | # Toolchain asset includes a script that configures for x86 building. |
| 47 | # We don't support x86 builds with local MSVC installations. |
| 48 | env_setup = "cmd /c $win_sdk/bin/SetEnv.cmd /x86 && " |
Brian Osman | a098265 | 2018-12-07 15:30:43 -0500 | [diff] [blame] | 49 | } else if (target_cpu == "arm64") { |
| 50 | # ARM64 compiler is incomplete - it relies on DLLs located in the host toolchain directory. |
Brian Osman | b2a0025 | 2018-12-10 10:10:55 -0500 | [diff] [blame] | 51 | env_setup = "cmd /C set \"PATH=%PATH%;$win_vc\\Tools\\MSVC\\$win_toolchain_version\\bin\\HostX64\\x64\" && " |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Ben Wagner | df57404 | 2018-03-13 15:11:14 -0400 | [diff] [blame] | 54 | cl_m32_flag = "" |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 55 | |
Mike Klein | c722f79 | 2017-07-31 11:57:21 -0400 | [diff] [blame] | 56 | if (clang_win != "") { |
Ben Wagner | df57404 | 2018-03-13 15:11:14 -0400 | [diff] [blame] | 57 | if (target_cpu == "x86") { |
| 58 | # cl.exe knows implicitly by the choice of executable that it's targeting |
| 59 | # x86, but clang-cl.exe needs to be told when targeting non-host |
| 60 | # platforms. (All our builders are x86-64, so x86 is always non-host.) |
| 61 | cl_m32_flag = "-m32" |
| 62 | } |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 63 | if (host_os == "win") { |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 64 | cl = "\"$clang_win/bin/clang-cl.exe\"" |
| 65 | lib = "\"$clang_win/bin/lld-link.exe\" /lib" |
| 66 | link = "\"$clang_win/bin/lld-link.exe\"" |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 67 | } else { |
Brian Osman | b2a0025 | 2018-12-10 10:10:55 -0500 | [diff] [blame] | 68 | cl = "\"$clang_win/bin/clang-cl\"" |
| 69 | lib = "\"$clang_win/bin/lld-link\" /lib" |
| 70 | link = "\"$clang_win/bin/lld-link\"" |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 71 | } |
Mike Klein | c722f79 | 2017-07-31 11:57:21 -0400 | [diff] [blame] | 72 | } else { |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 73 | cl = "\"$bin/cl.exe\"" |
| 74 | lib = "\"$bin/lib.exe\"" |
| 75 | link = "\"$bin/link.exe\"" |
Mike Klein | c722f79 | 2017-07-31 11:57:21 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 78 | tool("asm") { |
| 79 | _ml = "ml" |
| 80 | if (target_cpu == "x64") { |
| 81 | _ml += "64" |
| 82 | } |
Brian Osman | a098265 | 2018-12-07 15:30:43 -0500 | [diff] [blame] | 83 | command = "$env_setup \"$bin/$_ml.exe\" {{asmflags}} /nologo /c /Fo {{output}} {{source}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 84 | outputs = [ |
| 85 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 86 | ] |
| 87 | description = "assemble {{source}}" |
| 88 | } |
| 89 | |
| 90 | tool("cc") { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 91 | precompiled_header_type = "msvc" |
| 92 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 93 | |
| 94 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 95 | command = "$env_setup $cc_wrapper $cl /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_c}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 96 | depsformat = "msvc" |
| 97 | outputs = [ |
| 98 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 99 | ] |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 100 | description = "compile {{source}}" |
| 101 | } |
| 102 | |
| 103 | tool("cxx") { |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 104 | precompiled_header_type = "msvc" |
| 105 | pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
| 106 | |
| 107 | # Label names may have spaces so pdbname must be quoted. |
Mike Klein | a6e0c2b | 2018-12-10 08:48:03 -0500 | [diff] [blame] | 108 | command = "$env_setup $cc_wrapper $cl /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\"" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 109 | depsformat = "msvc" |
| 110 | outputs = [ |
| 111 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", |
| 112 | ] |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 113 | description = "compile {{source}}" |
| 114 | } |
| 115 | |
| 116 | tool("alink") { |
| 117 | rspfile = "{{output}}.rsp" |
| 118 | |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 119 | command = "$env_setup $lib /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 120 | outputs = [ |
| 121 | # Ignore {{output_extension}} and always use .lib, there's no reason to |
| 122 | # allow targets to override this extension on Windows. |
| 123 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 124 | ] |
| 125 | default_output_extension = ".lib" |
| 126 | default_output_dir = "{{target_out_dir}}" |
| 127 | |
| 128 | # inputs_newline works around a fixed per-line buffer size in the linker. |
| 129 | rspfile_content = "{{inputs_newline}}" |
| 130 | description = "link {{output}}" |
| 131 | } |
| 132 | |
| 133 | tool("solink") { |
| 134 | dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}" |
| 135 | libname = "${dllname}.lib" |
| 136 | pdbname = "${dllname}.pdb" |
| 137 | rspfile = "${dllname}.rsp" |
| 138 | |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 139 | command = "$env_setup $link /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 140 | outputs = [ |
| 141 | dllname, |
| 142 | libname, |
| 143 | pdbname, |
| 144 | ] |
| 145 | default_output_extension = ".dll" |
| 146 | default_output_dir = "{{root_out_dir}}" |
| 147 | |
| 148 | link_output = libname |
| 149 | depend_output = libname |
| 150 | runtime_outputs = [ |
| 151 | dllname, |
| 152 | pdbname, |
| 153 | ] |
| 154 | |
| 155 | # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn. |
| 156 | restat = true |
| 157 | |
| 158 | # inputs_newline works around a fixed per-line buffer size in the linker. |
| 159 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
| 160 | description = "link {{output}}" |
| 161 | } |
| 162 | |
| 163 | tool("link") { |
| 164 | exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" |
| 165 | pdbname = "$exename.pdb" |
| 166 | rspfile = "$exename.rsp" |
| 167 | |
Brian Salomon | 42ec7d7 | 2018-12-10 07:51:54 -0500 | [diff] [blame] | 168 | command = "$env_setup $link /nologo /OUT:$exename /PDB:$pdbname @$rspfile" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 169 | default_output_extension = ".exe" |
| 170 | default_output_dir = "{{root_out_dir}}" |
| 171 | outputs = [ |
| 172 | exename, |
| 173 | ] |
| 174 | |
| 175 | # inputs_newline works around a fixed per-line buffer size in the linker. |
| 176 | rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
| 177 | description = "link {{output}}" |
| 178 | } |
| 179 | |
| 180 | tool("stamp") { |
| 181 | command = "$stamp {{output}}" |
| 182 | description = "stamp {{output}}" |
| 183 | } |
| 184 | |
| 185 | tool("copy") { |
| 186 | cp_py = rebase_path("../cp.py") |
Ben Wagner | 96aa535 | 2018-06-19 10:34:32 -0400 | [diff] [blame] | 187 | command = "python $cp_py {{source}} {{output}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 188 | description = "copy {{source}} {{output}}" |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | template("gcc_like_toolchain") { |
| 193 | toolchain(target_name) { |
| 194 | ar = invoker.ar |
| 195 | cc = invoker.cc |
| 196 | cxx = invoker.cxx |
| 197 | lib_switch = "-l" |
| 198 | lib_dir_switch = "-L" |
| 199 | |
| 200 | tool("cc") { |
| 201 | depfile = "{{output}}.d" |
| 202 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}" |
| 203 | depsformat = "gcc" |
| 204 | outputs = [ |
| 205 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 206 | ] |
| 207 | description = "compile {{source}}" |
| 208 | } |
| 209 | |
| 210 | tool("cxx") { |
| 211 | depfile = "{{output}}.d" |
| 212 | command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}" |
| 213 | depsformat = "gcc" |
| 214 | outputs = [ |
| 215 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 216 | ] |
| 217 | description = "compile {{source}}" |
| 218 | } |
| 219 | |
| 220 | tool("objc") { |
| 221 | depfile = "{{output}}.d" |
| 222 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}" |
| 223 | depsformat = "gcc" |
| 224 | outputs = [ |
| 225 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 226 | ] |
| 227 | description = "compile {{source}}" |
| 228 | } |
| 229 | |
| 230 | tool("objcxx") { |
| 231 | depfile = "{{output}}.d" |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 232 | command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 233 | depsformat = "gcc" |
| 234 | outputs = [ |
| 235 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 236 | ] |
| 237 | description = "compile {{source}}" |
| 238 | } |
| 239 | |
| 240 | tool("asm") { |
| 241 | depfile = "{{output}}.d" |
| 242 | command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" |
| 243 | depsformat = "gcc" |
| 244 | outputs = [ |
| 245 | "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", |
| 246 | ] |
| 247 | description = "assemble {{source}}" |
| 248 | } |
| 249 | |
| 250 | tool("alink") { |
| 251 | rspfile = "{{output}}.rsp" |
| 252 | rspfile_content = "{{inputs}}" |
| 253 | ar_py = rebase_path("../ar.py") |
Ben Wagner | 96aa535 | 2018-06-19 10:34:32 -0400 | [diff] [blame] | 254 | command = "python $ar_py $ar {{output}} $rspfile" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 255 | outputs = [ |
| 256 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 257 | ] |
| 258 | default_output_extension = ".a" |
| 259 | output_prefix = "lib" |
| 260 | description = "link {{output}}" |
| 261 | } |
| 262 | |
| 263 | tool("solink") { |
| 264 | soname = "{{target_output_name}}{{output_extension}}" |
| 265 | |
| 266 | rpath = "-Wl,-soname,$soname" |
| 267 | if (is_mac) { |
| 268 | rpath = "-Wl,-install_name,@rpath/$soname" |
| 269 | } |
| 270 | |
Hal Canary | e1053ea | 2018-02-09 14:45:09 -0500 | [diff] [blame] | 271 | rspfile = "{{output}}.rsp" |
| 272 | rspfile_content = "{{inputs}}" |
| 273 | command = "$cc_wrapper $cxx -shared {{ldflags}} @$rspfile {{solibs}} {{libs}} $rpath -o {{output}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 274 | outputs = [ |
| 275 | "{{root_out_dir}}/$soname", |
| 276 | ] |
| 277 | output_prefix = "lib" |
| 278 | default_output_extension = ".so" |
| 279 | description = "link {{output}}" |
| 280 | } |
| 281 | |
| 282 | tool("link") { |
Hal Canary | e1053ea | 2018-02-09 14:45:09 -0500 | [diff] [blame] | 283 | rspfile = "{{output}}.rsp" |
| 284 | rspfile_content = "{{inputs}}" |
Mike Klein | 26ad6da | 2018-08-06 15:19:19 -0400 | [diff] [blame] | 285 | |
| 286 | # --start-group/--end-group let us link multiple .a {{inputs}} |
| 287 | # without worrying about their relative order on the link line. |
| 288 | # |
| 289 | # This is mostly important for traditional linkers like GNU ld and Gold. |
| 290 | # The Mac/iOS linker neither needs nor accepts these flags. |
| 291 | # LLD doesn't need these flags, but accepts and ignores them. |
| 292 | _start_group = "-Wl,--start-group" |
| 293 | _end_group = "-Wl,--end-group" |
| 294 | if (is_mac || is_ios) { |
| 295 | _start_group = "" |
| 296 | _end_group = "" |
| 297 | } |
| 298 | command = "$cc_wrapper $cxx {{ldflags}} $_start_group @$rspfile {{solibs}} $_end_group {{libs}} -o {{output}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 299 | outputs = [ |
| 300 | "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", |
| 301 | ] |
| 302 | description = "link {{output}}" |
| 303 | } |
| 304 | |
| 305 | tool("stamp") { |
| 306 | command = "$stamp {{output}}" |
| 307 | description = "stamp {{output}}" |
| 308 | } |
| 309 | |
| 310 | tool("copy") { |
| 311 | cp_py = rebase_path("../cp.py") |
Ben Wagner | 96aa535 | 2018-06-19 10:34:32 -0400 | [diff] [blame] | 312 | command = "python $cp_py {{source}} {{output}}" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 313 | description = "copy {{source}} {{output}}" |
| 314 | } |
| 315 | |
Jim Van Verth | 443a913 | 2017-11-28 09:45:26 -0500 | [diff] [blame] | 316 | tool("copy_bundle_data") { |
| 317 | cp_py = rebase_path("../cp.py") |
Ben Wagner | 96aa535 | 2018-06-19 10:34:32 -0400 | [diff] [blame] | 318 | command = "python $cp_py {{source}} {{output}}" |
Jim Van Verth | 443a913 | 2017-11-28 09:45:26 -0500 | [diff] [blame] | 319 | description = "copy_bundle_data {{source}} {{output}}" |
| 320 | } |
| 321 | |
| 322 | # We don't currently have any xcasset files so make this a NOP |
| 323 | tool("compile_xcassets") { |
| 324 | command = "true" |
| 325 | description = "compile_xcassets {{output}}" |
| 326 | } |
| 327 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 328 | toolchain_args = { |
| 329 | current_cpu = invoker.cpu |
| 330 | current_os = invoker.os |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | gcc_like_toolchain("gcc_like") { |
| 336 | cpu = current_cpu |
| 337 | os = current_os |
| 338 | ar = target_ar |
| 339 | cc = target_cc |
| 340 | cxx = target_cxx |
| 341 | } |
| 342 | |
| 343 | gcc_like_toolchain("gcc_like_host") { |
| 344 | cpu = host_cpu |
| 345 | os = host_os |
| 346 | ar = host_ar |
| 347 | cc = host_cc |
| 348 | cxx = host_cxx |
| 349 | } |