blob: bbcdc1aa70f943c2ae045402781acb242ecfa963 [file] [log] [blame]
Avi Drissmandb497b32022-09-15 19:47:281# Copyright 2015 The Chromium Authors
phosekb4606252015-12-15 23:00:352# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Dirk Prankeccc0c362017-09-28 22:15:115import("//build/config/nacl/config.gni")
phosekb4606252015-12-15 23:00:356import("//build/config/nacl/rules.gni")
Dirk Prankeccc0c362017-09-28 22:15:117import("//components/nacl/features.gni")
Mark Seabornc4d61122022-03-25 01:32:258import("//components/nacl/target_cpu.gni")
phosekb4606252015-12-15 23:00:359
10assert(enable_nacl)
11
12if (current_cpu == "pnacl") {
Nico Weber7c271e92021-11-30 04:21:0913 nacl_toolchain_variant = "pnacl"
phosekb4606252015-12-15 23:00:3514} else if (is_nacl_glibc) {
15 nacl_toolchain_variant = "glibc"
Daniel Cheng073353a12023-06-08 17:52:0116} else if (is_nacl_saigo) {
17 nacl_toolchain_variant = "test_irt"
phosekb4606252015-12-15 23:00:3518} else {
19 nacl_toolchain_variant = "newlib"
20}
21
22# Assemble data for Native Client based test
23#
24# Build a Native Client based test, including any additional support files
25# and copy them over to a toolchain-specific target directory.
26#
27# Variables:
28# output_name: name of the ouput file other than the default
29# sources: source files for a target
30# generate_nmf: whether to generate a manifest (default true)
phoseke19dffc2016-05-09 07:03:4931# pretranslate_pexe: whether to pre-translate pexe to nexe during build
phoseke19dffc2016-05-09 07:03:4932# nonstable_pexe: use non-finalized pexe (default false)
33# debug_pexe: copy both non-finalized and finalized pexe (default false)
34# destination_dir: the output directory relative to the $root_build_dir,
35# if ommitted the output directory is $root_build_dir and the manifest
36# will be suffixed with the name of the toolchain (optional)
37# test_files: additional test files to copy to $destination_dir (optional)
38# nmfflags: additional flags for the nmf generator (optional)
phosekb4606252015-12-15 23:00:3539template("nacl_test_data") {
40 assert(defined(invoker.sources))
phosekb4606252015-12-15 23:00:3541 forward_variables_from(invoker, [ "destination_dir" ])
42
43 if (defined(invoker.output_name)) {
44 output_name = invoker.output_name
45 } else {
46 output_name = target_name
47 }
48
49 if (current_cpu == "x64") {
50 nmf_cpu = "x86_64"
51 } else if (current_cpu == "x86") {
52 nmf_cpu = "x86_32"
53 } else {
54 nmf_cpu = current_cpu
55 }
mcgrathra03f1192016-05-13 02:22:4856
Hidehiko Abe0f701242022-01-19 02:57:5757 if (current_cpu == "pnacl" && defined(invoker.pretranslate_pexe)) {
58 pretranslate_pexe = invoker.pretranslate_pexe
mcgrathra03f1192016-05-13 02:22:4859 } else {
60 pretranslate_pexe = false
61 }
62
63 # Note this can't test "is_win" because it's evaluated in the NaCl
64 # toolchain context where is_win==false because current_os=="nacl".
65 # It tests target_cpu rather than current_cpu because it's also
66 # needed in the current_cpu=="pnacl" && pretranslate_pexe case.
Nico Weber7c271e92021-11-30 04:21:0967 if (target_os == "win" && target_cpu == "x86" &&
mcgrathra03f1192016-05-13 02:22:4868 (current_cpu == "x86" || pretranslate_pexe)) {
69 # x86 Windows builds of Chrome run on both x86 Windows and x64
70 # Windows. On x64 Windows, only x64 NaCl is supported, so those
71 # tests are needed too.
72 extra_tc_cpu = "x64"
73 if (current_cpu == "x86") {
74 extra_nmf_cpu = "x86_64"
phoseke19dffc2016-05-09 07:03:4975 }
76 }
mcgrathra03f1192016-05-13 02:22:4877
78 if (is_nacl_glibc) {
79 suffix = "glibc_${nmf_cpu}"
80 if (defined(extra_nmf_cpu)) {
81 extra_suffix = "glibc_${extra_nmf_cpu}"
82 glibc_tc = "//build/toolchain/nacl:glibc"
83 assert(current_toolchain == "${glibc_tc}_${current_cpu}")
84 extra_toolchain = "${glibc_tc}_${extra_tc_cpu}"
85 }
86 } else {
87 suffix = "newlib_${nmf_cpu}"
88 if (defined(extra_nmf_cpu)) {
89 extra_suffix = "newlib_${extra_nmf_cpu}"
90 newlib_tc = "//build/toolchain/nacl:clang_newlib"
Daniel Cheng073353a12023-06-08 17:52:0191 if (is_nacl_saigo) {
92 newlib_tc = "//build/toolchain/nacl:test_irt"
93 }
mcgrathra03f1192016-05-13 02:22:4894 assert(current_toolchain == "${newlib_tc}_${current_cpu}")
95 extra_toolchain = "${newlib_tc}_${extra_tc_cpu}"
96 }
97 }
98 suffixed_output_name = "${output_name}_${suffix}"
99 if (defined(extra_nmf_cpu)) {
100 extra_suffixed_output_name = "${output_name}_${extra_suffix}"
101 }
102 if (pretranslate_pexe) {
103 pexe_translate_target_name = target_name + "_translate_pexe_"
104 if (defined(extra_tc_cpu)) {
105 # There will be an extra pretranslation done below for the
106 # extra CPU (i.e. for x64 on x86 Windows).
107 extra_pexe_translate_target_name =
108 pexe_translate_target_name + extra_tc_cpu
109 }
Mark Seabornc4d61122022-03-25 01:32:25110 pexe_translate_target_name += nacl_target_cpu
mcgrathra03f1192016-05-13 02:22:48111 }
phosekb4606252015-12-15 23:00:35112 if (defined(invoker.generate_nmf)) {
113 generate_nmf = invoker.generate_nmf
114 } else {
115 generate_nmf = true
116 }
117 nexe_target_name = target_name + "_nexe"
phosekb4606252015-12-15 23:00:35118 nexe_copy_target_name = target_name + "_copy_nexe"
Nico Weber7c271e92021-11-30 04:21:09119 if (current_cpu == "pnacl") {
phosekb4606252015-12-15 23:00:35120 if (defined(invoker.debug_pexe) && invoker.debug_pexe) {
121 pexe_copy_debug_target_name = target_name + "_copy_pexe_debug"
122 }
123 }
124 if (generate_nmf) {
125 nmf_target_name = target_name + "_nmf"
126 }
127 if (defined(invoker.test_files)) {
128 test_files_target_name = target_name + "_test_files"
129 }
130 final_target_name = target_name
131
phoseke19dffc2016-05-09 07:03:49132 # When the destination_dir is specified, the build artifacts end up
133 # in the that directory and the manifest is the same as the target name.
134 # When the destination_dir is not specified, the artifacts end up
135 # in the root build directory and the manifests are suffixed to ensure
136 # they do not overlap in case when we build the same test using multiple
137 # different toolchains.
138 if (defined(invoker.destination_dir)) {
139 target_dir =
140 "${root_build_dir}/${destination_dir}/${nacl_toolchain_variant}"
141 if (generate_nmf) {
142 nmf_name = output_name
143 }
144 } else {
145 target_dir = root_build_dir
146 if (generate_nmf) {
Nico Weber7c271e92021-11-30 04:21:09147 nacl_toolchain_name = nacl_toolchain_variant
phoseke19dffc2016-05-09 07:03:49148 nmf_name = "${output_name}_${nacl_toolchain_name}"
149 }
150 }
151
phosekb4606252015-12-15 23:00:35152 executable(nexe_target_name) {
153 visibility = [ ":*" ]
154 output_name = suffixed_output_name
155 sources = invoker.sources
156 forward_variables_from(invoker,
157 [
Nico Weber287adb22021-11-25 03:34:16158 "assert_no_deps",
phosekb4606252015-12-15 23:00:35159 "cflags",
phoseke19dffc2016-05-09 07:03:49160 "defines",
161 "include_dirs",
phosekb4606252015-12-15 23:00:35162 "ldflags",
163 "libs",
164 ])
165 deps = [
phosekd07c7712016-01-14 23:22:51166 "//build/config/nacl:nacl_base",
Clark DuVall5446e672020-11-14 01:56:55167 "//ppapi/c",
phosekb4606252015-12-15 23:00:35168 "//ppapi/native_client:ppapi_lib",
169 ]
phosekb4606252015-12-15 23:00:35170 ldflags = [ "-pthread" ]
171 if (defined(invoker.deps)) {
172 deps += invoker.deps
173 }
174 }
175
phoseke19dffc2016-05-09 07:03:49176 if (current_cpu == "pnacl" && pretranslate_pexe) {
mcgrathra03f1192016-05-13 02:22:48177 # This is a template so it can be invoked twice in the
178 # defined(extra_tc_cpu) case below.
179 template("nacl_test_data_pretranslate_pexe") {
Fabian Sommer3b46bc72021-07-15 16:59:58180 action(target_name) {
mcgrathra03f1192016-05-13 02:22:48181 translate_cpu = invoker.translate_cpu
phosekb4606252015-12-15 23:00:35182
mcgrathra03f1192016-05-13 02:22:48183 visibility = [ ":$nexe_copy_target_name" ]
phosekb4606252015-12-15 23:00:35184
mcgrathra03f1192016-05-13 02:22:48185 # We specify the toolchain explicitly because in the Non-SFI case, we
186 # still want to use the pexe built using the newlib_pnacl toolchain.
187 tests = ":ppapi_nacl_tests_nexe(//build/toolchain/nacl:newlib_pnacl)"
phosekb4606252015-12-15 23:00:35188
mcgrathra03f1192016-05-13 02:22:48189 pexe = get_label_info(tests, "root_out_dir") +
190 "/${suffixed_output_name}.pexe"
Nico Weber7c271e92021-11-30 04:21:09191 if (translate_cpu == "x86") {
mcgrathra03f1192016-05-13 02:22:48192 nmf_cpu = "x32"
193 } else {
194 nmf_cpu = translate_cpu
phoseke19dffc2016-05-09 07:03:49195 }
Nico Weber7c271e92021-11-30 04:21:09196 suffix = "pnacl_newlib_${nmf_cpu}"
mcgrathra03f1192016-05-13 02:22:48197 nexe = "${root_out_dir}/${output_name}_${suffix}.nexe"
phosekb4606252015-12-15 23:00:35198
mcgrathra03f1192016-05-13 02:22:48199 script = "${nacl_toolchain_bindir}/pydir/loader.py"
Nico Weber9efa6232020-01-13 19:08:51200 sources = [ pexe ]
201 outputs = [ nexe ]
phosekb4606252015-12-15 23:00:35202
Nico Weber7c271e92021-11-30 04:21:09203 # TODO(phosek): remove the following once change 1360243003 is rolled
204 # into Chrome and use translate_cpu directly.
205 if (translate_cpu == "x86") {
206 arch = "i686"
207 } else if (translate_cpu == "x64") {
208 arch = "x86-64"
209 } else if (translate_cpu == "arm") {
210 arch = "armv7"
211 } else if (translate_cpu == "mipsel") {
212 arch = "mipsel"
mcgrathra03f1192016-05-13 02:22:48213 }
214
215 # The pre-translated object file has to be linked with an IRT shim to
216 # get a runnable nexe. This is handled by pnacl-translate, which passes
217 # -l:libpnacl_irt_shim.a to native linker, and we need to ensure the
218 # linker can find the correct library.
Nico Weber7c271e92021-11-30 04:21:09219 pnacl_irt_shim = "//ppapi/native_client/src/untrusted/pnacl_irt_shim:aot(//build/toolchain/nacl:clang_newlib_${translate_cpu})"
mcgrathra03f1192016-05-13 02:22:48220
221 args = [
222 "pnacl-translate",
223 rebase_path(pexe, root_build_dir),
224 "-o",
225 rebase_path(nexe, root_build_dir),
226 "-arch",
227 arch,
228 "-Wl,-L" +
wychen5e1f7252017-05-30 08:05:10229 rebase_path(get_label_info(pnacl_irt_shim, "target_out_dir"),
230 root_build_dir),
mcgrathra03f1192016-05-13 02:22:48231 ]
Nico Weber9efa6232020-01-13 19:08:51232 deps = [ ":$nexe_target_name(//build/toolchain/nacl:newlib_pnacl)" ]
233 data_deps = [ pnacl_irt_shim ]
mcgrathra03f1192016-05-13 02:22:48234 }
235 }
236
237 nacl_test_data_pretranslate_pexe(pexe_translate_target_name) {
Mark Seabornc4d61122022-03-25 01:32:25238 translate_cpu = nacl_target_cpu
mcgrathra03f1192016-05-13 02:22:48239 }
240 if (defined(extra_tc_cpu)) {
241 nacl_test_data_pretranslate_pexe(extra_pexe_translate_target_name) {
242 translate_cpu = extra_tc_cpu
243 }
phosekb4606252015-12-15 23:00:35244 }
245 }
246
247 copy(nexe_copy_target_name) {
248 visibility = [ ":$final_target_name" ]
249 if (generate_nmf) {
250 visibility += [ ":$nmf_target_name" ]
251 }
phoseke19dffc2016-05-09 07:03:49252 if (current_cpu == "pnacl") {
253 if (pretranslate_pexe) {
254 sources = get_target_outputs(":${pexe_translate_target_name}")
mcgrathra03f1192016-05-13 02:22:48255 if (defined(extra_tc_cpu)) {
256 sources += get_target_outputs(":${extra_pexe_translate_target_name}")
257 }
phoseke19dffc2016-05-09 07:03:49258 } else if (defined(invoker.nonstable_pexe) && invoker.nonstable_pexe) {
Nico Weber9efa6232020-01-13 19:08:51259 sources =
260 [ "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe" ]
phosekb4606252015-12-15 23:00:35261 } else {
Nico Weber9efa6232020-01-13 19:08:51262 sources = [ "${root_out_dir}/${suffixed_output_name}.pexe" ]
phosekb4606252015-12-15 23:00:35263 }
phosekb4606252015-12-15 23:00:35264 } else {
Nico Weber9efa6232020-01-13 19:08:51265 sources = [ "${root_out_dir}/${suffixed_output_name}.nexe" ]
mcgrathra03f1192016-05-13 02:22:48266 if (defined(extra_nmf_cpu)) {
267 extra_root_out_dir =
268 get_label_info(":${nexe_target_name}(${extra_toolchain})",
269 "root_out_dir")
270 sources +=
271 [ "${extra_root_out_dir}/${extra_suffixed_output_name}.nexe" ]
272 }
phosekb4606252015-12-15 23:00:35273 }
Nico Weber9efa6232020-01-13 19:08:51274 outputs = [ "${target_dir}/{{source_file_part}}" ]
phoseke19dffc2016-05-09 07:03:49275 if (current_cpu == "pnacl" && pretranslate_pexe) {
Nico Weber9efa6232020-01-13 19:08:51276 deps = [ ":$pexe_translate_target_name" ]
mcgrathra03f1192016-05-13 02:22:48277 if (defined(extra_tc_cpu)) {
278 deps += [ ":$extra_pexe_translate_target_name" ]
279 }
phosekb4606252015-12-15 23:00:35280 } else {
Nico Weber9efa6232020-01-13 19:08:51281 deps = [ ":$nexe_target_name" ]
mcgrathra03f1192016-05-13 02:22:48282 if (defined(extra_nmf_cpu)) {
283 deps += [ ":${nexe_target_name}(${extra_toolchain})" ]
284 }
phosekb4606252015-12-15 23:00:35285 }
286 }
287
Nico Weber7c271e92021-11-30 04:21:09288 if (current_cpu == "pnacl") {
phosekb4606252015-12-15 23:00:35289 if (defined(invoker.debug_pexe) && invoker.debug_pexe) {
290 copy(pexe_copy_debug_target_name) {
291 visibility = [ ":$final_target_name" ]
Nico Weber9efa6232020-01-13 19:08:51292 sources =
293 [ "${root_out_dir}/exe.unstripped/${suffixed_output_name}.pexe" ]
294 outputs = [ "${target_dir}/{{source_name_part}}.pexe.debug" ]
295 deps = [ ":$nexe_target_name" ]
phosekb4606252015-12-15 23:00:35296 }
297 }
298 }
299
300 if (generate_nmf) {
Nico Weber7c271e92021-11-30 04:21:09301 generate_nmf(nmf_target_name) {
302 visibility = [ ":$final_target_name" ]
303 forward_variables_from(invoker, [ "nmfflags" ])
304 nmf = "${target_dir}/${nmf_name}.nmf"
305 executables = get_target_outputs(":$nexe_copy_target_name")
306 if (is_nacl_glibc) {
307 lib_prefix = "${output_name}_libs"
308 stage_dependencies = target_dir
phosekb4606252015-12-15 23:00:35309 }
Nico Weber7c271e92021-11-30 04:21:09310 deps = [ ":$nexe_copy_target_name" ]
phosekb4606252015-12-15 23:00:35311 }
312 }
313
314 if (defined(invoker.test_files)) {
315 copy(test_files_target_name) {
316 visibility = [ ":$final_target_name" ]
317 sources = invoker.test_files
Nico Weber9efa6232020-01-13 19:08:51318 outputs = [ "${target_dir}/{{source_file_part}}" ]
phosekb4606252015-12-15 23:00:35319 }
320 }
321
322 group(final_target_name) {
Nico Weber9efa6232020-01-13 19:08:51323 data_deps = [ ":$nexe_copy_target_name" ]
Nico Weber7c271e92021-11-30 04:21:09324 if (current_cpu == "pnacl") {
phosekb4606252015-12-15 23:00:35325 if (defined(invoker.debug_pexe) && invoker.debug_pexe) {
326 data_deps += [ ":$pexe_copy_debug_target_name" ]
327 }
328 }
329 if (generate_nmf) {
330 data_deps += [ ":$nmf_target_name" ]
331 }
332 if (defined(invoker.test_files)) {
333 data_deps += [ ":$test_files_target_name" ]
334 }
335 }
336}