summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/toolchain/nacl/BUILD.gn
blob: 259e6347ae0034f947f11d865398bac208959bcf (plain)
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
# Copyright (c) 2014 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/nacl/config.gni")
import("//build/config/sysroot.gni")
import("//build/toolchain/nacl_toolchain.gni")

# Add the toolchain revision as a preprocessor define so that sources are
# rebuilt when a toolchain is updated.
# Idea we could use the toolchain deps feature, but currently that feature is
# bugged and does not trigger a rebuild.
# https://code.google.com/p/chromium/issues/detail?id=431880
# Calls to get the toolchain revision are relatively slow, so do them all in a
# single batch to amortize python startup, etc.
revisions = exec_script("//native_client/build/get_toolchain_revision.py",
                        [
                          "nacl_x86_glibc",
                          "nacl_arm_glibc",
                          "pnacl_newlib",
                          "saigo_newlib",
                        ],
                        "trim list lines")
nacl_x86_glibc_rev = revisions[0]
nacl_arm_glibc_rev = revisions[1]

pnacl_newlib_rev = revisions[2]
saigo_newlib_rev = revisions[3]

use_saigo = true

if (host_os == "win") {
  toolsuffix = ".exe"
} else {
  toolsuffix = ""
}

# The PNaCl toolchain tools are all wrapper scripts rather than binary
# executables.  On POSIX systems, nobody cares what kind of executable
# file you are.  But on Windows, scripts (.bat files) cannot be run
# directly and need the Windows shell (cmd.exe) specified explicily.
if (host_os == "win") {
  # NOTE!  The //build/toolchain/gcc_*_wrapper.py scripts recognize
  # this exact prefix string, so they must be updated if this string
  # is changed in any way.
  scriptprefix = "cmd /c call "
  scriptsuffix = ".bat"
} else {
  scriptprefix = ""
  scriptsuffix = ""
}

# When the compilers are run via goma, rbe or ccache rather than directly by
# GN/Ninja, the rbe/goma/ccache wrapper handles .bat files but gets confused
# by being given the scriptprefix.
if (host_os == "win" && !use_goma && !use_rbe && cc_wrapper == "") {
  compiler_scriptprefix = scriptprefix
} else {
  compiler_scriptprefix = ""
}

template("pnacl_toolchain") {
  assert(defined(invoker.executable_extension),
         "Must define executable_extension")

  nacl_toolchain(target_name) {
    toolchain_package = "pnacl_newlib"
    toolchain_revision = pnacl_newlib_rev
    toolprefix =
        rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/pnacl-",
                    root_build_dir)

    if (host_os == "win") {
      # Flip the slashes so that copy/paste of the commands works.
      # This is also done throughout build\toolchain\win\BUILD.gn
      toolprefix = string_replace(toolprefix, "/", "\\")
    }

    cc = compiler_scriptprefix + toolprefix + "clang" + scriptsuffix
    cxx = compiler_scriptprefix + toolprefix + "clang++" + scriptsuffix
    ar = toolprefix + "ar" + scriptsuffix
    readelf = scriptprefix + toolprefix + "readelf" + scriptsuffix
    nm = scriptprefix + toolprefix + "nm" + scriptsuffix
    if (defined(invoker.strip)) {
      strip = scriptprefix + toolprefix + invoker.strip + scriptsuffix
    }
    forward_variables_from(invoker,
                           [
                             "executable_extension",
                             "is_clang_analysis_supported",
                             "extra_cppflags",
                           ])

    # Note this is not the usual "ld = cxx" because "ld" uses are
    # never run via goma, so this needs scriptprefix.
    ld = scriptprefix + toolprefix + "clang++" + scriptsuffix

    toolchain_args = {
      is_clang = true
      target_cpu = "pnacl"
      use_lld = false
    }
  }
}

pnacl_toolchain("newlib_pnacl") {
  executable_extension = ".pexe"

  # The pnacl-finalize tool turns a .pexe.debug file into a .pexe file.
  # It's very similar in purpose to the traditional "strip" utility: it
  # turns what comes out of the linker into what you actually want to
  # distribute and run.  PNaCl doesn't have a "strip"-like utility that
  # you ever actually want to use other than pnacl-finalize, so just
  # make pnacl-finalize the strip tool rather than adding an additional
  # step like "postlink" to run pnacl-finalize.
  strip = "finalize"
}

pnacl_toolchain("newlib_pnacl_nonsfi") {
  executable_extension = ""
  strip = "strip"

  # This macro is embedded on nonsfi toolchains but reclient can't figure
  # that out itself, so we make it explicit.
  extra_cppflags = "-D__native_client_nonsfi__"
}

template("nacl_glibc_toolchain") {
  toolchain_cpu = target_name
  assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  assert(defined(invoker.toolchain_package), "Must define toolchain_package")
  assert(defined(invoker.toolchain_revision), "Must define toolchain_revision")
  forward_variables_from(invoker,
                         [
                           "toolchain_package",
                           "toolchain_revision",
                         ])

  toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
                               invoker.toolchain_tuple + "-",
                           root_build_dir)

  if (host_os == "win") {
    # Flip the slashes so that copy/paste of the commands works.
    # This is also done throughout build\toolchain\win\BUILD.gn
    toolprefix = string_replace(toolprefix, "/", "\\")
  }

  nacl_toolchain("glibc_" + toolchain_cpu) {
    cc = toolprefix + "gcc" + toolsuffix
    cxx = toolprefix + "g++" + toolsuffix
    ar = toolprefix + "ar" + toolsuffix
    ld = cxx
    readelf = toolprefix + "readelf" + toolsuffix
    nm = toolprefix + "nm" + toolsuffix
    strip = toolprefix + "strip" + toolsuffix

    toolchain_args = {
      target_cpu = toolchain_cpu

      # reclient does not support gcc.
      use_rbe = false
      is_clang = false
      is_nacl_glibc = true
      use_lld = false
    }
  }
}

nacl_glibc_toolchain("x86") {
  toolchain_package = "nacl_x86_glibc"
  toolchain_revision = nacl_x86_glibc_rev

  # Rely on the :compiler_cpu_abi config adding the -m32 flag here rather
  # than using the i686-nacl binary directly.  This is a because i686-nacl-gcc
  # is a shell script wrapper around x86_64-nacl-gcc and goma has trouble with
  # compiler executables that are shell scripts (so the i686 'compiler' is not
  # currently in goma).
  toolchain_tuple = "x86_64-nacl"
}

nacl_glibc_toolchain("x64") {
  toolchain_package = "nacl_x86_glibc"
  toolchain_revision = nacl_x86_glibc_rev
  toolchain_tuple = "x86_64-nacl"
}

nacl_glibc_toolchain("arm") {
  toolchain_package = "nacl_arm_glibc"
  toolchain_revision = nacl_arm_glibc_rev
  toolchain_tuple = "arm-nacl"
}

template("nacl_clang_toolchain") {
  toolchain_cpu = target_name
  assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")

  toolchain_package = "pnacl_newlib"
  toolchain_revision = pnacl_newlib_rev
  toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
                               invoker.toolchain_tuple + "-",
                           root_build_dir)

  if (host_os == "win") {
    # Flip the slashes so that copy/paste of the commands works.
    # This is also done throughout build\toolchain\win\BUILD.gn
    toolprefix = string_replace(toolprefix, "/", "\\")
  }

  nacl_toolchain("clang_newlib_" + toolchain_cpu) {
    cc = toolprefix + "clang" + toolsuffix
    cxx = toolprefix + "clang++" + toolsuffix
    ar = toolprefix + "ar" + toolsuffix
    ld = cxx
    readelf = toolprefix + "readelf" + toolsuffix
    nm = toolprefix + "nm" + toolsuffix
    strip = toolprefix + "strip" + toolsuffix

    toolchain_args = {
      target_cpu = toolchain_cpu
      is_clang = true
      use_lld = false
    }
  }
}

template("nacl_irt_toolchain") {
  toolchain_cpu = target_name
  assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")

  toolchain_package = "pnacl_newlib"
  toolchain_revision = pnacl_newlib_rev
  if (use_saigo) {
    toolchain_package = "saigo_newlib"
    toolchain_revision = saigo_newlib_rev
  }
  toolprefix = rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/" +
                               invoker.toolchain_tuple + "-",
                           root_build_dir)

  if (host_os == "win") {
    # Flip the slashes so that copy/paste of the commands works.
    # This is also done throughout build\toolchain\win\BUILD.gn
    toolprefix = string_replace(toolprefix, "/", "\\")
  }

  link_irt = rebase_path("//native_client/build/link_irt.py", root_build_dir)

  tls_edit_label =
      "//native_client/src/tools/tls_edit:tls_edit($host_toolchain)"
  host_toolchain_out_dir =
      rebase_path(get_label_info(tls_edit_label, "root_out_dir"),
                  root_build_dir)
  tls_edit = "${host_toolchain_out_dir}/tls_edit"

  nacl_toolchain("irt_" + toolchain_cpu) {
    cc = toolprefix + "clang" + toolsuffix
    cxx = toolprefix + "clang++" + toolsuffix
    ar = toolprefix + "ar" + toolsuffix
    readelf = toolprefix + "readelf" + toolsuffix
    nm = toolprefix + "nm" + toolsuffix
    strip = toolprefix + "strip" + toolsuffix

    # Some IRT implementations (notably, Chromium's) contain C++ code,
    # so we need to link w/ the C++ linker.
    ld = "${python_path} ${link_irt} --tls-edit=${tls_edit} --link-cmd=${cxx} --readelf-cmd=${readelf}"

    toolchain_args = {
      target_cpu = toolchain_cpu
      is_clang = true
      use_lld = false
      is_nacl_saigo = use_saigo
    }

    # TODO(ncbray): depend on link script
    deps = [ tls_edit_label ]
  }
}

template("nacl_clang_toolchains") {
  assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
  nacl_clang_toolchain(target_name) {
    toolchain_tuple = invoker.toolchain_tuple
  }
  nacl_irt_toolchain(target_name) {
    toolchain_tuple = invoker.toolchain_tuple
  }
}

nacl_clang_toolchains("x86") {
  # Rely on :compiler_cpu_abi adding -m32.  See nacl_x86_glibc above.
  toolchain_tuple = "x86_64-nacl"
}

nacl_clang_toolchains("x64") {
  toolchain_tuple = "x86_64-nacl"
}

nacl_clang_toolchains("arm") {
  toolchain_tuple = "arm-nacl"
}

nacl_clang_toolchains("mipsel") {
  toolchain_tuple = "mipsel-nacl"
}