Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | # Copyright 2019 The Dawn & Tint Authors |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 2 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are met: |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 5 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | # list of conditions and the following disclaimer. |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 8 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer in the documentation |
| 11 | # and/or other materials provided with the distribution. |
| 12 | # |
| 13 | # 3. Neither the name of the copyright holder nor the names of its |
| 14 | # contributors may be used to endorse or promote products derived from |
| 15 | # this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 27 | |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 28 | import("//build_overrides/build.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 29 | import("dawn_features.gni") |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 30 | import("dawn_overrides_with_defaults.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 31 | |
| 32 | ############################################################################### |
| 33 | # Template to produce a component for one of Dawn's libraries. |
| 34 | ############################################################################### |
| 35 | |
| 36 | # Template that produces static and shared versions of the same library as well |
| 37 | # as a target similar to Chromium's component targets. |
| 38 | # - The shared version exports symbols and has dependent import the symbols |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 39 | # as libdawn_${name}.so. If the target name matches the package directory |
| 40 | # name, then the shared library target will be named 'shared', otherwise |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 41 | # '${target_name}_shared'. |
| 42 | # - The static library doesn't export symbols nor make dependents import them. |
| 43 | # If the target name matches the package directory name, then the static |
| 44 | # library target will be named 'static', otherwise '${target_name}_static'. |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 45 | # - The libname target is similar to a Chromium component and is an alias for |
| 46 | # either the static or the shared library. |
| 47 | # |
| 48 | # The DEFINE_PREFIX must be provided and must match the respective "_export.h" |
| 49 | # file. |
| 50 | # |
| 51 | # Example usage: |
| 52 | # |
| 53 | # dawn_component("my_library") { |
| 54 | # // my_library_export.h must use the MY_LIBRARY_IMPLEMENTATION and |
| 55 | # // MY_LIBRARY_SHARED_LIBRARY macros. |
| 56 | # DEFINE_PREFIX = "MY_LIBRARY" |
| 57 | # |
| 58 | # sources = [...] |
| 59 | # deps = [...] |
| 60 | # configs = [...] |
| 61 | # } |
| 62 | # |
| 63 | # executable("foo") { |
| 64 | # deps = [ ":my_library_shared" ] // or :my_library for the same effect |
| 65 | # } |
| 66 | template("dawn_component") { |
| 67 | # Copy the target_name in the local scope so it doesn't get shadowed in the |
| 68 | # definition of targets. |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 69 | name = target_name |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 70 | |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 71 | prefix = "${name}_" |
| 72 | |
| 73 | # Remove prefix if the target name matches directory |
| 74 | if (get_label_info(get_label_info(":$target_name", "dir"), "name") == name) { |
| 75 | prefix = "" |
| 76 | } |
| 77 | |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 78 | # The config that will apply to dependents of the shared library so they know |
| 79 | # they should "import" the symbols |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 80 | config("${prefix}shared_public_config") { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 81 | defines = [ "${invoker.DEFINE_PREFIX}_SHARED_LIBRARY" ] |
| 82 | |
| 83 | # Executable needs an rpath to find our shared libraries on OSX and Linux |
| 84 | if (is_mac) { |
| 85 | ldflags = [ |
| 86 | "-rpath", |
| 87 | "@executable_path/", |
| 88 | ] |
| 89 | } |
Hidehiko Abe | 948b3a0 | 2020-09-11 02:24:16 +0000 | [diff] [blame] | 90 | if ((is_linux || is_chromeos) && dawn_has_build) { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 91 | configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] |
| 92 | } |
| 93 | } |
| 94 | |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 95 | shared_library("${prefix}shared") { |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 96 | # The "tool" for creating shared libraries will automatically add the "lib" prefix |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 97 | output_name = "dawn_${name}" |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 98 | |
| 99 | # Copy all variables except "configs", which has a default value |
| 100 | forward_variables_from(invoker, "*", [ "configs" ]) |
| 101 | if (defined(invoker.configs)) { |
| 102 | configs += invoker.configs |
| 103 | } |
| 104 | |
Avi Drissman | ffd8681 | 2023-07-20 18:49:05 +0000 | [diff] [blame] | 105 | # If a "build with ARC" config is present, remove it. |
Avi Drissman | ffd8681 | 2023-07-20 18:49:05 +0000 | [diff] [blame] | 106 | if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) != |
| 107 | []) { |
| 108 | configs -= [ "//build/config/compiler:enable_arc" ] |
| 109 | } |
Avi Drissman | ffd8681 | 2023-07-20 18:49:05 +0000 | [diff] [blame] | 110 | |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 111 | # Tell dependents where to find this shared library |
| 112 | if (is_mac) { |
| 113 | ldflags = [ |
| 114 | "-install_name", |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 115 | "@rpath/lib${name}.dylib", |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 116 | ] |
| 117 | } |
| 118 | |
| 119 | # Use the config that makes the ${DEFINE_PREFIX}_EXPORT macro do something |
| 120 | if (!defined(public_configs)) { |
| 121 | public_configs = [] |
| 122 | } |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 123 | public_configs += [ ":${prefix}shared_public_config" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 124 | |
| 125 | # Tell sources of this library to export the symbols (and not import) |
| 126 | if (!defined(defines)) { |
| 127 | defines = [] |
| 128 | } |
| 129 | defines += [ "${invoker.DEFINE_PREFIX}_IMPLEMENTATION" ] |
Corentin Wallez | 6731464 | 2019-11-28 09:40:54 +0000 | [diff] [blame] | 130 | |
| 131 | # Chromium adds a config that uses a special linker script that removes |
| 132 | # all symbols except JNI ones. Remove this config so that our |
| 133 | # shared_library symbols are visible. This matches what Chromium's |
| 134 | # component template does. |
| 135 | if (build_with_chromium && is_android) { |
| 136 | configs -= [ "//build/config/android:hide_all_but_jni_onload" ] |
| 137 | } |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Sunny Sachanandani | b8e5a6a | 2023-11-15 16:20:13 +0000 | [diff] [blame] | 140 | if (dawn_complete_static_libs) { |
| 141 | # Use static_library if explicitly requested - this works even if there are |
| 142 | # no sources in the target by linking in sources from all dependencies. |
| 143 | _static_target_type = "static_library" |
| 144 | } else if (!defined(invoker.sources) || invoker.sources == []) { |
| 145 | # When there are no sources defined, use a source set to avoid creating |
| 146 | # an empty static library (which generally don't work). |
| 147 | _static_target_type = "source_set" |
| 148 | } else { |
| 149 | # Use static libraries for the static build rather than source sets because |
| 150 | # many of of our test binaries link many large dependencies but often don't |
| 151 | # use large portions of them. The static libraries are much more efficient |
| 152 | # in this situation since only the necessary object files are linked. |
| 153 | _static_target_type = "static_library" |
| 154 | } |
| 155 | |
| 156 | target(_static_target_type, "${prefix}static") { |
Ben Clayton | b01cf60 | 2022-02-04 17:53:55 +0000 | [diff] [blame] | 157 | output_name = "dawn_${name}_static" |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 158 | |
Sunny Sachanandani | b8e5a6a | 2023-11-15 16:20:13 +0000 | [diff] [blame] | 159 | if (dawn_complete_static_libs) { |
| 160 | assert(_static_target_type == "static_library") |
| 161 | complete_static_lib = true |
| 162 | } |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 163 | |
| 164 | # Copy all variables except "configs", which has a default value |
| 165 | forward_variables_from(invoker, "*", [ "configs" ]) |
| 166 | if (defined(invoker.configs)) { |
| 167 | configs += invoker.configs |
| 168 | } |
Avi Drissman | ffd8681 | 2023-07-20 18:49:05 +0000 | [diff] [blame] | 169 | |
| 170 | # If a "build with ARC" config is present, remove it. |
Avi Drissman | ffd8681 | 2023-07-20 18:49:05 +0000 | [diff] [blame] | 171 | if (filter_include(configs, [ "//build/config/compiler:enable_arc" ]) != |
| 172 | []) { |
| 173 | configs -= [ "//build/config/compiler:enable_arc" ] |
| 174 | } |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Corentin Wallez | 6574f92 | 2020-04-09 17:31:40 +0000 | [diff] [blame] | 177 | group(name) { |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 178 | if (is_component_build) { |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 179 | public_deps = [ ":${prefix}shared" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 180 | } else { |
Ben Clayton | 7d5badd | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 181 | public_deps = [ ":${prefix}static" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |