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
42 # This value will be inherited in the toolchain below.
43 concurrent_links = exec_script("../get_concurrent_links.py", [], "value")
46 # current_cpu: current_cpu to pass as a build arg
47 # environment: File name of environment file.
48 template("msvc_toolchain") {
49 if (defined(invoker.concurrent_links)) {
50 concurrent_links = invoker.concurrent_links
53 env = invoker.environment
56 configuration = "Debug"
58 configuration = "Release"
60 exec_script("../../vs_toolchain.py",
63 rebase_path(root_build_dir),
69 goma_prefix = "$goma_dir/gomacc.exe "
74 cl = "${goma_prefix}\"${vc_bin_dir}/cl.exe\""
76 toolchain(target_name) {
77 # Make these apply to all tools below.
79 lib_dir_switch = "/LIBPATH:"
82 rspfile = "{{output}}.rsp"
83 pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
84 command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
86 description = "CC {{output}}"
88 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
90 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
94 rspfile = "{{output}}.rsp"
96 # The PDB name needs to be different between C and C++ compiled files.
97 pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
98 command = "ninja -t msvc -e $env -- $cl /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
100 description = "CXX {{output}}"
102 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
104 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
108 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{include_dirs}} /fo{{output}} {{source}}"
110 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.res",
112 description = "RC {{output}}"
116 # TODO(brettw): "/safeseh" assembler argument is hardcoded here. Extract
117 # assembler flags to a variable like cflags. crbug.com/418613
118 command = "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {{include_dirs}} /safeseh /c /Fo {{output}} {{source}}"
119 description = "ASM {{output}}"
121 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
126 rspfile = "{{output}}.rsp"
127 command = "$python_path gyp-win-tool link-wrapper $env False lib.exe /nologo /ignore:4221 /OUT:{{output}} @$rspfile"
128 description = "LIB {{output}}"
130 # Ignore {{output_extension}} and always use .lib, there's no reason to
131 # allow targets to override this extension on Windows.
132 "{{target_out_dir}}/{{target_output_name}}.lib",
134 default_output_extension = ".lib"
136 # The use of inputs_newline is to work around a fixed per-line buffer
137 # size in the linker.
138 rspfile_content = "{{inputs_newline}}"
142 dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e.g. foo.dll
144 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib" # e.g. foo.dll.lib
145 rspfile = "${dllname}.rsp"
147 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"
149 # TODO(brettw) support manifests
150 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:${dllname}.manifest"
151 #command = "cmd /c $link_command && $manifest_command"
152 command = link_command
154 default_output_extension = ".dll"
155 description = "LINK(DLL) {{output}}"
160 link_output = libname
161 depend_output = libname
163 # The use of inputs_newline is to work around a fixed per-line buffer
164 # size in the linker.
165 rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
169 rspfile = "{{output}}.rsp"
171 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile"
173 # TODO(brettw) support manifests
174 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:{{output}}.manifest"
175 #command = "cmd /c $link_command && $manifest_command"
176 command = link_command
178 default_output_extension = ".exe"
179 description = "LINK {{output}}"
181 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
184 # The use of inputs_newline is to work around a fixed per-line buffer
185 # size in the linker.
186 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
190 command = "$python_path gyp-win-tool stamp {{output}}"
191 description = "STAMP {{output}}"
196 "$python_path gyp-win-tool recursive-mirror {{source}} {{output}}"
197 description = "COPY {{source}} {{output}}"
200 # When invoking this toolchain not as the default one, these args will be
201 # passed to the build. They are ignored when this is the default toolchain.
203 current_cpu = invoker.current_cpu
208 # TODO(dpranke): Declare both toolchains all of the time when we
209 # get it sorted out how we want to support them both in a single build.
210 # Right now only one of these can be enabled at a time because the
211 # runtime libraries get copied to root_build_dir and would collide.
212 if (current_cpu == "x86") {
213 msvc_toolchain("32") {
214 environment = "environment.x86"
220 if (current_cpu == "x64") {
221 msvc_toolchain("64") {
222 environment = "environment.x64"