Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 1 | # 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 | |
| 5 | import("//base/android/linker/config.gni") |
| 6 | import("//build/config/android/config.gni") |
| 7 | import("//build/config/android/linker_version_script.gni") |
| 8 | import("//build/config/compiler/compiler.gni") |
Christopher Grant | 2b9c951 | 2019-05-21 16:02:38 | [diff] [blame] | 9 | import("//build/partitioned_shared_library.gni") |
Tibor Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 10 | import("//chrome/android/modules/buildflags.gni") |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 11 | import("//device/vr/buildflags/buildflags.gni") |
| 12 | |
Christopher Grant | b1f70c5 | 2019-06-04 22:37:18 | [diff] [blame] | 13 | # TODO(cjgrant): Remove these variables once downstream stops using them. |
| 14 | bundle_library_suffix = "" |
Christopher Grant | 133ae77d | 2019-06-07 15:17:48 | [diff] [blame] | 15 | apk_pak_asset_type = "_apk" |
Christopher Grant | 5f09fb9b | 2018-12-05 20:15:14 | [diff] [blame] | 16 | |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 17 | # 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 Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 22 | # 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 Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 25 | # 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 Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 32 | template("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 Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 36 | _collect_inputs_only = |
| 37 | defined(invoker.collect_inputs_only) && invoker.collect_inputs_only |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 38 | |
Andrew Grieve | bb0c9ca | 2020-06-25 22:27:08 | [diff] [blame] | 39 | # When _collect_inputs_only && !(!_is_webview && enable_vr). |
Clark DuVall | 2c43385 | 2020-09-17 05:46:44 | [diff] [blame] | 40 | not_needed([ "_export_java_symbols" ]) |
| 41 | |
Christopher Grant | 883056b3 | 2019-06-17 18:48:03 | [diff] [blame] | 42 | # Create a partitioned libraries if the build config supports it, and the |
Christopher Grant | 48705d7 | 2019-10-07 21:22:53 | [diff] [blame] | 43 | # invoker has supplied module descriptors. |
Clark DuVall | 003524e | 2020-09-18 02:38:34 | [diff] [blame] | 44 | _generate_partitions = defined(invoker.module_descs) && |
Andrew Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 45 | use_native_partitions && !_collect_inputs_only |
Tibor Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 46 | _module_descs = [] |
Christopher Grant | 48705d7 | 2019-10-07 21:22:53 | [diff] [blame] | 47 | if (defined(invoker.module_descs)) { |
Tibor Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 48 | _module_descs = invoker.module_descs |
Tibor Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 49 | } |
Christopher Grant | 883056b3 | 2019-06-17 18:48:03 | [diff] [blame] | 50 | |
Andrew Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 51 | 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 Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 66 | } |
| 67 | } |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Christopher Grant | 883056b3 | 2019-06-17 18:48:03 | [diff] [blame] | 71 | if (_generate_partitions) { |
Christopher Grant | 2b9c951 | 2019-05-21 16:02:38 | [diff] [blame] | 72 | _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 Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 80 | if (!_is_webview) { |
| 81 | deps += [ "//chrome:chrome_android_core" ] |
| 82 | } |
| 83 | |
Tiancong Wang | 5abb4775 | 2019-07-10 19:18:47 | [diff] [blame] | 84 | configs += [ "//build/config/compiler:chrome_orderfile_config" ] |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 85 | |
| 86 | # Use a dynamically-generated linker script. |
| 87 | configs -= [ "//build/config/android:hide_all_but_jni_onload" ] |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 88 | if (!defined(ldflags)) { |
| 89 | ldflags = [] |
| 90 | } |
Andrew Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 91 | 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 Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 101 | |
Christopher Grant | 2b9c951 | 2019-05-21 16:02:38 | [diff] [blame] | 102 | # Handle VR JNI registration and dependencies. |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 103 | if (!_is_webview && enable_vr) { |
| 104 | if (_export_java_symbols) { |
Tibor Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 105 | # NOTE: While this file is named *_monochrome.cc, it just contains an |
| 106 | # empty vr::RegisterJni() function that returns true. |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 107 | 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 Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 116 | if (_generate_partitions) { |
Tibor Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 117 | partitions = [] |
Tibor Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 118 | foreach(_module_desc, _module_descs) { |
Tibor Goldschwendt | aef8e39 | 2019-07-19 16:39:10 | [diff] [blame] | 119 | if (defined(_module_desc.native_deps)) { |
| 120 | partitions += [ _module_desc.name ] |
| 121 | deps += _module_desc.native_deps |
| 122 | } |
| 123 | } |
Clark DuVall | 003524e | 2020-09-18 02:38:34 | [diff] [blame] | 124 | } else if (_collect_inputs_only) { |
Andrew Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 125 | foreach(_module_desc, _module_descs) { |
| 126 | if (defined(_module_desc.native_deps)) { |
| 127 | deps += _module_desc.native_deps |
| 128 | } |
| 129 | } |
Christopher Grant | 2b9c951 | 2019-05-21 16:02:38 | [diff] [blame] | 130 | } |
| 131 | |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 132 | # Compress relocations if needed. |
Sam Maier | 0aae786 | 2019-02-04 20:44:32 | [diff] [blame] | 133 | if ((_is_monochrome || _is_webview || chromium_linker_supported) && |
| 134 | use_lld) { |
| 135 | configs += [ "//build/config/android:lld_pack_relocations" ] |
Christopher Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 136 | } |
| 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 Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 154 | |
Andrew Grieve | 71bd025e | 2020-06-25 05:23:18 | [diff] [blame] | 155 | if (!_generate_partitions && !_collect_inputs_only) { |
Tibor Goldschwendt | b05a888 | 2019-10-29 15:12:08 | [diff] [blame] | 156 | # 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 Grant | 5f0c138 | 2018-12-04 18:48:22 | [diff] [blame] | 167 | } |