Debian Codegraph @

gn/toolchain/BUILD.gn

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