summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/android/chrome_common_shared_library.gni
blob: 5da411ddee0131187161d3f00c62fcf11fd32859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//base/android/linker/config.gni")
import("//build/config/android/config.gni")
import("//build/config/android/linker_version_script.gni")
import("//build/config/compiler/compiler.gni")
import("//build/partitioned_shared_library.gni")
import("//chrome/android/modules/buildflags.gni")
import("//device/vr/buildflags/buildflags.gni")

# TODO(cjgrant): Remove these variables once downstream stops using them.
bundle_library_suffix = ""
apk_pak_asset_type = "_apk"

# This template contains all common configuration for native shared libraries,
# including libchrome, monochrome, standalone webview (also called monochrome),
# and libchromefortest (used by chrome_public_test_apk).
#
# Variables:
#    is_monochrome: Optional. If set, the library is for use in monochrome.
#    is_webview: If true, the library is for webview, and browser-specific
#      config is skipped.
#    allow_partitions: If true, and the build config supports it, the library
#      is linked as a partitioned library, and separate feature libs are
#      generated if specified. Those libraries may later be packaged into
#      dynamic feature modules or APKs.
#    module_descs: Optional. Descriptors of modules for which to extract
#      partitions. Can only be set if |allow_partitions| is true. See
#      //chrome/android/modules/chrome_feature_modules.gni for the descriptor
#      format.
template("chrome_common_shared_library") {
  _is_monochrome = defined(invoker.is_monochrome) && invoker.is_monochrome
  _is_webview = defined(invoker.is_webview) && invoker.is_webview
  _export_java_symbols = _is_monochrome || _is_webview

  _linker_script = "$target_gen_dir/${target_name}_linker_script.txt"
  _linker_script_target = "${target_name}_linker_script"

  # Create a partitioned libraries if the build config supports it, and the
  # invoker wants partitions.
  _generate_partitions = defined(invoker.allow_partitions) &&
                         invoker.allow_partitions && use_native_modules
  if (_generate_partitions) {
    assert(defined(invoker.module_descs))
  } else {
    if (defined(invoker.module_descs)) {
      not_needed(invoker, [ "module_descs" ])
    }
  }

  # Create a custom linker script based on JNI and feature module requirements.
  generate_linker_version_script(_linker_script_target) {
    linker_script = _linker_script
    export_java_symbols = _export_java_symbols
    if (_generate_partitions) {
      export_symbol_whitelist_files = []
      foreach(_module_desc, invoker.module_descs) {
        if (defined(_module_desc.native_entrypoints)) {
          export_symbol_whitelist_files += [ _module_desc.native_entrypoints ]
        }
      }
    }
  }

  if (_generate_partitions) {
    _target_type = "partitioned_shared_library"
  } else {
    _target_type = "shared_library"
  }

  target(_target_type, target_name) {
    forward_variables_from(invoker, "*")

    if (!_is_webview) {
      deps += [ "//chrome:chrome_android_core" ]
    }

    configs += [ "//build/config/compiler:chrome_orderfile_config" ]

    # Use a dynamically-generated linker script.
    configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
    deps += [ ":$_linker_script_target" ]
    inputs = [
      "$_linker_script",
    ]
    if (!defined(ldflags)) {
      ldflags = []
    }
    ldflags += [ "-Wl,--version-script=" +
                 rebase_path(_linker_script, root_build_dir) ]

    # Handle VR JNI registration and dependencies.
    if (!_is_webview && enable_vr) {
      if (_export_java_symbols) {
        # NOTE: While this file is named *_monochrome.cc, it just contains an
        # empty vr::RegisterJni() function that returns true.
        sources += [ "../browser/android/vr/register_jni_monochrome.cc" ]
      } else {
        sources += [ "../browser/android/vr/register_jni.cc" ]
        deps += [
          "//chrome/browser/android/vr:jni_registration($default_toolchain)",
        ]
      }
    }

    if (_generate_partitions) {
      partitions = []
      foreach(_module_desc, invoker.module_descs) {
        if (defined(_module_desc.native_deps)) {
          partitions += [ _module_desc.name ]
          deps += _module_desc.native_deps
        }
      }
    }

    # Compress relocations if needed.
    if ((_is_monochrome || _is_webview || chromium_linker_supported) &&
        use_lld) {
      configs += [ "//build/config/android:lld_pack_relocations" ]
    }

    if ((_is_monochrome || _is_webview || chromium_linker_supported) &&
        target_cpu != "mipsel" && target_cpu != "mips64el") {
      # By default, the static linker will create ELF executables with both
      # SysV and GNU hash tables. Now that the chromium linker supports the GNU
      # format, which is considerably smaller, ensure that the SysV one is
      # never compiled in the final library (http://crbug.com/742525#c28). GNU
      # hash support was added in Android M. Also not supported on MIPS
      # architecture (http://crbug.com/811306).
      ldflags += [ "-Wl,--hash-style=gnu" ]
    }

    # See crbug.com/705088.
    if (target_cpu == "arm" && is_asan) {
      ldflags += [ "-Wl,--long-plt" ]
    }
  }
}