• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1declare_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) {
37    bin = "$win_vc/bin/amd64"
38  } else {
39    bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu"
40  }
41
42  env_setup = ""
43  if (target_cpu == "x86") {
44    # Toolchain asset includes a script that configures for x86 building.
45    # We don't support x86 builds with local MSVC installations.
46    env_setup = "cmd /c $win_sdk/bin/SetEnv.cmd /x86 && "
47  }
48
49  if (clang_win != "") {
50    cl = "$clang_win/bin/clang-cl.exe"
51  } else {
52    cl = "$bin/cl.exe"
53  }
54
55  tool("asm") {
56    _ml = "ml"
57    if (target_cpu == "x64") {
58      _ml += "64"
59    }
60    command = "$env_setup $bin/$_ml.exe /nologo /c /Fo {{output}} {{source}}"
61    outputs = [
62      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
63    ]
64    description = "assemble {{source}}"
65  }
66
67  tool("cc") {
68    rspfile = "{{output}}.rsp"
69    precompiled_header_type = "msvc"
70    pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
71
72    # Label names may have spaces so pdbname must be quoted.
73    command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
74    depsformat = "msvc"
75    outputs = [
76      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
77    ]
78    rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
79    description = "compile {{source}}"
80  }
81
82  tool("cxx") {
83    rspfile = "{{output}}.rsp"
84    precompiled_header_type = "msvc"
85    pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
86
87    # Label names may have spaces so pdbname must be quoted.
88    command = "$env_setup $cc_wrapper \"$cl\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
89    depsformat = "msvc"
90    outputs = [
91      "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
92    ]
93    rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
94    description = "compile {{source}}"
95  }
96
97  tool("alink") {
98    rspfile = "{{output}}.rsp"
99
100    command = "$env_setup $bin/lib.exe /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile"
101    outputs = [
102      # Ignore {{output_extension}} and always use .lib, there's no reason to
103      # allow targets to override this extension on Windows.
104      "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
105    ]
106    default_output_extension = ".lib"
107    default_output_dir = "{{target_out_dir}}"
108
109    # inputs_newline works around a fixed per-line buffer size in the linker.
110    rspfile_content = "{{inputs_newline}}"
111    description = "link {{output}}"
112  }
113
114  tool("solink") {
115    dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
116    libname = "${dllname}.lib"
117    pdbname = "${dllname}.pdb"
118    rspfile = "${dllname}.rsp"
119
120    command = "$env_setup $bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
121    outputs = [
122      dllname,
123      libname,
124      pdbname,
125    ]
126    default_output_extension = ".dll"
127    default_output_dir = "{{root_out_dir}}"
128
129    link_output = libname
130    depend_output = libname
131    runtime_outputs = [
132      dllname,
133      pdbname,
134    ]
135
136    # I don't quite understand this.  Aping Chrome's toolchain/win/BUILD.gn.
137    restat = true
138
139    # inputs_newline works around a fixed per-line buffer size in the linker.
140    rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
141    description = "link {{output}}"
142  }
143
144  tool("link") {
145    exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
146    pdbname = "$exename.pdb"
147    rspfile = "$exename.rsp"
148
149    command =
150        "$env_setup $bin/link.exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
151
152    default_output_extension = ".exe"
153    default_output_dir = "{{root_out_dir}}"
154    outputs = [
155      exename,
156    ]
157
158    # inputs_newline works around a fixed per-line buffer size in the linker.
159    rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
160    description = "link {{output}}"
161  }
162
163  tool("stamp") {
164    command = "$stamp {{output}}"
165    description = "stamp {{output}}"
166  }
167
168  tool("copy") {
169    cp_py = rebase_path("../cp.py")
170    command = "$python $cp_py {{source}} {{output}}"
171    description = "copy {{source}} {{output}}"
172  }
173}
174
175template("gcc_like_toolchain") {
176  toolchain(target_name) {
177    ar = invoker.ar
178    cc = invoker.cc
179    cxx = invoker.cxx
180    lib_switch = "-l"
181    lib_dir_switch = "-L"
182
183    tool("cc") {
184      depfile = "{{output}}.d"
185      command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
186      depsformat = "gcc"
187      outputs = [
188        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
189      ]
190      description = "compile {{source}}"
191    }
192
193    tool("cxx") {
194      depfile = "{{output}}.d"
195      command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
196      depsformat = "gcc"
197      outputs = [
198        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
199      ]
200      description = "compile {{source}}"
201    }
202
203    tool("objc") {
204      depfile = "{{output}}.d"
205      command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
206      depsformat = "gcc"
207      outputs = [
208        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
209      ]
210      description = "compile {{source}}"
211    }
212
213    tool("objcxx") {
214      depfile = "{{output}}.d"
215      command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
216      depsformat = "gcc"
217      outputs = [
218        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
219      ]
220      description = "compile {{source}}"
221    }
222
223    tool("asm") {
224      depfile = "{{output}}.d"
225      command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
226      depsformat = "gcc"
227      outputs = [
228        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
229      ]
230      description = "assemble {{source}}"
231    }
232
233    tool("alink") {
234      rspfile = "{{output}}.rsp"
235      rspfile_content = "{{inputs}}"
236      ar_py = rebase_path("../ar.py")
237      command = "$python $ar_py $ar {{output}} $rspfile"
238      outputs = [
239        "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
240      ]
241      default_output_extension = ".a"
242      output_prefix = "lib"
243      description = "link {{output}}"
244    }
245
246    tool("solink") {
247      soname = "{{target_output_name}}{{output_extension}}"
248
249      rpath = "-Wl,-soname,$soname"
250      if (is_mac) {
251        rpath = "-Wl,-install_name,@rpath/$soname"
252      }
253
254      rspfile = "{{output}}.rsp"
255      rspfile_content = "{{inputs}}"
256      command = "$cc_wrapper $cxx -shared {{ldflags}} @$rspfile {{solibs}} {{libs}} $rpath -o {{output}}"
257      outputs = [
258        "{{root_out_dir}}/$soname",
259      ]
260      output_prefix = "lib"
261      default_output_extension = ".so"
262      description = "link {{output}}"
263    }
264
265    tool("link") {
266      rspfile = "{{output}}.rsp"
267      rspfile_content = "{{inputs}}"
268      command = "$cc_wrapper $cxx {{ldflags}} @$rspfile {{solibs}} {{libs}} -o {{output}}"
269      outputs = [
270        "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
271      ]
272      description = "link {{output}}"
273    }
274
275    tool("stamp") {
276      command = "$stamp {{output}}"
277      description = "stamp {{output}}"
278    }
279
280    tool("copy") {
281      cp_py = rebase_path("../cp.py")
282      command = "$python $cp_py {{source}} {{output}}"
283      description = "copy {{source}} {{output}}"
284    }
285
286    tool("copy_bundle_data") {
287      cp_py = rebase_path("../cp.py")
288      command = "$python $cp_py {{source}} {{output}}"
289      description = "copy_bundle_data {{source}} {{output}}"
290    }
291
292    # We don't currently have any xcasset files so make this a NOP
293    tool("compile_xcassets") {
294      command = "true"
295      description = "compile_xcassets {{output}}"
296    }
297
298    toolchain_args = {
299      current_cpu = invoker.cpu
300      current_os = invoker.os
301    }
302  }
303}
304
305gcc_like_toolchain("gcc_like") {
306  cpu = current_cpu
307  os = current_os
308  ar = target_ar
309  cc = target_cc
310  cxx = target_cxx
311}
312
313gcc_like_toolchain("gcc_like_host") {
314  cpu = host_cpu
315  os = host_os
316  ar = host_ar
317  cc = host_cc
318  cxx = host_cxx
319}
320