blob: 0a5cf87ad40213301f8e5c1f5540363de1e1d416 [file] [log] [blame]
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +00001# 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.
4
Ben Murdochc5cede92014-04-10 11:22:14 +01005import("//build/config/win/visual_studio_version.gni")
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +00006import("//build/toolchain/goma.gni")
7
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +00008# Should only be running on Windows.
9assert(is_win)
10
11# Setup the Visual Studio state.
12#
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000013# 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
15# list to us.
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000016gyp_win_tool_path = rebase_path("//tools/gyp/pylib/gyp/win_tool.py",
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000017 root_build_dir)
Torne (Richard Coles)23730a62014-03-21 14:25:57 +000018exec_script("setup_toolchain.py",
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010019 [ visual_studio_path, gyp_win_tool_path, windows_sdk_path ])
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000020
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010021# Parameters:
22# cpu_arch: cpu_arch to pass as a build arg
23# environment: File name of environment file.
24# force_win64 (optional): value for this build arg.
25template("msvc_toolchain") {
26 env = invoker.environment
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000027
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010028 toolchain(target_name) {
29 # Make these apply to all tools below.
30 lib_switch = ""
31 lib_dir_switch="/LIBPATH:"
Torne (Richard Coles)5f1c9432014-08-12 13:47:38 +010032
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010033 tool("cc") {
34 rspfile = "{{output}}.rsp"
35 pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
36 command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
37 depsformat = "msvc"
38 description = "CC {{output}}"
39 outputs = [
40 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
41 ]
42 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
43 }
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000044
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010045 tool("cxx") {
46 rspfile = "{{output}}.rsp"
47 # The PDB name needs to be different between C and C++ compiled files.
48 pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
49 command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
50 depsformat = "msvc"
51 description = "CXX {{output}}"
52 outputs = [
53 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
54 ]
55 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
56 }
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000057
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +010058 tool("rc") {
59 command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{include_dirs}} /fo{{output}} {{source}}"
60 outputs = [
61 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.res",
62 ]
63 description = "RC {{output}}"
64 }
65
66 tool("asm") {
67 command = "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {{include_dirs}} /c /Fo {{output}} {{source}}"
68 description = "ASM {{output}}"
69 outputs = [
70 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
71 ]
72 }
73
74 tool("alink") {
75 rspfile = "{{output}}.rsp"
76 command = "$python_path gyp-win-tool link-wrapper $env False lib.exe /nologo /ignore:4221 /OUT:{{output}} @$rspfile"
77 description = "LIB {{output}}"
78 outputs = [
79 # Ignore {{output_extension}} and always use .lib, there's no reason to
80 # allow targets to override this extension on Windows.
81 "{{target_out_dir}}/{{target_output_name}}.lib",
82 ]
83 default_output_extension = ".lib"
84 # The use of inputs_newline is to work around a fixed per-line buffer
85 # size in the linker.
86 rspfile_content = "{{inputs_newline}}"
87 }
88
89 tool("solink") {
90 dllname = "{{target_output_name}}{{output_extension}}" # e.g. foo.dll
91 libname = "{{target_output_name}}{{output_extension}}.lib" # e.g. foo.dll.lib
92 rspfile = "${dllname}.rsp"
93
94 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"
95
96 # TODO(brettw) support manifests
97 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:${dllname}.manifest"
98 #command = "cmd /c $link_command && $manifest_command"
99 command = link_command
100
101 default_output_extension = ".dll"
102 description = "LINK(DLL) {{output}}"
103 outputs = [
104 dllname,
105 libname,
106 ]
107 # The use of inputs_newline is to work around a fixed per-line buffer
108 # size in the linker.
109 rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
110 }
111
112 tool("link") {
113 rspfile = "{{output}}.rsp"
114
115 link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile"
116
117 # TODO(brettw) support manifests
118 #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:{{output}}.manifest"
119 #command = "cmd /c $link_command && $manifest_command"
120 command = link_command
121
122 default_output_extension = ".exe"
123 description = "LINK {{output}}"
124 outputs = [
125 "{{target_output_name}}{{output_extension}}",
126 ]
127 # The use of inputs_newline is to work around a fixed per-line buffer
128 # size in the linker.
129 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
130 }
131
132 tool("stamp") {
133 command = "$python_path gyp-win-tool stamp {{output}}"
134 description = "STAMP {{output}}"
135 }
136
137 tool("copy") {
138 command = "$python_path gyp-win-tool recursive-mirror {{source}} {{output}}"
139 description = "COPY {{source}} {{output}}"
140 }
141
142 # When invoking this toolchain not as the default one, these args will be
143 # passed to the build. They are ignored when this is the default toolchain.
144 toolchain_args() {
145 cpu_arch = invoker.cpu_arch
146
147 # Normally the build config resets the CPU architecture to 32-bits. Setting
148 # this flag overrides that behavior.
149 if (defined(invoker.force_win64)) {
150 force_win64 = invoker.force_win64
151 }
152 }
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000153 }
154}
155
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +0100156msvc_toolchain("32") {
157 environment = "environment.x86"
158 cpu_arch = "x64"
159}
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000160
Torne (Richard Coles)03b57e02014-08-28 12:05:23 +0100161msvc_toolchain("64") {
162 environment = "environment.x64"
163 cpu_arch = "x64"
164 force_win64 = true
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000165}