blob: 1c0c2dc56a398d6aae9d982e6cfa43349b831ed4 [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") {
26 python = "python.bat"
27 stamp = "cmd.exe /c echo >"
28} else {
29 python = "python"
30 stamp = "touch"
31}
32
33toolchain("msvc") {
34 lib_dir_switch = "/LIBPATH:"
35
36 if (msvc == 2015) {
Kaloyan Donevf7466bd2018-03-16 14:45:35 +020037 if (target_cpu == "x86") {
38 bin = "$win_vc/bin"
39 } else {
40 bin = "$win_vc/bin/amd64"
41 }
Ethan Nicholas762466e2017-06-29 10:03:38 -040042 } else {
Brian Osman852ca312017-12-07 16:16:21 -050043 bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu"
44 }
45
46 env_setup = ""
47 if (target_cpu == "x86") {
48 # Toolchain asset includes a script that configures for x86 building.
49 # We don't support x86 builds with local MSVC installations.
50 env_setup = "cmd /c $win_sdk/bin/SetEnv.cmd /x86 && "
Ethan Nicholas762466e2017-06-29 10:03:38 -040051 }
52
Ben Wagnerdf574042018-03-13 15:11:14 -040053 cl_m32_flag = ""
Mike Kleinc722f792017-07-31 11:57:21 -040054 if (clang_win != "") {
Ben Wagnerdf574042018-03-13 15:11:14 -040055 if (target_cpu == "x86") {
56 # cl.exe knows implicitly by the choice of executable that it's targeting
57 # x86, but clang-cl.exe needs to be told when targeting non-host
58 # platforms. (All our builders are x86-64, so x86 is always non-host.)
59 cl_m32_flag = "-m32"
60 }
Mike Kleinc722f792017-07-31 11:57:21 -040061 cl = "$clang_win/bin/clang-cl.exe"
62 } else {
63 cl = "$bin/cl.exe"
64 }
65
Ethan Nicholas762466e2017-06-29 10:03:38 -040066 tool("asm") {
67 _ml = "ml"
68 if (target_cpu == "x64") {
69 _ml += "64"
70 }
Kaloyan Donevf7466bd2018-03-16 14:45:35 +020071 command = "$env_setup $bin/$_ml.exe {{asmflags}} /nologo /c /Fo {{output}} {{source}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -040072 outputs = [
73 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
74 ]
75 description = "assemble {{source}}"
76 }
77
78 tool("cc") {
79 rspfile = "{{output}}.rsp"
80 precompiled_header_type = "msvc"
81 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
82
83 # Label names may have spaces so pdbname must be quoted.
Brian Osman9dd4ae12017-10-23 12:13:14 -040084 command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -040085 depsformat = "msvc"
86 outputs = [
87 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
88 ]
Ben Wagnerdf574042018-03-13 15:11:14 -040089 rspfile_content =
90 "{{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_c}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -040091 description = "compile {{source}}"
92 }
93
94 tool("cxx") {
95 rspfile = "{{output}}.rsp"
96 precompiled_header_type = "msvc"
97 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
98
99 # Label names may have spaces so pdbname must be quoted.
Brian Osman9dd4ae12017-10-23 12:13:14 -0400100 command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
Ethan Nicholas762466e2017-06-29 10:03:38 -0400101 depsformat = "msvc"
102 outputs = [
103 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
104 ]
Ben Wagnerdf574042018-03-13 15:11:14 -0400105 rspfile_content =
106 "{{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_cc}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400107 description = "compile {{source}}"
108 }
109
110 tool("alink") {
111 rspfile = "{{output}}.rsp"
112
Brian Osman9dd4ae12017-10-23 12:13:14 -0400113 command = "$env_setup $bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400114 outputs = [
115 # Ignore {{output_extension}} and always use .lib, there's no reason to
116 # allow targets to override this extension on Windows.
117 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
118 ]
119 default_output_extension = ".lib"
120 default_output_dir = "{{target_out_dir}}"
121
122 # inputs_newline works around a fixed per-line buffer size in the linker.
123 rspfile_content = "{{inputs_newline}}"
124 description = "link {{output}}"
125 }
126
127 tool("solink") {
128 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
129 libname = "${dllname}.lib"
130 pdbname = "${dllname}.pdb"
131 rspfile = "${dllname}.rsp"
132
Brian Osman9dd4ae12017-10-23 12:13:14 -0400133 command = "$env_setup $bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400134 outputs = [
135 dllname,
136 libname,
137 pdbname,
138 ]
139 default_output_extension = ".dll"
140 default_output_dir = "{{root_out_dir}}"
141
142 link_output = libname
143 depend_output = libname
144 runtime_outputs = [
145 dllname,
146 pdbname,
147 ]
148
149 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
150 restat = true
151
152 # inputs_newline works around a fixed per-line buffer size in the linker.
153 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
154 description = "link {{output}}"
155 }
156
157 tool("link") {
158 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
159 pdbname = "$exename.pdb"
160 rspfile = "$exename.rsp"
161
162 command =
Brian Osman9dd4ae12017-10-23 12:13:14 -0400163 "$env_setup $bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400164
165 default_output_extension = ".exe"
166 default_output_dir = "{{root_out_dir}}"
167 outputs = [
168 exename,
169 ]
170
171 # inputs_newline works around a fixed per-line buffer size in the linker.
172 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
173 description = "link {{output}}"
174 }
175
176 tool("stamp") {
177 command = "$stamp {{output}}"
178 description = "stamp {{output}}"
179 }
180
181 tool("copy") {
182 cp_py = rebase_path("../cp.py")
183 command = "$python $cp_py {{source}} {{output}}"
184 description = "copy {{source}} {{output}}"
185 }
186}
187
188template("gcc_like_toolchain") {
189 toolchain(target_name) {
190 ar = invoker.ar
191 cc = invoker.cc
192 cxx = invoker.cxx
193 lib_switch = "-l"
194 lib_dir_switch = "-L"
195
196 tool("cc") {
197 depfile = "{{output}}.d"
198 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
199 depsformat = "gcc"
200 outputs = [
201 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
202 ]
203 description = "compile {{source}}"
204 }
205
206 tool("cxx") {
207 depfile = "{{output}}.d"
208 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
209 depsformat = "gcc"
210 outputs = [
211 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
212 ]
213 description = "compile {{source}}"
214 }
215
216 tool("objc") {
217 depfile = "{{output}}.d"
218 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
219 depsformat = "gcc"
220 outputs = [
221 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
222 ]
223 description = "compile {{source}}"
224 }
225
226 tool("objcxx") {
227 depfile = "{{output}}.d"
Greg Daniel6b7e0e22017-07-12 16:21:09 -0400228 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 -0400229 depsformat = "gcc"
230 outputs = [
231 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
232 ]
233 description = "compile {{source}}"
234 }
235
236 tool("asm") {
237 depfile = "{{output}}.d"
238 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
239 depsformat = "gcc"
240 outputs = [
241 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
242 ]
243 description = "assemble {{source}}"
244 }
245
246 tool("alink") {
247 rspfile = "{{output}}.rsp"
248 rspfile_content = "{{inputs}}"
249 ar_py = rebase_path("../ar.py")
250 command = "$python $ar_py $ar {{output}} $rspfile"
251 outputs = [
252 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
253 ]
254 default_output_extension = ".a"
255 output_prefix = "lib"
256 description = "link {{output}}"
257 }
258
259 tool("solink") {
260 soname = "{{target_output_name}}{{output_extension}}"
261
262 rpath = "-Wl,-soname,$soname"
263 if (is_mac) {
264 rpath = "-Wl,-install_name,@rpath/$soname"
265 }
266
Hal Canarye1053ea2018-02-09 14:45:09 -0500267 rspfile = "{{output}}.rsp"
268 rspfile_content = "{{inputs}}"
269 command = "$cc_wrapper $cxx -shared {{ldflags}} @$rspfile {{solibs}} {{libs}} $rpath -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400270 outputs = [
271 "{{root_out_dir}}/$soname",
272 ]
273 output_prefix = "lib"
274 default_output_extension = ".so"
275 description = "link {{output}}"
276 }
277
278 tool("link") {
Hal Canarye1053ea2018-02-09 14:45:09 -0500279 rspfile = "{{output}}.rsp"
280 rspfile_content = "{{inputs}}"
281 command = "$cc_wrapper $cxx {{ldflags}} @$rspfile {{solibs}} {{libs}} -o {{output}}"
Ethan Nicholas762466e2017-06-29 10:03:38 -0400282 outputs = [
283 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
284 ]
285 description = "link {{output}}"
286 }
287
288 tool("stamp") {
289 command = "$stamp {{output}}"
290 description = "stamp {{output}}"
291 }
292
293 tool("copy") {
294 cp_py = rebase_path("../cp.py")
295 command = "$python $cp_py {{source}} {{output}}"
296 description = "copy {{source}} {{output}}"
297 }
298
Jim Van Verth443a9132017-11-28 09:45:26 -0500299 tool("copy_bundle_data") {
300 cp_py = rebase_path("../cp.py")
301 command = "$python $cp_py {{source}} {{output}}"
302 description = "copy_bundle_data {{source}} {{output}}"
303 }
304
305 # We don't currently have any xcasset files so make this a NOP
306 tool("compile_xcassets") {
307 command = "true"
308 description = "compile_xcassets {{output}}"
309 }
310
Ethan Nicholas762466e2017-06-29 10:03:38 -0400311 toolchain_args = {
312 current_cpu = invoker.cpu
313 current_os = invoker.os
314 }
315 }
316}
317
318gcc_like_toolchain("gcc_like") {
319 cpu = current_cpu
320 os = current_os
321 ar = target_ar
322 cc = target_cc
323 cxx = target_cxx
324}
325
326gcc_like_toolchain("gcc_like_host") {
327 cpu = host_cpu
328 os = host_os
329 ar = host_ar
330 cc = host_cc
331 cxx = host_cxx
332}