blob: 0d6d03640a3de8586de2fdef6cca10a53d611d7d [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# Copyright 2015 The Native Client Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/features.gni")
6import("//build/config/nacl/config.gni")
7
8# Generate a nmf file
9#
10# Native Client Manifest (nmf) is a JSON file that tells the browser where to
11# download and load Native Client application files and libraries.
12#
13# Variables:
14# executables: .nexe/.pexe/.bc executables to generate nmf for
15# lib_prefix: path to prepend to shared libraries in the nmf
16# nmf: the name and the path of the output file
17# nmfflags: additional flags for the nmf generator
18# stage_dependencies: directory for staging libraries
19template("generate_nmf") {
20 assert(defined(invoker.executables), "Must define executables")
21 assert(defined(invoker.nmf), "Must define nmf")
22
23 action(target_name) {
24 forward_variables_from(invoker,
25 [
26 "deps",
27 "data_deps",
28 "executables",
29 "lib_prefix",
30 "nmf",
31 "nmfflags",
32 "public_deps",
33 "stage_dependencies",
34 "testonly",
35 "visibility",
36 ])
37 if (!defined(nmfflags)) {
38 nmfflags = []
39 }
40
41 # TODO(phosek): Remove this conditional once
42 # https://bugs.chromium.org/p/nativeclient/issues/detail?id=4339 is
43 # resolved.
44 if (current_cpu == "pnacl") {
45 objdump = rebase_path("${nacl_toolchain_bindir}/x86_64-nacl-objdump")
46 } else {
47 objdump = rebase_path("${nacl_toolprefix}objdump")
48 }
49 if (host_os == "win") {
50 objdump += ".exe"
51 }
52
53 script = "//native_client_sdk/src/tools/create_nmf.py"
54 inputs = [
55 objdump,
56 ]
57 sources = executables
58 outputs = [
59 nmf,
60 ]
61 if (is_nacl_glibc) {
62 if (defined(stage_dependencies)) {
63 nmfflags += [ "--stage-dependencies=" +
64 rebase_path(stage_dependencies, root_build_dir) ]
65 lib_path = stage_dependencies
66 } else {
67 lib_path = root_build_dir
68 }
69 if (defined(lib_prefix)) {
70 nmfflags += [ "--lib-prefix=" + lib_prefix ]
71 lib_path += "/${lib_prefix}"
72 }
73
74 # Starts empty so the code below can use += everywhere.
75 data = []
76
77 nmfflags += [ "--library-path=" + rebase_path(root_out_dir) ]
78
79 # NOTE: There is no explicit dependency for the lib directory
80 # (lib32 and lib64 for x86/x64) created in the product directory.
81 # They are created as a side-effect of nmf creation.
82 if (current_cpu != "x86" && current_cpu != "x64") {
83 nmfflags +=
84 [ "--library-path=" + rebase_path("${nacl_toolchain_tooldir}/lib") ]
85 data += [ "${lib_path}/lib/" ]
86 } else {
87 # For x86-32, the lib/ directory is called lib32/ instead.
88 if (current_cpu == "x86") {
89 nmfflags += [ "--library-path=" +
90 rebase_path("${nacl_toolchain_tooldir}/lib32") ]
91 data += [ "${lib_path}/lib32/" ]
92 }
93
94 # x86-32 Windows needs to build both x86-32 and x86-64 NaCl
95 # binaries into the same nmf covering both architectures. That
96 # gets handled at a higher level (see the nacl_test_data template),
97 # so a single generate_nmf invocation gets both x86-32 and x86-64
98 # nexes listed in executables.
99 if (current_cpu == "x64" || target_os == "win") {
100 # For x86-64, the lib/ directory is called lib64/ instead
101 # when copied by create_nmf.py.
102 glibc_tc = "//build/toolchain/nacl:glibc"
103 assert(current_toolchain == "${glibc_tc}_${current_cpu}")
104 if (current_cpu == "x64") {
105 x64_out_dir = root_out_dir
106 } else {
107 x64_out_dir = get_label_info(":${target_name}(${glibc_tc}_x64)",
108 "root_out_dir")
109 }
110 nmfflags += [
111 "--library-path=" + rebase_path(x64_out_dir),
112 "--library-path=" + rebase_path("${nacl_toolchain_tooldir}/lib"),
113 ]
114 data += [ "${lib_path}/lib64/" ]
115 }
116 }
117 }
118 args = [
119 "--no-default-libpath",
120 "--objdump=" + objdump,
121 "--output=" + rebase_path(nmf, root_build_dir),
122 ] + nmfflags + rebase_path(sources, root_build_dir)
123 if (is_nacl_glibc && current_cpu == "arm") {
124 deps += [ "//native_client/src/untrusted/elf_loader:elf_loader" ]
125 }
126 }
127}
128
129# Generate a nmf file for Non-SFI tests
130#
131# Non-SFI tests use a different manifest format from regular Native Client and
132# as such requires a different generator.
133#
134# Variables:
135# executable: Non-SFI .nexe executable to generate nmf for
136# nmf: the name and the path of the output file
137# nmfflags: additional flags for the nmf generator
138template("generate_nonsfi_test_nmf") {
139 assert(defined(invoker.executable), "Must define executable")
140 assert(defined(invoker.nmf), "Must define nmf")
141
142 action(target_name) {
143 forward_variables_from(invoker,
144 [
145 "deps",
146 "data_deps",
147 "executable",
148 "nmf",
149 "testonly",
150 "public_deps",
151 "visibility",
152 ])
153
154 script = "//ppapi/tests/create_nonsfi_test_nmf.py"
155 sources = [
156 executable,
157 ]
158 outputs = [
159 nmf,
160 ]
161
162 # NOTE: We use target_cpu rather than current_cpu on purpose because
163 # current_cpu is always going to be pnacl for Non-SFI, but the Non-SFI
164 # .nexe executable is always translated to run on the target machine.
165 if (target_cpu == "x86") {
166 arch = "x86-32"
167 } else if (target_cpu == "x64") {
168 arch = "x86-64"
169 } else {
170 arch = target_cpu
171 }
172 args = [
173 "--program=" + rebase_path(executable, root_build_dir),
174 "--arch=${arch}",
175 "--output=" + rebase_path(nmf, root_build_dir),
176 ]
177 if (defined(invoker.nmfflags)) {
178 args += invoker.nmfflags
179 }
180 }
181}