Debian Codegraph @

gn/toolchain/BUILD.gn

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 if (is_wasm) {
2 import("wasm.gni")
3 }
4
5 declare_args() {
6 host_ar = ar
7 host_cc = cc
8 host_cxx = cxx
9
10 if (is_android) {
11 _prefix = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin"
12 if (host_os == "win") {
13 target_ar = "$_prefix/llvm-ar.exe"
14 target_cc = "$_prefix/clang.exe --target=$ndk_target$ndk_api -fno-addrsig"
15 target_cxx =
16 "$_prefix/clang++.exe --target=$ndk_target$ndk_api -fno-addrsig"
17 } else {
18 target_ar = "$_prefix/llvm-ar"
19 target_cc = "$_prefix/$ndk_target$ndk_api-clang"
20 target_cxx = "$_prefix/$ndk_target$ndk_api-clang++"
21 }
22 } else {
23 target_ar = ar
24 target_cc = cc
25 target_cxx = cxx
26 }
27
28 cc_wrapper = ""
29
30 # dsymutil seems to kill the machine when too many processes are run in
31 # parallel, so we need to use a pool to limit the concurrency when passing
32 # large -j to Ninja (e.g. Goma build). Unfortunately this is also one of the
33 # slowest steps in a build, so we don't want to limit too much. Use the number
34 # of CPUs as a default.
35 dlsymutil_pool_depth = exec_script("num_cpus.py", [], "value")
36
37 # Too many linkers running at once causes issues for some builders. Allow
38 # such builders to limit the number of concurrent link steps.
39 # link_pool_depth < 0 means no pool, 0 means cpu count, > 0 sets pool size.
40 link_pool_depth = -1
41 }
42
43 declare_args() {
44 host_link = host_cxx
45 target_link = target_cxx
46 }
47
48 # For 'shell' see https://ninja-build.org/manual.html#ref_rule_command
49 if (host_os == "win") {
50 shell = "cmd.exe /c "
51 stamp = "$shell echo >"
52 } else {
53 shell = ""
54 stamp = "touch"
55 }
56
57 if (current_toolchain == default_toolchain) {
58 pool("dsymutil_pool") {
59 depth = dlsymutil_pool_depth
60 }
61 if (0 <= link_pool_depth) {
62 pool("link_pool") {
63 if (link_pool_depth == 0) {
64 depth = exec_script("num_cpus.py", [], "value")
65 } else {
66 depth = link_pool_depth
67 }
68 }
69 }
70 }
71
72 template("msvc_toolchain") {
73 toolchain(target_name) {
74 toolchain_target_cpu = invoker.cpu
75 lib_switch = ""
76 lib_dir_switch = "/LIBPATH:"
77
78 bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$toolchain_target_cpu"
79
80 cl_m32_flag = ""
81
82 if (clang_win != "") {
83 if (toolchain_target_cpu == "x86") {
84 # cl.exe knows implicitly by the choice of executable that it's targeting
85 # x86, but clang-cl.exe needs to be told when targeting non-host
86 # platforms. (All our builders are x86-64, so x86 is always non-host.)
87 cl_m32_flag = "-m32"
88 }
89 if (host_os == "win") {
90 cl = "\"$clang_win/bin/clang-cl.exe\""
91 lib = "\"$clang_win/bin/lld-link.exe\" /lib"
92 link = "\"$clang_win/bin/lld-link.exe\""
93 } else {
94 cl = "\"$clang_win/bin/clang-cl\""
95 lib = "\"$clang_win/bin/lld-link\" /lib"
96 link = "\"$clang_win/bin/lld-link\""
97 }
98 } else {
99 cl = "\"$bin/cl.exe\""
100 lib = "\"$bin/lib.exe\""
101 link = "\"$bin/link.exe\""
102 }
103
104 tool("asm") {
105 _ml = "ml"
106 if (toolchain_target_cpu == "x64") {
107 _ml += "64"
108 }
109 command =
110 "\"$bin/$_ml.exe\" {{asmflags}} /nologo /c /Fo {{output}} {{source}}"
111 outputs = [
112 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
113 ]
114 description = "assemble {{source}}"
115 }
116
117 tool("cc") {
118 precompiled_header_type = "msvc"
119 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
120
121 # Label names may have spaces so pdbname must be quoted.
122 command = "$cc_wrapper $cl /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_c}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
123 depsformat = "msvc"
124 outputs = [
125 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
126 ]
127 description = "compile {{source}}"
128 }
129
130 tool("cxx") {
131 precompiled_header_type = "msvc"
132 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
133
134 # Label names may have spaces so pdbname must be quoted.
135 command = "$cc_wrapper $cl /nologo /showIncludes /FC {{defines}} {{include_dirs}} {{cflags}} $cl_m32_flag {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
136 depsformat = "msvc"
137 outputs = [
138 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
139 ]
140 description = "compile {{source}}"
141 }
142
143 tool("alink") {
144 rspfile = "{{output}}.rsp"
145
146 command =
147 "$lib /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
148 outputs = [
149 # Ignore {{output_extension}} and always use .lib, there's no reason to
150 # allow targets to override this extension on Windows.
151 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
152 ]
153 default_output_extension = ".lib"
154 default_output_dir = "{{target_out_dir}}"
155
156 # inputs_newline works around a fixed per-line buffer size in the linker.
157 rspfile_content = "{{inputs_newline}}"
158 description = "link {{output}}"
159 if (0 <= link_pool_depth) {
160 pool = ":link_pool($default_toolchain)"
161 }
162 }
163
164 tool("solink") {
165 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
166 libname = "${dllname}.lib"
167 pdbname = "${dllname}.pdb"
168 rspfile = "${dllname}.rsp"
169
170 command = "$link /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
171 outputs = [
172 dllname,
173 libname,
174 pdbname,
175 ]
176 default_output_extension = ".dll"
177 default_output_dir = "{{root_out_dir}}"
178
179 link_output = libname
180 depend_output = libname
181 runtime_outputs = [
182 dllname,
183 pdbname,
184 ]
185
186 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
187 restat = true
188
189 # inputs_newline works around a fixed per-line buffer size in the linker.
190 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
191 description = "link {{output}}"
192 if (0 <= link_pool_depth) {
193 pool = ":link_pool($default_toolchain)"
194 }
195 }
196
197 tool("link") {
198 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
199 pdbname = "$exename.pdb"
200 rspfile = "$exename.rsp"
201
202 command = "$link /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
203 default_output_extension = ".exe"
204 default_output_dir = "{{root_out_dir}}"
205 outputs = [ exename ]
206
207 # inputs_newline works around a fixed per-line buffer size in the linker.
208 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
209 description = "link {{output}}"
210 if (0 <= link_pool_depth) {
211 pool = ":link_pool($default_toolchain)"
212 }
213 }
214
215 tool("stamp") {
216 command = "$stamp {{output}}"
217 description = "stamp {{output}}"
218 }
219
220 tool("copy") {
221 cp_py = rebase_path("../cp.py")
222 command = "$shell python3 \"$cp_py\" {{source}} {{output}}"
223 description = "copy {{source}} {{output}}"
224 }
225
226 toolchain_args = {
227 current_cpu = invoker.cpu
228 current_os = invoker.os
229 }
230 }
231 }
232
233 msvc_toolchain("msvc") {
234 cpu = current_cpu
235 os = current_os
236 }
237
238 msvc_toolchain("msvc_host") {
239 cpu = host_cpu
240 os = host_os
241 }
242
243 template("gcc_like_toolchain") {
244 toolchain(target_name) {
245 ar = invoker.ar
246 cc = invoker.cc
247 cxx = invoker.cxx
248 link = invoker.link
249 lib_switch = "-l"
250 lib_dir_switch = "-L"
251
252 tool("cc") {
253 depfile = "{{output}}.d"
254 command = "$cc_wrapper $cc -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
255 depsformat = "gcc"
256 outputs =
257 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
258 description = "compile {{source}}"
259 }
260
261 tool("cxx") {
262 depfile = "{{output}}.d"
263 command = "$cc_wrapper $cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
264 depsformat = "gcc"
265 outputs =
266 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
267 description = "compile {{source}}"
268 }
269
270 tool("objc") {
271 depfile = "{{output}}.d"
272 command = "$cc_wrapper $cc -MD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
273 depsformat = "gcc"
274 outputs =
275 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
276 description = "compile {{source}}"
277 }
278
279 tool("objcxx") {
280 depfile = "{{output}}.d"
281 command = "$cc_wrapper $cxx -MD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objcc}} -c {{source}} -o {{output}}"
282 depsformat = "gcc"
283 outputs =
284 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
285 description = "compile {{source}}"
286 }
287
288 tool("asm") {
289 depfile = "{{output}}.d"
290 command = "$cc_wrapper $cc -MD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
291 depsformat = "gcc"
292 outputs =
293 [ "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o" ]
294 description = "assemble {{source}}"
295 }
296
297 if (is_mac || is_ios) {
298 not_needed([ "ar" ]) # We use libtool instead.
299 }
300
301 tool("alink") {
302 if (is_mac || is_ios) {
303 command = "libtool -static -o {{output}} -no_warning_for_no_symbols {{inputs}}"
304 } else {
305 rspfile = "{{output}}.rsp"
306 rspfile_content = "{{inputs}}"
307 rm_py = rebase_path("../rm.py")
308 command = "$shell python3 \"$rm_py\" \"{{output}}\" && $ar rcs {{output}} @$rspfile"
309 }
310
311 outputs =
312 [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}" ]
313 default_output_extension = ".a"
314 output_prefix = "lib"
315 description = "link {{output}}"
316 if (0 <= link_pool_depth) {
317 pool = ":link_pool($default_toolchain)"
318 }
319 }
320
321 tool("solink") {
322 soname = "{{target_output_name}}{{output_extension}}"
323
324 rpath = "-Wl,-soname,$soname"
325 if (is_mac || is_ios) {
326 rpath = "-Wl,-install_name,@rpath/$soname"
327 }
328
329 rspfile = "{{output}}.rsp"
330 rspfile_content = "{{inputs}}"
331
332 # --start-group/--end-group let us link multiple .a {{inputs}}
333 # without worrying about their relative order on the link line.
334 #
335 # This is mostly important for traditional linkers like GNU ld and Gold.
336 # The Mac/iOS linker neither needs nor accepts these flags.
337 # LLD doesn't need these flags, but accepts and ignores them.
338 _start_group = "-Wl,--start-group"
339 _end_group = "-Wl,--end-group"
340 if (is_mac || is_ios) {
341 _start_group = ""
342 _end_group = ""
343 }
344
345 command = "$link -shared {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} $rpath -o {{output}}"
346 outputs = [ "{{root_out_dir}}/$soname" ]
347 output_prefix = "lib"
348 if (is_mac || is_ios) {
349 default_output_extension = ".dylib"
350 } else {
351 default_output_extension = ".so"
352 }
353 description = "link {{output}}"
354 if (0 <= link_pool_depth) {
355 pool = ":link_pool($default_toolchain)"
356 }
357 }
358
359 tool("link") {
360 exe_name = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
361 rspfile = "$exe_name.rsp"
362 rspfile_content = "{{inputs}}"
363
364 # --start-group/--end-group let us link multiple .a {{inputs}}
365 # without worrying about their relative order on the link line.
366 #
367 # This is mostly important for traditional linkers like GNU ld and Gold.
368 # The Mac/iOS linker neither needs nor accepts these flags.
369 # LLD doesn't need these flags, but accepts and ignores them.
370 _start_group = "-Wl,--start-group"
371 _end_group = "-Wl,--end-group"
372 if (is_mac || is_ios) {
373 _start_group = ""
374 _end_group = ""
375 }
376 command = "$link {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} -o $exe_name"
377
378 outputs = [ "$exe_name" ]
379 description = "link {{output}}"
380 if (0 <= link_pool_depth) {
381 pool = ":link_pool($default_toolchain)"
382 }
383 }
384
385 tool("stamp") {
386 command = "$stamp {{output}}"
387 description = "stamp {{output}}"
388 }
389
390 tool("copy") {
391 cp_py = rebase_path("../cp.py")
392 command = "python3 \"$cp_py\" {{source}} {{output}}"
393 description = "copy {{source}} {{output}}"
394 }
395
396 tool("copy_bundle_data") {
397 cp_py = rebase_path("../cp.py")
398 command = "python3 \"$cp_py\" {{source}} {{output}}"
399 description = "copy_bundle_data {{source}} {{output}}"
400 }
401
402 # We don't currently have any xcasset files so make this a NOP
403 tool("compile_xcassets") {
404 command = "true"
405 description = "compile_xcassets {{output}}"
406 }
407
408 toolchain_args = {
409 current_cpu = invoker.cpu
410 current_os = invoker.os
411 }
412 }
413 }
414
415 gcc_like_toolchain("gcc_like") {
416 cpu = current_cpu
417 os = current_os
418 ar = target_ar
419 cc = target_cc
420 cxx = target_cxx
421 link = target_link
422 }
423
424 gcc_like_toolchain("gcc_like_host") {
425 cpu = host_cpu
426 os = host_os
427 ar = host_ar
428 cc = host_cc
429 cxx = host_cxx
430 link = host_link
431 }
432
433 # Only define this toolchain if actually building for wasm.
434 if (is_wasm) {
435 gcc_like_toolchain("wasm") {
436 cpu = "wasm"
437 os = "wasm"
438 if (host_os == "win") {
439 ar = "$skia_emsdk_dir/upstream/emscripten/emar.bat"
440 cc = "$skia_emsdk_dir/upstream/emscripten/emcc.bat"
441 cxx = "$skia_emsdk_dir/upstream/emscripten/em++.bat"
442 } else {
443 ar = "$skia_emsdk_dir/upstream/emscripten/emar"
444 cc = "$skia_emsdk_dir/upstream/emscripten/emcc"
445 cxx = "$skia_emsdk_dir/upstream/emscripten/em++"
446 }
447 link = cxx
448 }
449 }