blob: 472583b0f136a72bd25bbb07f47a3b8466498cd7 [file] [log] [blame]
Christopher Grant5f0c1382018-12-04 18:48:221# Copyright 2018 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
5import("//base/android/linker/config.gni")
6import("//build/config/android/config.gni")
7import("//build/config/android/linker_version_script.gni")
8import("//build/config/compiler/compiler.gni")
Christopher Grant2b9c9512019-05-21 16:02:389import("//build/partitioned_shared_library.gni")
Tibor Goldschwendtaef8e392019-07-19 16:39:1010import("//chrome/android/modules/buildflags.gni")
Christopher Grant5f0c1382018-12-04 18:48:2211import("//device/vr/buildflags/buildflags.gni")
12
Christopher Grantb1f70c52019-06-04 22:37:1813# TODO(cjgrant): Remove these variables once downstream stops using them.
14bundle_library_suffix = ""
Christopher Grant133ae77d2019-06-07 15:17:4815apk_pak_asset_type = "_apk"
Christopher Grant5f09fb9b2018-12-05 20:15:1416
Christopher Grant5f0c1382018-12-04 18:48:2217# This template contains all common configuration for native shared libraries,
18# including libchrome, monochrome, standalone webview (also called monochrome),
19# and libchromefortest (used by chrome_public_test_apk).
20#
21# Variables:
Christopher Grant5f0c1382018-12-04 18:48:2222# is_monochrome: Optional. If set, the library is for use in monochrome.
23# is_webview: If true, the library is for webview, and browser-specific
24# config is skipped.
Tibor Goldschwendtb05a8882019-10-29 15:12:0825# module_descs: Optional. Descriptors of feature modules for which library
26# targets should be auto-generated. The targets are called
27# "${target_name}_<module name>" and can be depended on like shared_library
28# targets. If enabled, the library targets create partitions containing the
29# module's native code. Otherwise, they simply depend on the module's
30# native_deps. See //chrome/android/modules/chrome_feature_modules.gni for
31# the descriptor format.
Christopher Grant5f0c1382018-12-04 18:48:2232template("chrome_common_shared_library") {
33 _is_monochrome = defined(invoker.is_monochrome) && invoker.is_monochrome
34 _is_webview = defined(invoker.is_webview) && invoker.is_webview
35 _export_java_symbols = _is_monochrome || _is_webview
Andrew Grieve71bd025e2020-06-25 05:23:1836 _collect_inputs_only =
37 defined(invoker.collect_inputs_only) && invoker.collect_inputs_only
Christopher Grant5f0c1382018-12-04 18:48:2238
Andrew Grievebb0c9ca2020-06-25 22:27:0839 # When _collect_inputs_only && !(!_is_webview && enable_vr).
Clark DuVall2c433852020-09-17 05:46:4440 not_needed([ "_export_java_symbols" ])
41
Christopher Grant883056b32019-06-17 18:48:0342 # Create a partitioned libraries if the build config supports it, and the
Christopher Grant48705d72019-10-07 21:22:5343 # invoker has supplied module descriptors.
Clark DuVall003524e2020-09-18 02:38:3444 _generate_partitions = defined(invoker.module_descs) &&
Andrew Grieve71bd025e2020-06-25 05:23:1845 use_native_partitions && !_collect_inputs_only
Tibor Goldschwendtb05a8882019-10-29 15:12:0846 _module_descs = []
Christopher Grant48705d72019-10-07 21:22:5347 if (defined(invoker.module_descs)) {
Tibor Goldschwendtb05a8882019-10-29 15:12:0848 _module_descs = invoker.module_descs
Tibor Goldschwendtaef8e392019-07-19 16:39:1049 }
Christopher Grant883056b32019-06-17 18:48:0350
Andrew Grieve71bd025e2020-06-25 05:23:1851 if (!_collect_inputs_only) {
52 _linker_script_target = "${target_name}_linker_script"
53 _linker_script = "$target_gen_dir/${target_name}_linker_script.txt"
54
55 # Create a custom linker script based on JNI and feature module requirements.
56 generate_linker_version_script(_linker_script_target) {
57 linker_script = _linker_script
58 export_java_symbols = _export_java_symbols
59 export_feature_registrations = true
60 if (_generate_partitions) {
61 export_symbol_allowlist_files = []
62 foreach(_module_desc, invoker.module_descs) {
63 if (defined(_module_desc.native_entrypoints)) {
64 export_symbol_allowlist_files += [ _module_desc.native_entrypoints ]
65 }
Tibor Goldschwendtaef8e392019-07-19 16:39:1066 }
67 }
Christopher Grant5f0c1382018-12-04 18:48:2268 }
69 }
70
Christopher Grant883056b32019-06-17 18:48:0371 if (_generate_partitions) {
Christopher Grant2b9c9512019-05-21 16:02:3872 _target_type = "partitioned_shared_library"
73 } else {
74 _target_type = "shared_library"
75 }
76
77 target(_target_type, target_name) {
78 forward_variables_from(invoker, "*")
79
Christopher Grant5f0c1382018-12-04 18:48:2280 if (!_is_webview) {
81 deps += [ "//chrome:chrome_android_core" ]
82 }
83
Tiancong Wang5abb47752019-07-10 19:18:4784 configs += [ "//build/config/compiler:chrome_orderfile_config" ]
Christopher Grant5f0c1382018-12-04 18:48:2285
86 # Use a dynamically-generated linker script.
87 configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
Christopher Grant5f0c1382018-12-04 18:48:2288 if (!defined(ldflags)) {
89 ldflags = []
90 }
Andrew Grieve71bd025e2020-06-25 05:23:1891 if (_collect_inputs_only) {
92 metadata = {
93 }
94 ldflags += [ "--collect-inputs-only" ]
95 } else {
96 deps += [ ":$_linker_script_target" ]
97 inputs = [ "$_linker_script" ]
98 ldflags += [ "-Wl,--version-script=" +
99 rebase_path(_linker_script, root_build_dir) ]
100 }
Christopher Grant5f0c1382018-12-04 18:48:22101
Christopher Grant2b9c9512019-05-21 16:02:38102 # Handle VR JNI registration and dependencies.
Christopher Grant5f0c1382018-12-04 18:48:22103 if (!_is_webview && enable_vr) {
104 if (_export_java_symbols) {
Tibor Goldschwendtaef8e392019-07-19 16:39:10105 # NOTE: While this file is named *_monochrome.cc, it just contains an
106 # empty vr::RegisterJni() function that returns true.
Christopher Grant5f0c1382018-12-04 18:48:22107 sources += [ "../browser/android/vr/register_jni_monochrome.cc" ]
108 } else {
109 sources += [ "../browser/android/vr/register_jni.cc" ]
110 deps += [
111 "//chrome/browser/android/vr:jni_registration($default_toolchain)",
112 ]
113 }
114 }
115
Tibor Goldschwendtb05a8882019-10-29 15:12:08116 if (_generate_partitions) {
Tibor Goldschwendtaef8e392019-07-19 16:39:10117 partitions = []
Tibor Goldschwendtb05a8882019-10-29 15:12:08118 foreach(_module_desc, _module_descs) {
Tibor Goldschwendtaef8e392019-07-19 16:39:10119 if (defined(_module_desc.native_deps)) {
120 partitions += [ _module_desc.name ]
121 deps += _module_desc.native_deps
122 }
123 }
Clark DuVall003524e2020-09-18 02:38:34124 } else if (_collect_inputs_only) {
Andrew Grieve71bd025e2020-06-25 05:23:18125 foreach(_module_desc, _module_descs) {
126 if (defined(_module_desc.native_deps)) {
127 deps += _module_desc.native_deps
128 }
129 }
Christopher Grant2b9c9512019-05-21 16:02:38130 }
131
Christopher Grant5f0c1382018-12-04 18:48:22132 # Compress relocations if needed.
Sam Maier0aae7862019-02-04 20:44:32133 if ((_is_monochrome || _is_webview || chromium_linker_supported) &&
134 use_lld) {
135 configs += [ "//build/config/android:lld_pack_relocations" ]
Christopher Grant5f0c1382018-12-04 18:48:22136 }
137
138 if ((_is_monochrome || _is_webview || chromium_linker_supported) &&
139 target_cpu != "mipsel" && target_cpu != "mips64el") {
140 # By default, the static linker will create ELF executables with both
141 # SysV and GNU hash tables. Now that the chromium linker supports the GNU
142 # format, which is considerably smaller, ensure that the SysV one is
143 # never compiled in the final library (http://crbug.com/742525#c28). GNU
144 # hash support was added in Android M. Also not supported on MIPS
145 # architecture (http://crbug.com/811306).
146 ldflags += [ "-Wl,--hash-style=gnu" ]
147 }
148
149 # See crbug.com/705088.
150 if (target_cpu == "arm" && is_asan) {
151 ldflags += [ "-Wl,--long-plt" ]
152 }
153 }
Tibor Goldschwendtb05a8882019-10-29 15:12:08154
Andrew Grieve71bd025e2020-06-25 05:23:18155 if (!_generate_partitions && !_collect_inputs_only) {
Tibor Goldschwendtb05a8882019-10-29 15:12:08156 # Make helper targets so that we always have module native targets no matter
157 # whether partitions are enabled.
158 foreach(_module_desc, _module_descs) {
159 if (defined(_module_desc.native_deps)) {
160 group("${target_name}_${_module_desc.name}") {
161 forward_variables_from(invoker, [ "testonly" ])
162 deps = _module_desc.native_deps
163 }
164 }
165 }
166 }
Christopher Grant5f0c1382018-12-04 18:48:22167}