File: BUILD.gn

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (395 lines) | stat: -rw-r--r-- 12,738 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
import("//llvm/utils/gn/build/toolchain/compiler.gni")

declare_args() {
  # If is_goma is true, the location of the goma client install.
  # Set this to the output of `goma_ctl goma_dir`.
  goma_dir = ""
}

assert(!use_goma || goma_dir != "",
       "set `goma_dir` to the output of `goma_ctl goma_dir` in your args.gn")

template("unix_toolchain") {
  toolchain(target_name) {
    # https://groups.google.com/a/chromium.org/d/msg/gn-dev/F_lv5T-tNDM
    forward_variables_from(invoker.toolchain_args, "*")
    not_needed("*")

    forward_variables_from(invoker, "*")

    cc = "cc"
    cxx = "c++"

    if (clang_base_path != "") {
      cc = rebase_path(clang_base_path, root_build_dir) + "/bin/clang"
      cxx = rebase_path(clang_base_path, root_build_dir) + "/bin/clang++"
    }

    ld = cxx  # Don't use goma wrapper for linking.
    if (use_goma) {
      cc = "$goma_dir/gomacc $cc"
      cxx = "$goma_dir/gomacc $cxx"
    }

    tool("cc") {
      depfile = "{{output}}.d"
      command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
      depsformat = "gcc"
      description = "CC {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
    }

    tool("cxx") {
      depfile = "{{output}}.d"
      command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
      depsformat = "gcc"
      description = "CXX {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
    }

    tool("objcxx") {
      depfile = "{{output}}.d"
      command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_objcc}}"
      depsformat = "gcc"
      description = "OBJCXX {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
    }

    tool("asm") {
      depfile = "{{output}}.d"
      command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}}"
      depsformat = "gcc"
      description = "ASM {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
    }

    tool("alink") {
      if (current_os == "ios" || current_os == "mac") {
        command = "libtool -D -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
      } else {
        # Remove the output file first so that ar doesn't try to modify the
        # existing file.
        command =
            "rm -f {{output}} && $ar rcsD {{arflags}} {{output}} {{inputs}}"
      }
      description = "AR {{output}}"
      outputs = [ "{{output_dir}}/{{target_output_name}}.a" ]
      output_prefix = "lib"
      default_output_dir = "{{root_out_dir}}/lib"
    }

    if (current_os == "ios" || current_os == "mac") {
      # gn < 1693 (e214b5d35898) doesn't support |frameworks|, requiring
      # frameworks to be listed in |libs|, but gn >= 1808 (3028c6a426a4) forbids
      # frameworks from appearing in |libs|. This assertion provides a helpful
      # cue to upgrade, and is much more user-friendly than the failure that
      # occurs when an older gn encounters |frameworks|.
      #
      # gn_version doesn’t actually exist in gn < 1709 (52cb644a3fb4), and
      # defined(gn_version) doesn't actually work as expected
      # (https://crbug.com/gn/183), so 1709 is the true minimum enforced by
      # this construct, and if gn_version is not available, this line will still
      # be blamed, making the resolution somewhat discoverable.
      assert(gn_version >= 1693,
             "Your GN is too old! " +
                 "Update it, perhaps by running llvm/utils/gn/get.py")
    }

    # Make these apply to all tools below.
    lib_switch = "-l"
    lib_dir_switch = "-L"

    tool("solink") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      if (current_os == "ios" || current_os == "mac") {
        command = "$ld -shared {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}"
        default_output_extension = ".dylib"
      } else {
        command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{inputs}} {{libs}}"
        default_output_extension = ".so"
      }
      description = "SOLINK $outfile"
      outputs = [ outfile ]
      output_prefix = "lib"
      default_output_dir = "{{root_out_dir}}/lib"
    }

    tool("solink_module") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      if (current_os == "ios" || current_os == "mac") {
        command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{inputs}} {{libs}} {{frameworks}}"
        default_output_extension = ".dylib"
      } else {
        command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{inputs}} {{libs}}"
        default_output_extension = ".so"
      }
      description = "SOLINK $outfile"
      outputs = [ outfile ]
      default_output_dir = "{{root_out_dir}}/lib"
    }

    tool("link") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      if (current_os == "ios" || current_os == "mac") {
        command =
            "$ld {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}"
      } else {
        command = "$ld {{ldflags}} -o $outfile -Wl,--start-group {{inputs}} -Wl,--end-group {{libs}}"
      }
      description = "LINK $outfile"
      outputs = [ outfile ]

      # Setting this allows targets to override the default executable output by
      # setting output_dir.
      default_output_dir = "{{root_out_dir}}/bin"
    }

    copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
    tool("copy") {
      command = copy_command
      description = "COPY {{source}} {{output}}"
    }

    if (current_os == "ios" || current_os == "mac") {
      tool("copy_bundle_data") {
        # https://github.com/nico/hack/blob/master/notes/copydir.md
        _copydir = "cd {{source}} && " +
                   "find . | cpio -pdl \"\$OLDPWD\"/{{output}} 2>/dev/null"
        command = "rm -rf {{output}} && if [[ -d {{source}} ]]; then " +
                  _copydir + "; else " + copy_command + "; fi"
        description = "COPY_BUNDLE_DATA {{source}} {{output}}"
      }
      tool("compile_xcassets") {
        command = "false"
        description = "The LLVM build doesn't use any xcasset files"
      }
    }

    tool("stamp") {
      command = "touch {{output}}"
      description = "STAMP {{output}}"
    }
  }
}

unix_toolchain("unix") {
  if (current_os != "ios" && current_os != "mac") {
    ar = "ar"
  }

  toolchain_args = {
    current_os = host_os
    current_cpu = host_cpu
  }
}

# This template defines a toolchain that uses just-built clang and lld
# as compiler and linker.
template("stage2_unix_toolchain") {
  unix_toolchain(target_name) {
    toolchain_args = {
      forward_variables_from(invoker.toolchain_args, "*")

      clang_base_path = root_build_dir
      use_goma = false
    }

    deps = [
      "//:clang($host_toolchain)",
      "//:lld($host_toolchain)",
    ]
    if (current_os != "ios" && current_os != "mac") {
      ar = "bin/llvm-ar"
      deps += [ "//:llvm-ar($host_toolchain)" ]
    }
  }
}

stage2_unix_toolchain("stage2_unix") {
  toolchain_args = {
    current_os = host_os
    current_cpu = host_cpu
  }
}

if (android_ndk_path != "") {
  stage2_unix_toolchain("stage2_android_aarch64") {
    toolchain_args = {
      current_os = "android"
      current_cpu = "arm64"
    }
  }

  stage2_unix_toolchain("stage2_android_arm") {
    toolchain_args = {
      current_os = "android"
      current_cpu = "arm"
    }
  }
}

if (host_os == "mac") {
  stage2_unix_toolchain("stage2_ios_aarch64") {
    toolchain_args = {
      current_os = "ios"
      current_cpu = "arm64"
    }
  }

  stage2_unix_toolchain("stage2_iossim_x64") {
    toolchain_args = {
      current_os = "ios"
      current_cpu = "x64"
    }
  }
}

template("win_toolchain") {
  toolchain(target_name) {
    # https://groups.google.com/a/chromium.org/d/msg/gn-dev/F_lv5T-tNDM
    forward_variables_from(invoker.toolchain_args, "*")
    not_needed("*")

    forward_variables_from(invoker, "*")

    cl = "cl"
    link = "link"

    if (clang_base_path != "") {
      cl = rebase_path(clang_base_path, root_build_dir) + "/bin/clang-cl"
      if (use_lld) {
        link = rebase_path(clang_base_path, root_build_dir) + "/bin/lld-link"
      }
    }

    if (use_goma) {
      cl = "$goma_dir/gomacc $cl"
    }

    tool("cc") {
      command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
      depsformat = "msvc"
      description = "CC {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
    }

    tool("cxx") {
      command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
      depsformat = "msvc"
      description = "CXX {{output}}"
      outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj" ]
    }

    tool("alink") {
      command = "$link /lib /nologo {{arflags}} /out:{{output}} {{inputs}}"
      description = "LIB {{output}}"
      outputs = [ "{{output_dir}}/{{target_output_name}}.lib" ]
      default_output_dir = "{{root_out_dir}}/lib"
    }

    # Make these apply to all tools below.
    lib_switch = ""
    lib_dir_switch = "/LIBPATH:"

    tool("solink") {
      outprefix = "{{output_dir}}/{{target_output_name}}"
      dllfile = "$outprefix{{output_extension}}"
      libfile = "$outprefix.lib"
      pdbfile = "$outprefix.pdb"
      command = "$link /nologo /dll {{ldflags}} /out:$dllfile /implib:$libfile /pdb:$pdbfile {{inputs}} {{libs}} "
      description = "LINK $dllfile"
      link_output = libfile
      depend_output = libfile
      runtime_outputs = [ dllfile ]
      outputs = [
        dllfile,
        libfile,
      ]
      default_output_extension = ".dll"
      restat = true

      # Put dlls next to the executables in bin/ on Windows, since Windows
      # doesn't have a configurable rpath. This matches initialization of
      # module_dir to bin/ in AddLLVM.cmake's set_output_directory().
      default_output_dir = "{{root_out_dir}}/bin"
    }

    # Plugins for opt and clang and so on don't work in LLVM's Windows build
    # since the code doesn't have export annotations, but there are a few
    # standalone loadable modules used for unit-testing LLVM's dynamic library
    # loading code.
    tool("solink_module") {
      outprefix = "{{output_dir}}/{{target_output_name}}"
      dllfile = "$outprefix{{output_extension}}"
      pdbfile = "$outprefix.pdb"
      command = "$link /nologo /dll {{ldflags}} /out:$dllfile /pdb:$pdbfile {{inputs}} {{libs}} "
      description = "LINK_MODULE $dllfile"
      outputs = [ dllfile ]
      runtime_outputs = outputs
      default_output_extension = ".dll"

      # No default_output_dir, all clients set output_dir.
    }

    tool("link") {
      outprefix = "{{output_dir}}/{{target_output_name}}"
      outfile = "$outprefix{{output_extension}}"
      pdbfile = "$outprefix.pdb"
      command = "$link /nologo {{ldflags}} /out:$outfile /pdb:$pdbfile {{inputs}} {{libs}}"
      description = "LINK $outfile"
      outputs = [ outfile ]
      default_output_extension = ".exe"

      # Setting this allows targets to override the default executable output by
      # setting output_dir.
      default_output_dir = "{{root_out_dir}}/bin"
    }

    tool("copy") {
      # GN hands out slash-using paths, but cmd's copy needs backslashes.
      # Use cmd's %foo:a=b% substitution feature to convert.
      command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
      description = "COPY {{source}} {{output}}"
    }

    tool("stamp") {
      command = "cmd /c type nul > {{output}}"
      description = "STAMP {{output}}"
    }
  }
}

win_toolchain("win") {
  toolchain_args = {
    current_os = "win"
    current_cpu = host_cpu
  }
}

win_toolchain("stage2_win") {
  toolchain_args = {
    current_os = host_os
    current_cpu = host_cpu

    clang_base_path = root_build_dir
    use_goma = false
  }
  deps = [
    "//:clang($host_toolchain)",
    "//:lld($host_toolchain)",
  ]
}

win_toolchain("stage2_win_x86") {
  toolchain_args = {
    current_os = host_os
    current_cpu = "x86"

    clang_base_path = root_build_dir
    use_goma = false
  }
  deps = [
    "//:clang($host_toolchain)",
    "//:lld($host_toolchain)",
  ]
}