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