blob: b7be2138af27c1f80d01454903df8b0baa2a9721 [file] [log] [blame]
Benjamin Lerman2150a7b2014-11-14 21:49:31 +01001# Copyright 2014 The Chromium 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
Colin Blundell69666252015-02-13 09:38:24 +01005import("//build/module_args/mojo.gni")
Colin Blundellc2385772014-12-08 12:59:29 +01006import("mojo.gni")
7import("mojo_sdk.gni")
Dave Moored4fc01b2014-11-14 13:26:32 -08008
Benjamin Lerman2150a7b2014-11-14 21:49:31 +01009# Generate a binary mojo application.The parameters of this template are those
10# of a shared library.
11template("mojo_native_application") {
12 if (defined(invoker.output_name)) {
Nick Bray693385e2015-02-26 17:21:23 -080013 base_target_name = invoker.output_name
Benjamin Lerman2150a7b2014-11-14 21:49:31 +010014 } else {
Nick Bray693385e2015-02-26 17:21:23 -080015 base_target_name = target_name
Benjamin Lerman6ad67f52014-12-19 16:10:58 +010016 }
17
Nick Bray693385e2015-02-26 17:21:23 -080018 if (!is_nacl) {
Sean Klein92bd7792015-09-30 08:32:40 -070019 final_target_name = target_name
Nick Bray693385e2015-02-26 17:21:23 -080020 output = base_target_name + ".mojo"
21 library_target_name = base_target_name + "_library"
Benjamin Lermanf961e5e2015-07-16 11:43:38 +020022 copy_symbols_target = "__${final_target_name}_copy_symbols"
Nick Bray693385e2015-02-26 17:21:23 -080023
24 if (is_linux || is_android) {
25 library_name = "lib${library_target_name}.so"
26 } else if (is_win) {
27 library_name = "${library_target_name}.dll"
Chinmay Garde2899a6b2015-06-12 12:23:47 -070028 } else if (is_mac || is_ios) {
Nick Bray693385e2015-02-26 17:21:23 -080029 library_name = "lib${library_target_name}.dylib"
30 } else {
31 assert(false, "Platform not supported.")
Benjamin Lerman2150a7b2014-11-14 21:49:31 +010032 }
Colin Blundellc2385772014-12-08 12:59:29 +010033
Nick Bray693385e2015-02-26 17:21:23 -080034 if (is_android) {
35 # On android, use the stripped version of the library, because applications
36 # are always fetched over the network.
37 library_dir = "${root_out_dir}/lib.stripped"
38 } else {
39 library_dir = root_out_dir
Benjamin Lerman2150a7b2014-11-14 21:49:31 +010040 }
Colin Blundell69666252015-02-13 09:38:24 +010041
Nick Bray693385e2015-02-26 17:21:23 -080042 shared_library(library_target_name) {
Nick Bray693385e2015-02-26 17:21:23 -080043 data_deps = []
Sean Kleinf2f97ea2015-09-25 14:07:27 -070044 forward_variables_from(invoker,
45 [
46 "cflags",
47 "cflags_c",
48 "cflags_cc",
49 "cflags_objc",
50 "cflags_objcc",
51 "defines",
52 "include_dirs",
53 "ldflags",
54 "lib_dirs",
55 "libs",
56 "data_deps",
57 ])
Nick Bray693385e2015-02-26 17:21:23 -080058
59 # Copy any necessary prebuilt artifacts.
Scott Violet912f52f2015-03-26 07:30:24 -070060 if (mojo_use_prebuilt_mojo_shell) {
Nick Bray693385e2015-02-26 17:21:23 -080061 data_deps +=
62 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
63 }
Scott Violet912f52f2015-03-26 07:30:24 -070064 if (mojo_use_prebuilt_network_service) {
Nick Bray693385e2015-02-26 17:21:23 -080065 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
66 ".",
67 mojo_root) ]
68 }
69
Viet-Trung Luu1835f7e2015-12-11 10:09:00 -080070 deps =
71 rebase_path([ "mojo/public/platform/native:system" ], ".", mojo_root)
Nick Bray693385e2015-02-26 17:21:23 -080072 if (defined(invoker.deps)) {
73 deps += invoker.deps
74 }
Nick Bray693385e2015-02-26 17:21:23 -080075 if (defined(invoker.configs)) {
76 configs += invoker.configs
77 }
Sean Kleinf2f97ea2015-09-25 14:07:27 -070078 forward_variables_from(invoker,
79 [
Sean Kleinf2f97ea2015-09-25 14:07:27 -070080 "public_deps",
81 "all_dependent_configs",
82 "public_configs",
83 "check_includes",
84 "data",
85 "inputs",
86 "public",
87 "sources",
88 "testonly",
89 ])
Nick Bray693385e2015-02-26 17:21:23 -080090
Benjamin Lermanf961e5e2015-07-16 11:43:38 +020091 visibility = [
92 ":${final_target_name}",
93 ":${copy_symbols_target}",
94 ]
95 }
96
97 copy(copy_symbols_target) {
98 if (defined(invoker.testonly)) {
99 testonly = invoker.testonly
100 }
Nick Bray693385e2015-02-26 17:21:23 -0800101 visibility = [ ":${final_target_name}" ]
Benjamin Lermanf961e5e2015-07-16 11:43:38 +0200102 deps = [
103 ":${library_target_name}",
104 ]
105
106 sources = [
107 "${root_out_dir}/${library_name}",
108 ]
109 outputs = [
110 "${root_out_dir}/symbols/${library_name}",
111 ]
Colin Blundell69666252015-02-13 09:38:24 +0100112 }
113
Nick Bray693385e2015-02-26 17:21:23 -0800114 copy(final_target_name) {
Sean Kleinf2f97ea2015-09-25 14:07:27 -0700115 forward_variables_from(invoker,
116 [
117 "testonly",
118 "visibility",
119 ])
Etienne Membrives92d6f6e2015-09-01 10:03:19 +0200120
121 public_deps = [
122 # We want to allow rules to depend on symbol libraries.
123 ":${copy_symbols_target}",
124 ]
125
Nick Bray693385e2015-02-26 17:21:23 -0800126 deps = [
127 ":${library_target_name}",
128 ]
129
130 sources = [
131 "${library_dir}/${library_name}",
132 ]
133 outputs = [
134 "${root_out_dir}/${output}",
135 ]
Benjamin Lerman2150a7b2014-11-14 21:49:31 +0100136 }
Nick Bray693385e2015-02-26 17:21:23 -0800137 } else {
138 nexe_target_name = base_target_name + "_nexe"
Sean Klein92bd7792015-09-30 08:32:40 -0700139 executable_target_name = base_target_name + "_exe"
Nick Bray693385e2015-02-26 17:21:23 -0800140
141 executable(nexe_target_name) {
142 output_name = base_target_name
Nick Bray693385e2015-02-26 17:21:23 -0800143 data_deps = []
Sean Kleinf2f97ea2015-09-25 14:07:27 -0700144 forward_variables_from(invoker,
145 [
146 "cflags",
147 "cflags_c",
148 "cflags_cc",
149 "cflags_objc",
150 "cflags_objcc",
151 "defines",
152 "include_dirs",
153 "ldflags",
154 "lib_dirs",
155 "libs",
156 "data_deps",
157 ])
Nick Bray693385e2015-02-26 17:21:23 -0800158
159 # Copy any necessary prebuilt artifacts.
Scott Violet912f52f2015-03-26 07:30:24 -0700160 if (mojo_use_prebuilt_mojo_shell) {
Nick Bray693385e2015-02-26 17:21:23 -0800161 data_deps +=
162 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
163 }
Scott Violet912f52f2015-03-26 07:30:24 -0700164 if (mojo_use_prebuilt_network_service) {
Nick Bray693385e2015-02-26 17:21:23 -0800165 data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
166 ".",
167 mojo_root) ]
168 }
169
170 deps = rebase_path([
171 "mojo/public/c/system",
172 "mojo/public/platform/nacl:system",
173 ],
174 ".",
175 mojo_root)
176 if (defined(invoker.deps)) {
177 deps += invoker.deps
178 }
Nick Bray693385e2015-02-26 17:21:23 -0800179 if (defined(invoker.configs)) {
180 configs += invoker.configs
181 }
Sean Kleinf2f97ea2015-09-25 14:07:27 -0700182
183 forward_variables_from(invoker,
184 [
185 "forward_dependent_configs_from",
186 "public_deps",
187 "all_dependent_configs",
188 "public_configs",
189 "check_includes",
190 "data",
191 "inputs",
192 "public",
193 "sources",
194 "testonly",
195 ])
Nick Bray693385e2015-02-26 17:21:23 -0800196
Sean Klein92bd7792015-09-30 08:32:40 -0700197 visibility = [ ":*" ]
Benjamin Lerman2150a7b2014-11-14 21:49:31 +0100198 }
199
Sean Klein92bd7792015-09-30 08:32:40 -0700200 group(target_name) {
201 # This group specifies two targets: first, it requests that the
202 # pexe be built, and secondly (if the toolchain is not requesting
203 # a pexe implicitly), it creates a nexe.
204 forward_variables_from(invoker, [ "testonly" ])
205 deps = [
206 ":${executable_target_name}(//build/toolchain/nacl:newlib_pnacl)",
207 ]
208 if (current_cpu != "pnacl") {
209 deps += [ ":${executable_target_name}" ]
210 }
211 }
212
213 action(executable_target_name) {
214 if (current_cpu == "pnacl") {
Sean Klein8f6e6792015-09-30 10:17:26 -0700215 input_file_extension = ".pexe"
216 output_file_extension = ".pexe.mojo"
Sean Klein2ba2b8d2015-10-28 16:38:09 -0700217 content_handler = "content_handler_nonsfi_pexe"
Sean Klein92bd7792015-09-30 08:32:40 -0700218 } else {
Sean Klein8f6e6792015-09-30 10:17:26 -0700219 input_file_extension = ".nexe"
220 output_file_extension = "_${target_cpu}.nexe.mojo"
Sean Klein63243fa2015-11-30 10:39:56 -0800221 content_handler = "content_handler_sfi_nexe"
Sean Klein92bd7792015-09-30 08:32:40 -0700222 }
Sean Klein8f6e6792015-09-30 10:17:26 -0700223 input_file = "${base_target_name}${input_file_extension}"
224 output_file = "${base_target_name}${output_file_extension}"
Sean Klein92bd7792015-09-30 08:32:40 -0700225
Sean Kleinf2f97ea2015-09-25 14:07:27 -0700226 forward_variables_from(invoker,
227 [
228 "testonly",
229 "visibility",
230 ])
Nick Bray158769a2015-02-27 16:48:41 -0800231
Nick Bray693385e2015-02-26 17:21:23 -0800232 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
Benjamin Lerman2150a7b2014-11-14 21:49:31 +0100233
Sean Klein8f6e6792015-09-30 10:17:26 -0700234 input_path = "${root_out_dir}/${input_file}"
Nick Bray693385e2015-02-26 17:21:23 -0800235 inputs = [
236 input_path,
237 ]
Benjamin Lerman6ad67f52014-12-19 16:10:58 +0100238
Sean Klein92bd7792015-09-30 08:32:40 -0700239 output_path = "${root_build_dir}/${output_file}"
Nick Bray693385e2015-02-26 17:21:23 -0800240 outputs = [
241 output_path,
242 ]
243
244 deps = [
245 ":${nexe_target_name}",
246 ]
247
248 rebase_input = rebase_path(input_path, root_build_dir)
249 rebase_output = rebase_path(output_path, root_build_dir)
250 args = [
251 "--input=$rebase_input",
252 "--output=$rebase_output",
Sean Klein92bd7792015-09-30 08:32:40 -0700253 "--line=#!mojo mojo:$content_handler",
Nick Bray693385e2015-02-26 17:21:23 -0800254 ]
255 }
Benjamin Lerman2150a7b2014-11-14 21:49:31 +0100256 }
257}
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100258
259if (is_android) {
Benjamin Lerman5227b632015-07-16 18:00:37 +0200260 import("//build/config/android/rules.gni")
261
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100262 # Declares an Android Mojo application consisting of an .so file and a
263 # corresponding .dex.jar file.
264 #
265 # Variables:
Benjamin Lerman5227b632015-07-16 18:00:37 +0200266 # sources (optional): The c++ sources.
267 # deps (optional): The c++ dependencies.
268 # java_sources (optional): The java sources.
269 # java_deps (optional): The java dependencies.
270 # jni_package (optional): The c++ package for the generated jni headers.
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100271 # output_name (optional): override for the output file name
Benjamin Lerman5227b632015-07-16 18:00:37 +0200272 # public_deps / data_deps (optional): Dependencies.
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100273 template("mojo_android_application") {
Benjamin Lerman5227b632015-07-16 18:00:37 +0200274 shared_library_name = "__${target_name}_lib"
275 library_basename = "lib${shared_library_name}.so"
276 if (defined(invoker.jni_package)) {
277 assert(defined(invoker.java_sources))
278 generate_jni_name = "__${target_name}_jni"
279 }
280 if (defined(invoker.java_sources)) {
281 java_library_name = "__${target_name}_java"
282 }
283 android_standalone_library_name = "__${target_name}_java_lib"
284 dex_output_path = "${target_gen_dir}/${target_name}.dex.jar"
285 zip_action_name = "__${target_name}_zip"
286 zip_action_output = "${target_gen_dir}/${target_name}.zip"
287 copy_symbols_target = "__${target_name}_copy_symbols"
288 final_target_name = target_name
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100289
Benjamin Lerman5227b632015-07-16 18:00:37 +0200290 if (defined(invoker.jni_package)) {
291 generate_jni(generate_jni_name) {
292 visibility = [ ":${shared_library_name}" ]
293
294 sources = invoker.java_sources
295 jni_package = invoker.jni_package
296 }
297 }
298
299 shared_library(shared_library_name) {
300 visibility = [
301 ":${copy_symbols_target}",
302 ":${zip_action_name}",
303 ]
304
305 if (defined(invoker.sources)) {
306 sources = invoker.sources
307 }
308
Viet-Trung Luu1835f7e2015-12-11 10:09:00 -0800309 deps =
310 rebase_path([ "mojo/public/platform/native:system" ], ".", mojo_root)
Benjamin Lerman5227b632015-07-16 18:00:37 +0200311 if (defined(invoker.jni_package)) {
312 deps += [ ":${generate_jni_name}" ]
313 }
314 if (defined(invoker.deps)) {
315 deps += invoker.deps
316 }
317 }
318
319 copy(copy_symbols_target) {
320 visibility = [ ":${final_target_name}" ]
321 deps = [
322 ":${shared_library_name}",
323 ]
324
325 sources = [
326 "${root_out_dir}/${library_basename}",
327 ]
328 outputs = [
329 "${root_out_dir}/symbols/${library_basename}",
330 ]
331 }
332
333 if (defined(invoker.java_sources)) {
334 android_library(java_library_name) {
335 visibility = [ ":*" ]
336
337 java_files = invoker.java_sources
338
339 if (defined(invoker.java_deps)) {
340 deps = invoker.java_deps
341 }
342 }
343 }
344
345 android_standalone_library(android_standalone_library_name) {
346 deps = []
347
348 if (defined(invoker.java_sources)) {
349 deps += [ ":${java_library_name}" ]
350 }
351
352 if (defined(invoker.java_deps)) {
353 deps += invoker.java_deps
354 }
355
356 dex_path = dex_output_path
357 }
358
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100359 action(zip_action_name) {
Benjamin Lerman5227b632015-07-16 18:00:37 +0200360 visibility = [ ":${final_target_name}" ]
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100361 script = "//build/android/gn/zip.py"
362
363 inputs = [
Benjamin Lerman5227b632015-07-16 18:00:37 +0200364 "${root_out_dir}/lib.stripped/${library_basename}",
365 dex_output_path,
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100366 ]
367
368 output = zip_action_output
James Robinson3bfa8fd2014-12-10 13:56:25 -0800369 outputs = [
370 output,
371 ]
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100372
373 rebase_inputs = rebase_path(inputs, root_build_dir)
374 rebase_output = rebase_path(output, root_build_dir)
375 args = [
Benjamin Lerman5227b632015-07-16 18:00:37 +0200376 "--inputs=${rebase_inputs}",
377 "--output=${rebase_output}",
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100378 ]
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700379
Craig Stout677be222015-08-04 15:15:18 -0700380 deps = [
381 ":${android_standalone_library_name}",
382 ":${shared_library_name}",
383 ]
384
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700385 if (defined(invoker.deps)) {
Craig Stout677be222015-08-04 15:15:18 -0700386 deps += invoker.deps
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700387 }
388 if (defined(invoker.public_deps)) {
389 public_deps = invoker.public_deps
390 }
391 if (defined(invoker.data_deps)) {
392 data_deps = invoker.data_deps
393 }
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100394 }
395
396 if (defined(invoker.output_name)) {
Benjamin Lerman5227b632015-07-16 18:00:37 +0200397 mojo_output = "${root_out_dir}/" + invoker.output_name + ".mojo"
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100398 } else {
Benjamin Lerman5227b632015-07-16 18:00:37 +0200399 mojo_output = "${root_out_dir}/" + target_name + ".mojo"
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100400 }
401
Benjamin Lerman5227b632015-07-16 18:00:37 +0200402 action(final_target_name) {
Colin Blundellc2385772014-12-08 12:59:29 +0100403 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100404
405 input = zip_action_output
James Robinson3bfa8fd2014-12-10 13:56:25 -0800406 inputs = [
407 input,
408 ]
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100409
410 output = mojo_output
James Robinson3bfa8fd2014-12-10 13:56:25 -0800411 outputs = [
412 output,
413 ]
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100414
415 rebase_input = rebase_path(input, root_build_dir)
416 rebase_output = rebase_path(output, root_build_dir)
417 args = [
Benjamin Lerman5227b632015-07-16 18:00:37 +0200418 "--input=${rebase_input}",
419 "--output=${rebase_output}",
Scott Violet05833db2015-01-08 10:19:52 -0800420 "--line=#!mojo mojo:android_handler",
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100421 ]
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700422
Benjamin Lerman5227b632015-07-16 18:00:37 +0200423 deps = [
424 ":${copy_symbols_target}",
425 ]
426
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700427 public_deps = [
Benjamin Lerman5227b632015-07-16 18:00:37 +0200428 ":${zip_action_name}",
Brett Wilson55ddc6a2015-05-28 15:54:28 -0700429 ]
Przemyslaw Pietrzkiewicz9eedc902014-11-27 15:59:08 +0100430 }
431 }
432}