blob: 6229e45ee9a4b876605756c6ad65d20c493304c6 [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001declare_args() {
2 host_ar = ar
3 host_cc = cc
4 host_cxx = cxx
5
6 if (is_android) {
7 if (host_os == "win") {
8 target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe"
9 target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe"
10 target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe"
11 } else {
12 target_ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
13 target_cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
14 target_cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
15 }
16 } else {
17 target_ar = ar
18 target_cc = cc
19 target_cxx = cxx
20 }
21
22 cc_wrapper = ""
23}
24
25if (host_os == "win") {
Ethan Nicholas762466e2017-06-29 10:03:38 -040026 stamp = "cmd.exe /c echo >"
27} else {
Ethan Nicholas762466e2017-06-29 10:03:38 -040028 stamp = "touch"
29}
30
31toolchain("msvc") {
32 lib_dir_switch = "/LIBPATH:"
33
34 if (msvc == 2015) {
Kaloyan Donevf7466bd2018-03-16 14:45:35 +020035 if (target_cpu == "x86") {
36 bin = "$win_vc/bin"
37 } else {
38 bin = "$win_vc/bin/amd64"
39 }
Ethan Nicholas762466e2017-06-29 10:03:38 -040040 } else {
Brian Osman852ca312017-12-07 16:16:21 -050041 bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu"
42 }
43
44 env_setup = ""
45 if (target_cpu == "x86") {
46 # Toolchain asset includes a script that configures for x86 building.
47 # We don't support x86 builds with local MSVC installations.
48 env_setup = "cmd /c $win_sdk/bin/SetEnv.cmd /x86 && "
Ethan Nicholas762466e2017-06-29 10:03:38 -040049 }
50
Ben Wagnerdf574042018-03-13 15:11:14 -040051 cl_m32_flag = ""
Mike Kleinc722f792017-07-31 11:57:21 -040052 if (clang_win != "") {
Ben Wagnerdf574042018-03-13 15:11:14 -040053 if (target_cpu == "x86") {
54 # cl.exe knows implicitly by the choice of executable that it's targeting
55 # x86, but clang-cl.exe needs to be told when targeting non-host
56 # platforms. (All our builders are x86-64, so x86 is always non-host.)
57 cl_m32_flag = "-m32"
58 }
Mike Kleinc722f792017-07-31 11:57:21 -040059 cl = "$clang_win/bin/clang-cl.exe"
60 } else {
61 cl = "$bin/cl.exe"
62 }
63
Ethan Nicholas762466e2017-06-29 10:03:38 -040064 tool("asm") {
65 _ml = "ml"
66 if (target_cpu == "x64") {
67 _ml += "64"
68 }
Kaloyan Donevf7466bd2018-03-16 14:45:35 +020069 command = "$env_setup $bin/$_ml.exe {{asmflags}} /nologo /c /Fo {{output}} {{source}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -040070 outputs = [
71 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
72 ]
73 description = "assemble {{source}}"
74 }
75
76 tool("cc") {
77 rspfile = "{{output}}.rsp"
78 precompiled_header_type = "msvc"
79 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
80
81 # Label names may have spaces so pdbname must be quoted.
Brian Osman9dd4ae12017-10-23 12:13:14 -040082 command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -040083 depsformat = "msvc"
84 outputs = [
85 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
86 ]
Ben Wagnerdf574042018-03-13 15:11:14 -040087 rspfile_content =
88 "{{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_c}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -040089 description = "compile {{source}}"
90 }
91
92 tool("cxx") {
93 rspfile = "{{output}}.rsp"
94 precompiled_header_type = "msvc"
95 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
96
97 # Label names may have spaces so pdbname must be quoted.
Brian Osman9dd4ae12017-10-23 12:13:14 -040098 command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -040099 depsformat = "msvc"
100 outputs = [
101 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
102 ]
Ben Wagnerdf574042018-03-13 15:11:14 -0400103 rspfile_content =
104 "{{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_cc}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400105 description = "compile {{source}}"
106 }
107
108 tool("alink") {
109 rspfile = "{{output}}.rsp"
110
Brian Osman9dd4ae12017-10-23 12:13:14 -0400111 command = "$env_setup $bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400112 outputs = [
113 # Ignore {{output_extension}} and always use .lib, there's no reason to
114 # allow targets to override this extension on Windows.
115 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
116 ]
117 default_output_extension = ".lib"
118 default_output_dir = "{{target_out_dir}}"
119
120 # inputs_newline works around a fixed per-line buffer size in the linker.
121 rspfile_content = "{{inputs_newline}}"
122 description = "link {{output}}"
123 }
124
125 tool("solink") {
126 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
127 libname = "${dllname}.lib"
128 pdbname = "${dllname}.pdb"
129 rspfile = "${dllname}.rsp"
130
Brian Osman9dd4ae12017-10-23 12:13:14 -0400131 command = "$env_setup $bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400132 outputs = [
133 dllname,
134 libname,
135 pdbname,
136 ]
137 default_output_extension = ".dll"
138 default_output_dir = "{{root_out_dir}}"
139
140 link_output = libname
141 depend_output = libname
142 runtime_outputs = [
143 dllname,
144 pdbname,
145 ]
146
147 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
148 restat = true
149
150 # inputs_newline works around a fixed per-line buffer size in the linker.
151 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
152 description = "link {{output}}"
153 }
154
155 tool("link") {
156 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
157 pdbname = "$exename.pdb"
158 rspfile = "$exename.rsp"
159
160 command =
Brian Osman9dd4ae12017-10-23 12:13:14 -0400161 "$env_setup $bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400162
163 default_output_extension = ".exe"
164 default_output_dir = "{{root_out_dir}}"
165 outputs = [
166 exename,
167 ]
168
169 # inputs_newline works around a fixed per-line buffer size in the linker.
170 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
171 description = "link {{output}}"
172 }
173
174 tool("stamp") {
175 command = "$stamp {{output}}"
176 description = "stamp {{output}}"
177 }
178
179 tool("copy") {
180 cp_py = rebase_path("../cp.py")
Ben Wagner96aa5352018-06-19 10:34:32 -0400181 command = "python $cp_py {{source}} {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400182 description = "copy {{source}} {{output}}"
183 }
184}
185
186template("gcc_like_toolchain") {
187 toolchain(target_name) {
188 ar = invoker.ar
189 cc = invoker.cc
190 cxx = invoker.cxx
191 lib_switch = "-l"
192 lib_dir_switch = "-L"
193
194 tool("cc") {
195 depfile = "{{output}}.d"
196 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
197 depsformat = "gcc"
198 outputs = [
199 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
200 ]
201 description = "compile {{source}}"
202 }
203
204 tool("cxx") {
205 depfile = "{{output}}.d"
206 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
207 depsformat = "gcc"
208 outputs = [
209 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
210 ]
211 description = "compile {{source}}"
212 }
213
214 tool("objc") {
215 depfile = "{{output}}.d"
216 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
217 depsformat = "gcc"
218 outputs = [
219 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
220 ]
221 description = "compile {{source}}"
222 }
223
224 tool("objcxx") {
225 depfile = "{{output}}.d"
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400226 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400227 depsformat = "gcc"
228 outputs = [
229 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
230 ]
231 description = "compile {{source}}"
232 }
233
234 tool("asm") {
235 depfile = "{{output}}.d"
236 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
237 depsformat = "gcc"
238 outputs = [
239 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
240 ]
241 description = "assemble {{source}}"
242 }
243
244 tool("alink") {
245 rspfile = "{{output}}.rsp"
246 rspfile_content = "{{inputs}}"
247 ar_py = rebase_path("../ar.py")
Ben Wagner96aa5352018-06-19 10:34:32 -0400248 command = "python $ar_py $ar {{output}} $rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400249 outputs = [
250 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
251 ]
252 default_output_extension = ".a"
253 output_prefix = "lib"
254 description = "link {{output}}"
255 }
256
257 tool("solink") {
258 soname = "{{target_output_name}}{{output_extension}}"
259
260 rpath = "-Wl,-soname,$soname"
261 if (is_mac) {
262 rpath = "-Wl,-install_name,@rpath/$soname"
263 }
264
Hal Canarye1053ea2018-02-09 14:45:09 -0500265 rspfile = "{{output}}.rsp"
266 rspfile_content = "{{inputs}}"
267 command = "$cc_wrapper $cxx -shared {{ldflags}} @$rspfile {{solibs}} {{libs}} $rpath -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400268 outputs = [
269 "{{root_out_dir}}/$soname",
270 ]
271 output_prefix = "lib"
272 default_output_extension = ".so"
273 description = "link {{output}}"
274 }
275
276 tool("link") {
Hal Canarye1053ea2018-02-09 14:45:09 -0500277 rspfile = "{{output}}.rsp"
278 rspfile_content = "{{inputs}}"
279 command = "$cc_wrapper $cxx {{ldflags}} @$rspfile {{solibs}} {{libs}} -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400280 outputs = [
281 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
282 ]
283 description = "link {{output}}"
284 }
285
286 tool("stamp") {
287 command = "$stamp {{output}}"
288 description = "stamp {{output}}"
289 }
290
291 tool("copy") {
292 cp_py = rebase_path("../cp.py")
Ben Wagner96aa5352018-06-19 10:34:32 -0400293 command = "python $cp_py {{source}} {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400294 description = "copy {{source}} {{output}}"
295 }
296
Jim Van Verth443a9132017-11-28 09:45:26 -0500297 tool("copy_bundle_data") {
298 cp_py = rebase_path("../cp.py")
Ben Wagner96aa5352018-06-19 10:34:32 -0400299 command = "python $cp_py {{source}} {{output}}"
Jim Van Verth443a9132017-11-28 09:45:26 -0500300 description = "copy_bundle_data {{source}} {{output}}"
301 }
302
303 # We don't currently have any xcasset files so make this a NOP
304 tool("compile_xcassets") {
305 command = "true"
306 description = "compile_xcassets {{output}}"
307 }
308
Ethan Nicholas762466e2017-06-29 10:03:38 -0400309 toolchain_args = {
310 current_cpu = invoker.cpu
311 current_os = invoker.os
312 }
313 }
314}
315
316gcc_like_toolchain("gcc_like") {
317 cpu = current_cpu
318 os = current_os
319 ar = target_ar
320 cc = target_cc
321 cxx = target_cxx
322}
323
324gcc_like_toolchain("gcc_like_host") {
325 cpu = host_cpu
326 os = host_os
327 ar = host_ar
328 cc = host_cc
329 cxx = host_cxx
330}