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 declare_args() { |
| 6 # Path to the directory containing the VC binaries for the right |
| 7 # combination of host and target architectures. Currently only the |
| 8 # 64-bit host toolchain is supported, with either 32-bit or 64-bit targets. |
| 9 # If vc_bin_dir is not specified on the command line (and it normally |
| 10 # isn't), we will dynamically determine the right value to use at runtime. |
| 11 vc_bin_dir = "" |
| 12 } |
| 13 |
5 import("//build/config/win/visual_studio_version.gni") | 14 import("//build/config/win/visual_studio_version.gni") |
6 import("//build/toolchain/goma.gni") | 15 import("//build/toolchain/goma.gni") |
7 | 16 |
8 # Should only be running on Windows. | 17 # Should only be running on Windows. |
9 assert(is_win) | 18 assert(is_win) |
10 | 19 |
11 # Setup the Visual Studio state. | 20 # Setup the Visual Studio state. |
12 # | 21 # |
13 # Its arguments are the VS path and the compiler wrapper tool. It will write | 22 # Its arguments are the VS path and the compiler wrapper tool. It will write |
14 # "environment.x86" and "environment.x64" to the build directory and return a | 23 # "environment.x86" and "environment.x64" to the build directory and return a |
15 # list to us. | 24 # list to us. |
16 gyp_win_tool_path = rebase_path("//tools/gyp/pylib/gyp/win_tool.py", | 25 gyp_win_tool_path = |
17 root_build_dir) | 26 rebase_path("//tools/gyp/pylib/gyp/win_tool.py", root_build_dir) |
18 exec_script("setup_toolchain.py", | 27 |
19 [ | 28 toolchain_data = exec_script("setup_toolchain.py", |
20 visual_studio_path, | 29 [ |
21 gyp_win_tool_path, | 30 visual_studio_path, |
22 windows_sdk_path, | 31 gyp_win_tool_path, |
23 visual_studio_runtime_dirs | 32 windows_sdk_path, |
24 ]) | 33 visual_studio_runtime_dirs, |
| 34 cpu_arch, |
| 35 ], |
| 36 "scope") |
| 37 |
| 38 if (vc_bin_dir == "") { |
| 39 vc_bin_dir = toolchain_data.vc_bin_dir |
| 40 } |
25 | 41 |
26 # This value will be inherited in the toolchain below. | 42 # This value will be inherited in the toolchain below. |
27 concurrent_links = exec_script("../get_concurrent_links.py", [], "value") | 43 concurrent_links = exec_script("../get_concurrent_links.py", [], "value") |
28 | 44 |
29 # Parameters: | 45 # Parameters: |
30 # cpu_arch: cpu_arch to pass as a build arg | 46 # cpu_arch: cpu_arch to pass as a build arg |
31 # environment: File name of environment file. | 47 # environment: File name of environment file. |
32 template("msvc_toolchain") { | 48 template("msvc_toolchain") { |
33 if (defined(invoker.concurrent_links)) { | 49 if (defined(invoker.concurrent_links)) { |
34 concurrent_links = invoker.concurrent_links | 50 concurrent_links = invoker.concurrent_links |
35 } | 51 } |
36 | 52 |
37 env = invoker.environment | 53 env = invoker.environment |
38 | 54 |
39 if (is_debug) { | 55 if (is_debug) { |
40 configuration = "Debug" | 56 configuration = "Debug" |
41 } else { | 57 } else { |
42 configuration = "Release" | 58 configuration = "Release" |
43 } | 59 } |
44 exec_script("../../vs_toolchain.py", ["copy_dlls", | 60 exec_script("../../vs_toolchain.py", |
45 rebase_path(root_build_dir), | 61 [ |
46 configuration, | 62 "copy_dlls", |
47 invoker.cpu_arch]) | 63 rebase_path(root_build_dir), |
| 64 configuration, |
| 65 invoker.cpu_arch, |
| 66 ]) |
| 67 |
| 68 if (use_goma) { |
| 69 goma_prefix = "$goma_dir/gomacc.exe " |
| 70 } else { |
| 71 goma_prefix = "" |
| 72 } |
| 73 |
| 74 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\"" |
48 | 75 |
49 toolchain(target_name) { | 76 toolchain(target_name) { |
50 # Make these apply to all tools below. | 77 # Make these apply to all tools below. |
51 lib_switch = "" | 78 lib_switch = "" |
52 lib_dir_switch="/LIBPATH:" | 79 lib_dir_switch = "/LIBPATH:" |
53 | 80 |
54 tool("cc") { | 81 tool("cc") { |
55 rspfile = "{{output}}.rsp" | 82 rspfile = "{{output}}.rsp" |
56 pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb" | 83 pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb" |
57 command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rsp
file /c {{source}} /Fo{{output}} /Fd$pdbname" | 84 command = |
| 85 "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {
{source}} /Fo{{output}} /Fd$pdbname" |
58 depsformat = "msvc" | 86 depsformat = "msvc" |
59 description = "CC {{output}}" | 87 description = "CC {{output}}" |
60 outputs = [ | 88 outputs = |
61 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", | 89 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj"
] |
62 ] | |
63 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" | 90 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" |
64 } | 91 } |
65 | 92 |
66 tool("cxx") { | 93 tool("cxx") { |
67 rspfile = "{{output}}.rsp" | 94 rspfile = "{{output}}.rsp" |
| 95 |
68 # The PDB name needs to be different between C and C++ compiled files. | 96 # The PDB name needs to be different between C and C++ compiled files. |
69 pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb" | 97 pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb" |
70 command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rsp
file /c {{source}} /Fo{{output}} /Fd$pdbname" | 98 command = |
| 99 "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {
{source}} /Fo{{output}} /Fd$pdbname" |
71 depsformat = "msvc" | 100 depsformat = "msvc" |
72 description = "CXX {{output}}" | 101 description = "CXX {{output}}" |
73 outputs = [ | 102 outputs = |
74 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", | 103 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj"
] |
75 ] | |
76 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" | 104 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" |
77 } | 105 } |
78 | 106 |
79 tool("rc") { | 107 tool("rc") { |
80 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{
include_dirs}} /fo{{output}} {{source}}" | 108 command = |
81 outputs = [ | 109 "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{includ
e_dirs}} /fo{{output}} {{source}}" |
82 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.res", | 110 outputs = |
83 ] | 111 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.res"
] |
84 description = "RC {{output}}" | 112 description = "RC {{output}}" |
85 } | 113 } |
86 | 114 |
87 tool("asm") { | 115 tool("asm") { |
88 # TODO(brettw): "/safeseh" assembler argument is hardcoded here. Extract | 116 # TODO(brettw): "/safeseh" assembler argument is hardcoded here. Extract |
89 # assembler flags to a variable like cflags. crbug.com/418613 | 117 # assembler flags to a variable like cflags. crbug.com/418613 |
90 command = "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {
{include_dirs}} /safeseh /c /Fo {{output}} {{source}}" | 118 command = |
| 119 "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {{inclu
de_dirs}} /safeseh /c /Fo {{output}} {{source}}" |
91 description = "ASM {{output}}" | 120 description = "ASM {{output}}" |
92 outputs = [ | 121 outputs = |
93 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj", | 122 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj"
] |
94 ] | |
95 } | 123 } |
96 | 124 |
97 tool("alink") { | 125 tool("alink") { |
98 rspfile = "{{output}}.rsp" | 126 rspfile = "{{output}}.rsp" |
99 command = "$python_path gyp-win-tool link-wrapper $env False lib.exe /nolo
go /ignore:4221 /OUT:{{output}} @$rspfile" | 127 command = |
| 128 "$python_path gyp-win-tool link-wrapper $env False lib.exe /nologo /ig
nore:4221 /OUT:{{output}} @$rspfile" |
100 description = "LIB {{output}}" | 129 description = "LIB {{output}}" |
101 outputs = [ | 130 outputs = [ |
102 # Ignore {{output_extension}} and always use .lib, there's no reason to | 131 # Ignore {{output_extension}} and always use .lib, there's no reason to |
103 # allow targets to override this extension on Windows. | 132 # allow targets to override this extension on Windows. |
104 "{{target_out_dir}}/{{target_output_name}}.lib", | 133 "{{target_out_dir}}/{{target_output_name}}.lib", |
105 ] | 134 ] |
106 default_output_extension = ".lib" | 135 default_output_extension = ".lib" |
| 136 |
107 # The use of inputs_newline is to work around a fixed per-line buffer | 137 # The use of inputs_newline is to work around a fixed per-line buffer |
108 # size in the linker. | 138 # size in the linker. |
109 rspfile_content = "{{inputs_newline}}" | 139 rspfile_content = "{{inputs_newline}}" |
110 } | 140 } |
111 | 141 |
112 tool("solink") { | 142 tool("solink") { |
113 dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" #
e.g. foo.dll | 143 dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" #
e.g. foo.dll |
114 libname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib
" # e.g. foo.dll.lib | 144 libname = |
| 145 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib" # e
.g. foo.dll.lib |
115 rspfile = "${dllname}.rsp" | 146 rspfile = "${dllname}.rsp" |
116 | 147 |
117 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe
/nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile" | 148 link_command = |
| 149 "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /I
MPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile" |
118 | 150 |
119 # TODO(brettw) support manifests | 151 # TODO(brettw) support manifests |
120 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.ex
e -nologo -manifest $manifests -out:${dllname}.manifest" | 152 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.ex
e -nologo -manifest $manifests -out:${dllname}.manifest" |
121 #command = "cmd /c $link_command && $manifest_command" | 153 #command = "cmd /c $link_command && $manifest_command" |
122 command = link_command | 154 command = link_command |
123 | 155 |
124 default_output_extension = ".dll" | 156 default_output_extension = ".dll" |
125 description = "LINK(DLL) {{output}}" | 157 description = "LINK(DLL) {{output}}" |
126 outputs = [ | 158 outputs = [ |
127 dllname, | 159 dllname, |
128 libname, | 160 libname, |
129 ] | 161 ] |
130 link_output = libname | 162 link_output = libname |
131 depend_output = libname | 163 depend_output = libname |
| 164 |
132 # The use of inputs_newline is to work around a fixed per-line buffer | 165 # The use of inputs_newline is to work around a fixed per-line buffer |
133 # size in the linker. | 166 # size in the linker. |
134 rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}" | 167 rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}" |
135 } | 168 } |
136 | 169 |
137 tool("link") { | 170 tool("link") { |
138 rspfile = "{{output}}.rsp" | 171 rspfile = "{{output}}.rsp" |
139 | 172 |
140 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe
/nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile" | 173 link_command = |
| 174 "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /O
UT:{{output}} /PDB:{{output}}.pdb @$rspfile" |
141 | 175 |
142 # TODO(brettw) support manifests | 176 # TODO(brettw) support manifests |
143 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.ex
e -nologo -manifest $manifests -out:{{output}}.manifest" | 177 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.ex
e -nologo -manifest $manifests -out:{{output}}.manifest" |
144 #command = "cmd /c $link_command && $manifest_command" | 178 #command = "cmd /c $link_command && $manifest_command" |
145 command = link_command | 179 command = link_command |
146 | 180 |
147 default_output_extension = ".exe" | 181 default_output_extension = ".exe" |
148 description = "LINK {{output}}" | 182 description = "LINK {{output}}" |
149 outputs = [ | 183 outputs = |
150 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}", | 184 [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" ] |
151 ] | 185 |
152 # The use of inputs_newline is to work around a fixed per-line buffer | 186 # The use of inputs_newline is to work around a fixed per-line buffer |
153 # size in the linker. | 187 # size in the linker. |
154 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" | 188 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}" |
155 } | 189 } |
156 | 190 |
157 tool("stamp") { | 191 tool("stamp") { |
158 command = "$python_path gyp-win-tool stamp {{output}}" | 192 command = "$python_path gyp-win-tool stamp {{output}}" |
159 description = "STAMP {{output}}" | 193 description = "STAMP {{output}}" |
160 } | 194 } |
161 | 195 |
162 tool("copy") { | 196 tool("copy") { |
163 command = "$python_path gyp-win-tool recursive-mirror {{source}} {{output
}}" | 197 command = |
| 198 "$python_path gyp-win-tool recursive-mirror {{source}} {{output}}" |
164 description = "COPY {{source}} {{output}}" | 199 description = "COPY {{source}} {{output}}" |
165 } | 200 } |
166 | 201 |
167 # When invoking this toolchain not as the default one, these args will be | 202 # When invoking this toolchain not as the default one, these args will be |
168 # passed to the build. They are ignored when this is the default toolchain. | 203 # passed to the build. They are ignored when this is the default toolchain. |
169 toolchain_args() { | 204 toolchain_args() { |
170 cpu_arch = invoker.cpu_arch | 205 cpu_arch = invoker.cpu_arch |
171 } | 206 } |
172 } | 207 } |
173 } | 208 } |
174 | 209 |
175 # TODO(dpranke): Declare both toolchains all of the time when we | 210 # TODO(dpranke): Declare both toolchains all of the time when we |
176 # get it sorted out how we want to support them both in a single build. | 211 # get it sorted out how we want to support them both in a single build. |
177 # Right now only one of these can be enabled at a time because the | 212 # Right now only one of these can be enabled at a time because the |
178 # runtime libraries get copied to root_build_dir and would collide. | 213 # runtime libraries get copied to root_build_dir and would collide. |
179 if (cpu_arch == "x86") { | 214 if (cpu_arch == "x86") { |
180 msvc_toolchain("32") { | 215 msvc_toolchain("32") { |
181 environment = "environment.x86" | 216 environment = "environment.x86" |
182 cpu_arch = "x86" | 217 cpu_arch = "x86" |
183 } | 218 } |
184 } | 219 } |
185 | 220 |
186 if (cpu_arch == "x64") { | 221 if (cpu_arch == "x64") { |
187 msvc_toolchain("64") { | 222 msvc_toolchain("64") { |
188 environment = "environment.x64" | 223 environment = "environment.x64" |
189 cpu_arch = "x64" | 224 cpu_arch = "x64" |
190 } | 225 } |
191 } | 226 } |
OLD | NEW |