1 import("//llvm/utils/gn/build/toolchain/compiler.gni")
4 # If is_goma is true, the location of the goma client install.
5 if (host_os == "win") {
6 goma_dir = "c:\src\goma\goma-win64"
8 goma_dir = getenv("HOME") + "/goma"
12 template("unix_toolchain") {
13 toolchain(target_name) {
14 forward_variables_from(invoker, "*")
17 depfile = "{{output}}.d"
18 command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
20 description = "CC {{output}}"
22 "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o",
27 depfile = "{{output}}.d"
28 command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
30 description = "CXX {{output}}"
32 "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o",
37 depfile = "{{output}}.d"
38 command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}}"
40 description = "ASM {{output}}"
42 "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o",
47 if (current_os == "mac") {
48 command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
50 # Remove the output file first so that ar doesn't try to modify the
53 "rm -f {{output}} && $ar rcsD {{arflags}} {{output}} {{inputs}}"
55 description = "AR {{output}}"
57 "{{output_dir}}/{{target_output_name}}.a",
60 default_output_dir = "{{root_out_dir}}/lib"
64 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
65 if (current_os == "mac") {
66 command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
67 default_output_extension = ".dylib"
69 command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
70 default_output_extension = ".so"
72 description = "SOLINK $outfile"
78 default_output_dir = "{{root_out_dir}}/lib"
81 tool("solink_module") {
82 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
83 if (current_os == "mac") {
84 command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
85 default_output_extension = ".dylib"
87 command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
88 default_output_extension = ".so"
90 description = "SOLINK $outfile"
95 default_output_dir = "{{root_out_dir}}/lib"
99 outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
100 if (current_os == "mac") {
101 command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
103 command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
105 description = "LINK $outfile"
111 # Setting this allows targets to override the default executable output by
112 # setting output_dir.
113 default_output_dir = "{{root_out_dir}}/bin"
116 copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
118 command = copy_command
119 description = "COPY {{source}} {{output}}"
122 if (current_os == "mac") {
123 tool("copy_bundle_data") {
124 # http://serverfault.com/q/209888/43689
125 _copydir = "mkdir -p {{output}} && cd {{source}} && " +
126 "pax -rwl . \"\$OLDPWD\"/{{output}}"
127 command = "rm -rf {{output}} && if [[ -d {{source}} ]]; then " +
128 _copydir + "; else " + copy_command + "; fi"
129 description = "COPY_BUNDLE_DATA {{source}} {{output}}"
131 tool("compile_xcassets") {
133 description = "The LLVM build doesn't use any xcasset files"
138 command = "touch {{output}}"
139 description = "STAMP {{output}}"
144 unix_toolchain("unix") {
148 if (clang_base_path != "") {
149 cc = "$clang_base_path/bin/clang"
150 cxx = "$clang_base_path/bin/clang++"
153 ld = cxx # Don't use goma wrapper for linking.
155 cc = "$goma_dir/gomacc $cc"
156 cxx = "$goma_dir/gomacc $cxx"
159 if (current_os != "mac") {
165 current_cpu = host_cpu
169 # This template defines a toolchain that uses just-built clang and lld
170 # as compiler and linker.
171 template("stage2_unix_toolchain") {
172 unix_toolchain(target_name) {
173 forward_variables_from(invoker, "*")
178 if (current_os != "mac") {
183 "//:clang($host_toolchain)",
184 "//:lld($host_toolchain)",
186 if (current_os != "mac") {
187 deps += [ "//:llvm-ar($host_toolchain)" ]
192 stage2_unix_toolchain("stage2_unix") {
195 current_cpu = host_cpu
197 use_lld = host_os != "mac"
201 if (android_ndk_path != "") {
202 stage2_unix_toolchain("stage2_android_aarch64") {
204 current_os = "android"
205 current_cpu = "arm64"
216 if (clang_base_path != "") {
217 cl = "$clang_base_path/bin/clang-cl"
219 link = "$clang_base_path/bin/lld-link"
224 cl = "$goma_dir/gomacc $cl"
228 command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
230 description = "CC {{output}}"
232 "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj",
237 command = "$cl /nologo /showIncludes /Fo{{output}} /c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
239 description = "CXX {{output}}"
241 "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.obj",
246 command = "$link /lib /nologo {{arflags}} /out:{{output}} {{inputs}}"
247 description = "LIB {{output}}"
249 "{{output_dir}}/{{target_output_name}}.lib",
251 default_output_dir = "{{root_out_dir}}/lib"
255 outprefix = "{{output_dir}}/{{target_output_name}}"
256 dllfile = "$outprefix{{output_extension}}"
257 libfile = "$outprefix.lib"
258 pdbfile = "$outprefix.pdb"
259 command = "$link /nologo /dll {{ldflags}} /out:$dllfile /implib:$libfile /pdb:$pdbfile {{libs}} {{inputs}}"
260 description = "LINK $dllfile"
261 link_output = libfile
262 depend_output = libfile
263 runtime_outputs = [ dllfile ]
269 default_output_extension = ".dll"
272 # Put dlls next to the executables in bin/ on Windows, since Windows
273 # doesn't have a configurable rpath. This matches initialization of
274 # module_dir to bin/ in AddLLVM.cmake's set_output_directory().
275 default_output_dir = "{{root_out_dir}}/bin"
278 # Plugins for opt and clang and so on don't work in LLVM's Windows build
279 # since the code doesn't have export annotations, but there are a few
280 # standalone loadable modules used for unit-testing LLVM's dynamic library
282 tool("solink_module") {
283 outprefix = "{{output_dir}}/{{target_output_name}}"
284 dllfile = "$outprefix{{output_extension}}"
285 pdbfile = "$outprefix.pdb"
286 command = "$link /nologo /dll {{ldflags}} /out:$dllfile /pdb:$pdbfile {{libs}} {{inputs}}"
287 description = "LINK_MODULE $dllfile"
292 runtime_outputs = outputs
293 default_output_extension = ".dll"
295 # No default_output_dir, all clients set output_dir.
299 outprefix = "{{output_dir}}/{{target_output_name}}"
300 outfile = "$outprefix{{output_extension}}"
301 pdbfile = "$outprefix.pdb"
302 command = "$link /nologo {{ldflags}} /out:$outfile /pdb:$pdbfile {{libs}} {{inputs}}"
303 description = "LINK $outfile"
308 default_output_extension = ".exe"
310 # Setting this allows targets to override the default executable output by
311 # setting output_dir.
312 default_output_dir = "{{root_out_dir}}/bin"
316 # GN hands out slash-using paths, but cmd's copy needs backslashes.
317 # Use cmd's %foo:a=b% substitution feature to convert.
318 command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul"
319 description = "COPY {{source}} {{output}}"
323 command = "cmd /c type nul > {{output}}"
324 description = "STAMP {{output}}"
329 current_cpu = host_cpu