OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/clang/clang.gni") | 5 import("//build/config/clang/clang.gni") |
6 import("//build/config/compiler/compiler.gni") | 6 import("//build/config/compiler/compiler.gni") |
7 import("//build/config/sanitizers/sanitizers.gni") | 7 import("//build/config/sanitizers/sanitizers.gni") |
8 import("//build/config/win/visual_studio_version.gni") | 8 import("//build/config/win/visual_studio_version.gni") |
9 import("//build/toolchain/goma.gni") | 9 import("//build/toolchain/goma.gni") |
10 import("//build/toolchain/toolchain.gni") | 10 import("//build/toolchain/toolchain.gni") |
(...skipping 26 matching lines...) Expand all Loading... |
37 exec_script("../../vs_toolchain.py", | 37 exec_script("../../vs_toolchain.py", |
38 [ | 38 [ |
39 "copy_dlls", | 39 "copy_dlls", |
40 rebase_path(root_build_dir), | 40 rebase_path(root_build_dir), |
41 configuration_name, | 41 configuration_name, |
42 target_cpu, | 42 target_cpu, |
43 ]) | 43 ]) |
44 } | 44 } |
45 | 45 |
46 # Parameters: | 46 # Parameters: |
47 # toolchain_cpu: current_cpu to pass as a build arg | 47 # environment: File name of environment file. |
48 # toolchain_os: current_os to pass as a build arg | 48 # |
49 # environment: File name of environment file. | 49 # You would also define a toolchain_args variable with at least these set: |
| 50 # current_cpu: current_cpu to pass as a build arg |
| 51 # current_os: current_os to pass as a build arg |
50 template("msvc_toolchain") { | 52 template("msvc_toolchain") { |
51 env = invoker.environment | 53 toolchain(target_name) { |
| 54 # When invoking this toolchain not as the default one, these args will be |
| 55 # passed to the build. They are ignored when this is the default toolchain. |
| 56 assert(defined(invoker.toolchain_args)) |
| 57 toolchain_args = { |
| 58 if (defined(invoker.toolchain_args)) { |
| 59 forward_variables_from(invoker.toolchain_args, "*") |
| 60 } |
52 | 61 |
53 if (invoker.is_clang && host_os != "win") { | 62 # This value needs to be passed through unchanged. |
54 # This toolchain definition uses response files for compilations. GN uses | 63 host_toolchain = host_toolchain |
55 # the quoting rules of the host OS, while clang-cl always defaults to | |
56 # cmd.exe quoting rules for parsing response files. Tell clang-cl to use | |
57 # POSIX quoting rules, so it can understand what GN generates. | |
58 cl = "${invoker.cl} --rsp-quoting=posix" | |
59 } else { | |
60 cl = invoker.cl | |
61 } | |
62 | 64 |
63 if (use_lld) { | 65 current_os = "win" |
64 if (host_os == "win") { | |
65 lld_link = "lld-link.exe" | |
66 } else { | |
67 lld_link = "lld-link" | |
68 } | 66 } |
69 prefix = rebase_path("$clang_base_path/bin", root_build_dir) | |
70 | 67 |
71 # lld-link includes a replacement for lib.exe that can produce thin | |
72 # archives and understands bitcode (for lto builds). | |
73 lib = "$prefix/$lld_link /lib /llvmlibthin" | |
74 link = "$prefix/$lld_link" | |
75 } else { | |
76 lib = "lib.exe" | |
77 link = "link.exe" | |
78 } | |
79 | |
80 # If possible, pass system includes as flags to the compiler. When that's | |
81 # not possible, load a full environment file (containing %INCLUDE% and | |
82 # %PATH%) -- e.g. 32-bit MSVS builds require %PATH% to be set and just passing | |
83 # in a list of include directories isn't enough. | |
84 if (defined(invoker.sys_include_flags)) { | |
85 env_wrapper = "" | |
86 sys_include_flags = "${invoker.sys_include_flags} " # Note trailing space. | |
87 } else { | |
88 # clang-cl doesn't need this env hoop, so omit it there. | |
89 assert(!invoker.is_clang) | |
90 env_wrapper = "ninja -t msvc -e $env -- " # Note trailing space. | |
91 sys_include_flags = "" | |
92 } | |
93 | |
94 toolchain(target_name) { | |
95 # Make these apply to all tools below. | 68 # Make these apply to all tools below. |
96 lib_switch = "" | 69 lib_switch = "" |
97 lib_dir_switch = "/LIBPATH:" | 70 lib_dir_switch = "/LIBPATH:" |
98 | 71 |
99 # Object files go in this directory. | 72 # Object files go in this directory. |
100 object_subdir = "{{target_out_dir}}/{{label_name}}" | 73 object_subdir = "{{target_out_dir}}/{{label_name}}" |
101 | 74 |
| 75 env = invoker.environment |
| 76 |
| 77 # When the invoker has explicitly overridden use_goma or cc_wrapper in the |
| 78 # toolchain args, use those values, otherwise default to the global one. |
| 79 # This works because the only reasonable override that toolchains might |
| 80 # supply for these values are to force-disable them. |
| 81 if (defined(toolchain_args.is_clang)) { |
| 82 toolchain_uses_clang = toolchain_args.is_clang |
| 83 } else { |
| 84 toolchain_uses_clang = is_clang |
| 85 } |
| 86 |
| 87 if (toolchain_uses_clang && host_os != "win") { |
| 88 # This toolchain definition uses response files for compilations. GN uses |
| 89 # the quoting rules of the host OS, while clang-cl always defaults to |
| 90 # cmd.exe quoting rules for parsing response files. Tell clang-cl to use |
| 91 # POSIX quoting rules, so it can understand what GN generates. |
| 92 cl = "${invoker.cl} --rsp-quoting=posix" |
| 93 } else { |
| 94 cl = invoker.cl |
| 95 } |
| 96 |
| 97 if (use_lld) { |
| 98 if (host_os == "win") { |
| 99 lld_link = "lld-link.exe" |
| 100 } else { |
| 101 lld_link = "lld-link" |
| 102 } |
| 103 prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
| 104 |
| 105 # lld-link includes a replacement for lib.exe that can produce thin |
| 106 # archives and understands bitcode (for lto builds). |
| 107 lib = "$prefix/$lld_link /lib /llvmlibthin" |
| 108 link = "$prefix/$lld_link" |
| 109 } else { |
| 110 lib = "lib.exe" |
| 111 link = "link.exe" |
| 112 } |
| 113 |
| 114 # If possible, pass system includes as flags to the compiler. When that's |
| 115 # not possible, load a full environment file (containing %INCLUDE% and |
| 116 # %PATH%) -- e.g. 32-bit MSVS builds require %PATH% to be set and just |
| 117 # passing in a list of include directories isn't enough. |
| 118 if (defined(invoker.sys_include_flags)) { |
| 119 env_wrapper = "" |
| 120 sys_include_flags = "${invoker.sys_include_flags} " # Note trailing space
. |
| 121 } else { |
| 122 # clang-cl doesn't need this env hoop, so omit it there. |
| 123 assert(!toolchain_uses_clang) |
| 124 env_wrapper = "ninja -t msvc -e $env -- " # Note trailing space. |
| 125 sys_include_flags = "" |
| 126 } |
| 127 |
102 tool("cc") { | 128 tool("cc") { |
103 rspfile = "{{output}}.rsp" | 129 rspfile = "{{output}}.rsp" |
104 precompiled_header_type = "msvc" | 130 precompiled_header_type = "msvc" |
105 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" | 131 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb" |
106 | 132 |
107 # Label names may have spaces in them so the pdbname must be quoted. The | 133 # Label names may have spaces in them so the pdbname must be quoted. The |
108 # source and output don't need to be quoted because GN knows they're a | 134 # source and output don't need to be quoted because GN knows they're a |
109 # full file name and will quote automatically when necessary. | 135 # full file name and will quote automatically when necessary. |
110 command = "$env_wrapper$cl /nologo /showIncludes /FC @$rspfile /c {{source
}} /Fo{{output}} /Fd\"$pdbname\"" | 136 command = "$env_wrapper$cl /nologo /showIncludes /FC @$rspfile /c {{source
}} /Fo{{output}} /Fd\"$pdbname\"" |
111 depsformat = "msvc" | 137 depsformat = "msvc" |
(...skipping 23 matching lines...) Expand all Loading... |
135 | 161 |
136 tool("rc") { | 162 tool("rc") { |
137 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{
include_dirs}} /fo{{output}} {{source}}" | 163 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{
include_dirs}} /fo{{output}} {{source}}" |
138 outputs = [ | 164 outputs = [ |
139 "$object_subdir/{{source_name_part}}.res", | 165 "$object_subdir/{{source_name_part}}.res", |
140 ] | 166 ] |
141 description = "RC {{output}}" | 167 description = "RC {{output}}" |
142 } | 168 } |
143 | 169 |
144 tool("asm") { | 170 tool("asm") { |
145 if (invoker.toolchain_cpu == "x64") { | 171 if (toolchain_args.current_cpu == "x64") { |
146 ml = "ml64.exe" | 172 ml = "ml64.exe" |
147 } else { | 173 } else { |
148 ml = "ml.exe" | 174 ml = "ml.exe" |
149 } | 175 } |
150 command = "$python_path gyp-win-tool asm-wrapper $env $ml {{defines}} {{in
clude_dirs}} {{asmflags}} /c /Fo{{output}} {{source}}" | 176 command = "$python_path gyp-win-tool asm-wrapper $env $ml {{defines}} {{in
clude_dirs}} {{asmflags}} /c /Fo{{output}} {{source}}" |
151 description = "ASM {{output}}" | 177 description = "ASM {{output}}" |
152 outputs = [ | 178 outputs = [ |
153 "$object_subdir/{{source_name_part}}.obj", | 179 "$object_subdir/{{source_name_part}}.obj", |
154 ] | 180 ] |
155 } | 181 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 # each toolchain because GN doesn't allow a template to be used here. | 283 # each toolchain because GN doesn't allow a template to be used here. |
258 # See //build/toolchain/toolchain.gni for details. | 284 # See //build/toolchain/toolchain.gni for details. |
259 tool("stamp") { | 285 tool("stamp") { |
260 command = stamp_command | 286 command = stamp_command |
261 description = stamp_description | 287 description = stamp_description |
262 } | 288 } |
263 tool("copy") { | 289 tool("copy") { |
264 command = copy_command | 290 command = copy_command |
265 description = copy_description | 291 description = copy_description |
266 } | 292 } |
267 | |
268 # When invoking this toolchain not as the default one, these args will be | |
269 # passed to the build. They are ignored when this is the default toolchain. | |
270 toolchain_args() { | |
271 current_cpu = invoker.toolchain_cpu | |
272 if (defined(invoker.toolchain_os)) { | |
273 current_os = invoker.toolchain_os | |
274 } | |
275 | |
276 # These share a name with global variables that are already defined, and | |
277 # forward_variables_from won't clobber the existing value, so we need to | |
278 # set it explicitly. | |
279 if (defined(invoker.is_clang)) { | |
280 is_clang = invoker.is_clang | |
281 } | |
282 if (defined(invoker.is_component_build)) { | |
283 is_component_build = invoker.is_component_build | |
284 } | |
285 | |
286 # This value needs to be passed through unchanged. | |
287 host_toolchain = host_toolchain | |
288 } | |
289 } | 293 } |
290 } | 294 } |
291 | 295 |
292 if (is_clang) { | 296 if (is_clang) { |
293 sys_include_prefix = "-imsvc" | 297 sys_include_prefix = "-imsvc" |
294 } else { | 298 } else { |
295 # MSVC doesn't have the concept of system headers. | 299 # MSVC doesn't have the concept of system headers. |
296 sys_include_prefix = "/I" | 300 sys_include_prefix = "/I" |
297 } | 301 } |
298 | 302 |
(...skipping 13 matching lines...) Expand all Loading... |
312 gyp_win_tool_path, | 316 gyp_win_tool_path, |
313 windows_sdk_path, | 317 windows_sdk_path, |
314 visual_studio_runtime_dirs, | 318 visual_studio_runtime_dirs, |
315 "x86", | 319 "x86", |
316 "${sys_include_prefix}", | 320 "${sys_include_prefix}", |
317 ], | 321 ], |
318 "scope") | 322 "scope") |
319 | 323 |
320 msvc_toolchain("x86") { | 324 msvc_toolchain("x86") { |
321 environment = "environment.x86" | 325 environment = "environment.x86" |
322 toolchain_cpu = "x86" | |
323 cl = "${goma_prefix}\"${x86_toolchain_data.vc_bin_dir}/cl.exe\"" | 326 cl = "${goma_prefix}\"${x86_toolchain_data.vc_bin_dir}/cl.exe\"" |
324 is_clang = false | 327 toolchain_args = { |
| 328 current_cpu = "x86" |
| 329 is_clang = false |
| 330 } |
325 } | 331 } |
326 | 332 |
327 msvc_toolchain("clang_x86") { | 333 msvc_toolchain("clang_x86") { |
328 environment = "environment.x86" | 334 environment = "environment.x86" |
329 toolchain_cpu = "x86" | |
330 prefix = rebase_path("$clang_base_path/bin", root_build_dir) | 335 prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
331 cl = "${goma_prefix}$prefix/${clang_cl}" | 336 cl = "${goma_prefix}$prefix/${clang_cl}" |
332 toolchain_os = "win" | |
333 is_clang = true | |
334 sys_include_flags = "${x86_toolchain_data.include_flags}" | 337 sys_include_flags = "${x86_toolchain_data.include_flags}" |
| 338 |
| 339 toolchain_args = { |
| 340 current_cpu = "x86" |
| 341 is_clang = true |
| 342 } |
335 } | 343 } |
336 } | 344 } |
337 | 345 |
338 # 64-bit toolchains. | 346 # 64-bit toolchains. |
339 x64_toolchain_data = exec_script("setup_toolchain.py", | 347 x64_toolchain_data = exec_script("setup_toolchain.py", |
340 [ | 348 [ |
341 visual_studio_path, | 349 visual_studio_path, |
342 gyp_win_tool_path, | 350 gyp_win_tool_path, |
343 windows_sdk_path, | 351 windows_sdk_path, |
344 visual_studio_runtime_dirs, | 352 visual_studio_runtime_dirs, |
345 "x64", | 353 "x64", |
346 "${sys_include_prefix}", | 354 "${sys_include_prefix}", |
347 ], | 355 ], |
348 "scope") | 356 "scope") |
349 | 357 |
350 template("win_x64_toolchains") { | 358 template("win_x64_toolchains") { |
351 # TODO(mcgrathr): These assignments are only required because of | 359 # TODO(mcgrathr): These assignments are only required because of |
352 # crbug.com/395883. Drop them if that ever gets fixed in GN. | 360 # crbug.com/395883. Drop them if that ever gets fixed in GN. |
353 goma_prefix = invoker.goma_prefix | 361 goma_prefix = invoker.goma_prefix |
354 x64_toolchain_data = invoker.x64_toolchain_data | 362 x64_toolchain_data = invoker.x64_toolchain_data |
355 clang_cl = invoker.clang_cl | 363 clang_cl = invoker.clang_cl |
356 | 364 |
357 msvc_toolchain(target_name) { | 365 msvc_toolchain(target_name) { |
358 environment = "environment.x64" | 366 environment = "environment.x64" |
359 toolchain_cpu = "x64" | |
360 cl = "${goma_prefix}\"${x64_toolchain_data.vc_bin_dir}/cl.exe\"" | 367 cl = "${goma_prefix}\"${x64_toolchain_data.vc_bin_dir}/cl.exe\"" |
361 is_clang = false | |
362 | 368 |
363 # This shares a name with a global and forward_variables_from won't clobber | 369 toolchain_args = { |
364 # the existing value, so we need to set it explicitly. | 370 if (defined(invoker.toolchain_args)) { |
365 if (defined(invoker.is_component_build)) { | 371 forward_variables_from(invoker.toolchain_args, "*") |
366 is_component_build = invoker.is_component_build | 372 } |
| 373 is_clang = false |
| 374 current_cpu = "x64" |
367 } | 375 } |
368 } | 376 } |
369 | 377 |
370 msvc_toolchain("clang_" + target_name) { | 378 msvc_toolchain("clang_" + target_name) { |
371 environment = "environment.x64" | 379 environment = "environment.x64" |
372 toolchain_cpu = "x64" | |
373 prefix = rebase_path("$clang_base_path/bin", root_build_dir) | 380 prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
374 cl = "${goma_prefix}$prefix/${clang_cl}" | 381 cl = "${goma_prefix}$prefix/${clang_cl}" |
375 toolchain_os = "win" | |
376 is_clang = true | |
377 sys_include_flags = "${x64_toolchain_data.include_flags}" | 382 sys_include_flags = "${x64_toolchain_data.include_flags}" |
378 | 383 |
379 # This shares a name with a global and forward_variables_from won't clobber | 384 toolchain_args = { |
380 # the existing value, so we need to set it explicitly. | 385 if (defined(invoker.toolchain_args)) { |
381 if (defined(invoker.is_component_build)) { | 386 forward_variables_from(invoker.toolchain_args, "*") |
382 is_component_build = invoker.is_component_build | 387 } |
| 388 is_clang = true |
| 389 current_cpu = "x64" |
383 } | 390 } |
384 } | 391 } |
385 } | 392 } |
386 | 393 |
387 win_x64_toolchains("x64") { | 394 win_x64_toolchains("x64") { |
388 # TODO(mcgrathr): These assignments are only required because of | 395 # TODO(mcgrathr): These assignments are only required because of |
389 # crbug.com/395883. Drop them if that ever gets fixed in GN. | 396 # crbug.com/395883. Drop them if that ever gets fixed in GN. |
390 goma_prefix = goma_prefix | 397 goma_prefix = goma_prefix |
391 x64_toolchain_data = x64_toolchain_data | 398 x64_toolchain_data = x64_toolchain_data |
392 } | 399 } |
393 | 400 |
394 # The nacl_win64 toolchain is nearly identical to the plain x64 toolchain. | 401 # The nacl_win64 toolchain is nearly identical to the plain x64 toolchain. |
395 # It's used solely for building nacl64.exe (//components/nacl/broker:nacl64). | 402 # It's used solely for building nacl64.exe (//components/nacl/broker:nacl64). |
396 # The only reason it's a separate toolchain is so that it can force | 403 # The only reason it's a separate toolchain is so that it can force |
397 # is_component_build to false in the toolchain_args() block, because | 404 # is_component_build to false in the toolchain_args() block, because |
398 # building nacl64.exe in component style does not work. | 405 # building nacl64.exe in component style does not work. |
399 win_x64_toolchains("nacl_win64") { | 406 win_x64_toolchains("nacl_win64") { |
400 is_component_build = false | |
401 | |
402 # TODO(mcgrathr): These assignments are only required because of | 407 # TODO(mcgrathr): These assignments are only required because of |
403 # crbug.com/395883. Drop them if that ever gets fixed in GN. | 408 # crbug.com/395883. Drop them if that ever gets fixed in GN. |
404 goma_prefix = goma_prefix | 409 goma_prefix = goma_prefix |
405 x64_toolchain_data = x64_toolchain_data | 410 x64_toolchain_data = x64_toolchain_data |
406 clang_cl = clang_cl | 411 clang_cl = clang_cl |
| 412 |
| 413 toolchain_args = { |
| 414 is_component_build = false |
| 415 } |
407 } | 416 } |
408 | 417 |
409 # WinRT toolchains. Only define these when targeting them. | 418 # WinRT toolchains. Only define these when targeting them. |
410 # | 419 # |
411 # NOTE: This is currently broken because it references vc_bin_dir. brettw@ | 420 # NOTE: This is currently broken because it references vc_bin_dir. brettw@ |
412 # changed this around a bit, and I don't know what this should be set to | 421 # changed this around a bit, and I don't know what this should be set to |
413 # in terms of what setup_toolchain returns for a certain CPU architecture. | 422 # in terms of what setup_toolchain returns for a certain CPU architecture. |
414 if (target_os == "winrt_81" || target_os == "winrt_81_phone" || | 423 if (target_os == "winrt_81" || target_os == "winrt_81_phone" || |
415 target_os == "winrt_10") { | 424 target_os == "winrt_10") { |
416 msvc_toolchain("winrt_x86") { | 425 msvc_toolchain("winrt_x86") { |
417 environment = "environment.winrt_x86" | 426 environment = "environment.winrt_x86" |
418 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\"" | 427 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\"" |
419 is_clang = false | |
420 | 428 |
421 toolchain_cpu = "x86" | 429 toolchain_args = { |
422 toolchain_os = current_os | 430 is_clang = false |
| 431 current_cpu = "x86" |
| 432 } |
423 } | 433 } |
424 | 434 |
425 msvc_toolchain("winrt_x64") { | 435 msvc_toolchain("winrt_x64") { |
426 environment = "environment.winrt_x64" | 436 environment = "environment.winrt_x64" |
427 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\"" | 437 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\"" |
428 is_clang = false | |
429 | 438 |
430 toolchain_cpu = "x64" | 439 toolchain_args = { |
431 toolchain_os = current_os | 440 is_clang = false |
| 441 current_cpu = "x64" |
| 442 } |
432 } | 443 } |
433 } | 444 } |
OLD | NEW |