summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/nacl/rules.gni
blob: 42bb2483572fbae70dffa67e5792e34e6473b0b9 (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
# Copyright 2015 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")

# Generate a nmf file
#
# Native Client Manifest (nmf) is a JSON file that tells the browser where to
# download and load Native Client application files and libraries.
#
# Variables:
#   executables: .nexe/.pexe/.bc executables to generate nmf for
#   lib_prefix: path to prepend to shared libraries in the nmf
#   nmf: the name and the path of the output file
#   nmfflags: additional flags for the nmf generator
#   stage_dependencies: directory for staging libraries
template("generate_nmf") {
  assert(defined(invoker.executables), "Must define executables")
  assert(defined(invoker.nmf), "Must define nmf")

  action(target_name) {
    forward_variables_from(invoker,
                           [
                             "deps",
                             "data_deps",
                             "executables",
                             "lib_prefix",
                             "nmf",
                             "nmfflags",
                             "public_deps",
                             "stage_dependencies",
                             "testonly",
                             "visibility",
                           ])
    if (!defined(nmfflags)) {
      nmfflags = []
    }

    # TODO(phosek): Remove this conditional once
    # https://bugs.chromium.org/p/nativeclient/issues/detail?id=4339 is
    # resolved.
    if (target_cpu == "pnacl") {
      objdump = rebase_path("${nacl_toolchain_bindir}/x86_64-nacl-objdump")
    } else {
      objdump = rebase_path("${nacl_toolprefix}objdump")
    }
    if (host_os == "win") {
      objdump += ".exe"
    }

    script = "//native_client_sdk/src/tools/create_nmf.py"
    inputs = [ objdump ]
    sources = executables
    outputs = [ nmf ]
    if (is_nacl_glibc) {
      if (defined(stage_dependencies)) {
        nmfflags += [ "--stage-dependencies=" +
                      rebase_path(stage_dependencies, root_build_dir) ]
        lib_path = stage_dependencies
      } else {
        lib_path = root_build_dir
      }
      if (defined(lib_prefix)) {
        nmfflags += [ "--lib-prefix=" + lib_prefix ]
        lib_path += "/${lib_prefix}"
      }

      # Starts empty so the code below can use += everywhere.
      data = []

      nmfflags +=
          [ "--library-path=" + rebase_path(root_out_dir, root_build_dir) ]

      # NOTE: There is no explicit dependency for the lib directory
      # (lib32 and lib64 for x86/x64) created in the product directory.
      # They are created as a side-effect of nmf creation.
      if (target_cpu != "x86" && target_cpu != "x64") {
        nmfflags +=
            [ "--library-path=" +
              rebase_path("${nacl_toolchain_tooldir}/lib", root_build_dir) ]
        if (target_cpu == "arm") {
          data += [ "${lib_path}/libarm/" ]
        } else {
          data += [ "${lib_path}/lib/" ]
        }
      } else {
        # For x86-32, the lib/ directory is called lib32/ instead.
        if (target_cpu == "x86") {
          nmfflags +=
              [ "--library-path=" +
                rebase_path("${nacl_toolchain_tooldir}/lib32", root_build_dir) ]
          data += [ "${lib_path}/lib32/" ]
        }

        # x86-32 Windows needs to build both x86-32 and x86-64 NaCl
        # binaries into the same nmf covering both architectures.  That
        # gets handled at a higher level (see the nacl_test_data template),
        # so a single generate_nmf invocation gets both x86-32 and x86-64
        # nexes listed in executables.
        if (target_cpu == "x64" || target_os == "win") {
          # For x86-64, the lib/ directory is called lib64/ instead
          # when copied by create_nmf.py.
          glibc_tc = "//build/toolchain/nacl:glibc"
          assert(current_toolchain == "${glibc_tc}_${target_cpu}")
          if (target_cpu == "x64") {
            x64_out_dir = root_out_dir
          } else {
            x64_out_dir = get_label_info(":${target_name}(${glibc_tc}_x64)",
                                         "root_out_dir")
          }
          nmfflags += [
            "--library-path=" + rebase_path(x64_out_dir, root_build_dir),
            "--library-path=" +
                rebase_path("${nacl_toolchain_tooldir}/lib", root_build_dir),
          ]
          data += [ "${lib_path}/lib64/" ]
        }
      }
    }
    args = [
             "--no-default-libpath",
             "--objdump=" + rebase_path(objdump, root_build_dir),
             "--output=" + rebase_path(nmf, root_build_dir),
           ] + nmfflags + rebase_path(sources, root_build_dir)
    if (is_nacl_glibc && target_cpu == "arm") {
      deps += [ "//native_client/src/untrusted/elf_loader:elf_loader" ]
    }
  }
}

# Generate a nmf file for Non-SFI tests
#
# Non-SFI tests use a different manifest format from regular Native Client and
# as such requires a different generator.
#
# Variables:
#   executable: Non-SFI .nexe executable to generate nmf for
#   nmf: the name and the path of the output file
#   nmfflags: additional flags for the nmf generator
template("generate_nonsfi_test_nmf") {
  assert(defined(invoker.executable), "Must define executable")
  assert(defined(invoker.nmf), "Must define nmf")

  action(target_name) {
    forward_variables_from(invoker,
                           [
                             "deps",
                             "data_deps",
                             "executable",
                             "nmf",
                             "testonly",
                             "public_deps",
                             "visibility",
                           ])

    script = "//ppapi/tests/create_nonsfi_test_nmf.py"
    sources = [ executable ]
    outputs = [ nmf ]

    # NOTE: We use target_cpu rather than target_cpu on purpose because
    # target_cpu is always going to be pnacl for Non-SFI, but the Non-SFI
    # .nexe executable is always translated to run on the target machine.
    if (target_cpu == "x86") {
      arch = "x86-32"
    } else if (target_cpu == "x64") {
      arch = "x86-64"
    } else {
      arch = target_cpu
    }
    args = [
      "--program=" + rebase_path(executable, root_build_dir),
      "--arch=${arch}",
      "--output=" + rebase_path(nmf, root_build_dir),
    ]
    if (defined(invoker.nmfflags)) {
      args += invoker.nmfflags
    }
  }
}