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
3 # found in the LICENSE file.
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.
14 import("//build/config/win/visual_studio_version.gni")
15 import("//build/toolchain/goma.gni")
17 # Should only be running on Windows.
20 # Setup the Visual Studio state.
22 # Its arguments are the VS path and the compiler wrapper tool. It will write
23 # "environment.x86" and "environment.x64" to the build directory and return a
26 rebase_path("//tools/gyp/pylib/gyp/win_tool.py", root_build_dir)
28 toolchain_data = exec_script("setup_toolchain.py",
33 visual_studio_runtime_dirs,
38 if (vc_bin_dir == "") {
39 vc_bin_dir = toolchain_data.vc_bin_dir
43 goma_prefix = "$goma_dir/gomacc.exe "
48 # This value will be inherited in the toolchain below.
49 concurrent_links = exec_script("../get_concurrent_links.py", [], "value")
51 # Copy the VS runtime DLL for the default toolchain the root build directory so
53 if (current_toolchain == default_toolchain) {
55 configuration_name = "Debug"
57 configuration_name = "Release"
59 exec_script("../../vs_toolchain.py",
62 rebase_path(root_build_dir),
69 # current_cpu: current_cpu to pass as a build arg
70 # current_os: current_os to pass as a build arg
71 # environment: File name of environment file.
72 template("msvc_toolchain") {
73 if (defined(invoker.concurrent_links)) {
74 concurrent_links = invoker.concurrent_links
77 env = invoker.environment
81 toolchain(target_name) {
82 # Make these apply to all tools below.
84 lib_dir_switch = "/LIBPATH:"
87 rspfile = "{{output}}.rsp"
88 precompiled_header_type = "msvc"
89 pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
90 command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
92 description = "CC {{output}}"
94 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.obj",
96 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
100 rspfile = "{{output}}.rsp"
101 precompiled_header_type = "msvc"
103 # The PDB name needs to be different between C and C++ compiled files.
104 pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
105 command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
107 description = "CXX {{output}}"
109 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.obj",
111 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
115 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{include_dirs}} /fo{{output}} {{source}}"
117 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.res",
119 description = "RC {{output}}"
123 # TODO(brettw): "/safeseh" assembler argument is hardcoded here. Extract
124 # assembler flags to a variable like cflags. crbug.com/418613
125 command = "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {{include_dirs}} /safeseh /c /Fo {{output}} {{source}}"
126 description = "ASM {{output}}"
128 "{{target_out_dir}}/{{target_output_name}}/{{source_name_part}}.obj",
133 rspfile = "{{output}}.rsp"
134 command = "$python_path gyp-win-tool link-wrapper $env False lib.exe /nologo /ignore:4221 /OUT:{{output}} @$rspfile"
135 description = "LIB {{output}}"
137 # Ignore {{output_extension}} and always use .lib, there's no reason to
138 # allow targets to override this extension on Windows.
139 "{{target_out_dir}}/{{target_output_name}}.lib",
141 default_output_extension = ".lib"
143 # The use of inputs_newline is to work around a fixed per-line buffer
144 # size in the linker.
145 rspfile_content = "{{inputs_newline}}"
149 dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e.g. foo.dll
150 libname = "${dllname}.lib" # e.g. foo.dll.lib
151 rspfile = "${dllname}.rsp"
153 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"
155 # TODO(brettw) support manifests
156 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:${dllname}.manifest"
157 #command = "cmd /c $link_command && $manifest_command"
158 command = link_command
160 default_output_extension = ".dll"
161 description = "LINK(DLL) {{output}}"
166 link_output = libname
167 depend_output = libname
169 # Since the above commands only updates the .lib file when it changes, ask
170 # Ninja to check if the timestamp actually changed to know if downstream
171 # dependencies should be recompiled.
174 # The use of inputs_newline is to work around a fixed per-line buffer
175 # size in the linker.
176 rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
180 rspfile = "{{output}}.rsp"
182 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile"
184 # TODO(brettw) support manifests
185 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:{{output}}.manifest"
186 #command = "cmd /c $link_command && $manifest_command"
187 command = link_command
189 default_output_extension = ".exe"
190 description = "LINK {{output}}"
192 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
195 # The use of inputs_newline is to work around a fixed per-line buffer
196 # size in the linker.
197 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
201 command = "$python_path gyp-win-tool stamp {{output}}"
202 description = "STAMP {{output}}"
207 "$python_path gyp-win-tool recursive-mirror {{source}} {{output}}"
208 description = "COPY {{source}} {{output}}"
211 # When invoking this toolchain not as the default one, these args will be
212 # passed to the build. They are ignored when this is the default toolchain.
214 current_cpu = invoker.current_cpu
215 if (defined(invoker.is_clang)) {
216 is_clang = invoker.is_clang
218 current_os = invoker.current_os
223 # TODO(dpranke): Declare both toolchains all of the time when we
224 # get it sorted out how we want to support them both in a single build.
225 # Right now only one of these can be enabled at a time because the
226 # runtime libraries get copied to root_build_dir and would collide.
227 if (current_cpu == "x86") {
228 msvc_toolchain("x86") {
229 environment = "environment.x86"
231 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
234 msvc_toolchain("clang_x86") {
235 environment = "environment.x86"
237 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
239 cl = "${goma_prefix}$prefix/clang-cl.exe"
245 if (current_cpu == "x64") {
246 msvc_toolchain("x64") {
247 environment = "environment.x64"
249 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
252 msvc_toolchain("clang_x64") {
253 environment = "environment.x64"
255 prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
257 cl = "${goma_prefix}$prefix/clang-cl.exe"
264 msvc_toolchain("winrt_x86") {
265 environment = "environment.winrt_x86"
266 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
270 current_os = current_os
273 msvc_toolchain("winrt_x64") {
274 environment = "environment.winrt_x64"
275 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
279 current_os = current_os