David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 1 | # Internal Starlark definitions for Protobuf. |
| 2 | |
Mike Kruskal | 5888882 | 2023-03-01 13:45:10 -0800 | [diff] [blame] | 3 | load("@bazel_skylib//lib:selects.bzl", "selects") |
aiuto | 3ab1276 | 2024-02-13 09:06:30 -0800 | [diff] [blame] | 4 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") |
Protobuf Team Bot | 21d75f8 | 2024-04-05 07:45:26 -0700 | [diff] [blame] | 5 | load("//bazel:cc_proto_library.bzl", starlark_cc_proto_library = "cc_proto_library") |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 6 | load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test") |
| 7 | load(":compiler_config_setting.bzl", "create_compiler_config_setting") |
| 8 | |
| 9 | package( |
| 10 | default_visibility = [ |
| 11 | # Public, but Protobuf only visibility. |
| 12 | "//:__subpackages__", |
| 13 | ], |
| 14 | ) |
| 15 | |
| 16 | create_compiler_config_setting( |
| 17 | name = "config_msvc", |
| 18 | value = "msvc-cl", |
| 19 | ) |
| 20 | |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 21 | config_setting( |
| 22 | name = "aarch64", |
| 23 | values = {"cpu": "linux-aarch_64"}, |
| 24 | ) |
| 25 | |
| 26 | config_setting( |
| 27 | name = "x86_64", |
| 28 | values = {"cpu": "linux-x86_64"}, |
| 29 | ) |
| 30 | |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 31 | # Android NDK builds can specify different crosstool_top flags to choose which |
| 32 | # STL they use for C++. We need these multiple variants to catch all of those |
| 33 | # versions of crosstool_top and reliably detect Android. |
| 34 | # |
| 35 | # For more info on the various crosstool_tops used by NDK Bazel builds, see: |
| 36 | # https://docs.bazel.build/versions/master/android-ndk.html#configuring-the-stl |
| 37 | |
Ming-Chuan | e541747 | 2024-03-13 09:42:33 -0700 | [diff] [blame] | 38 | # When using https://bazel.build/concepts/platforms |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 39 | config_setting( |
| 40 | name = "config_android", |
Ming-Chuan | eef5564 | 2024-03-22 09:17:10 -0700 | [diff] [blame] | 41 | constraint_values = ["@platforms//os:android"], |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
Ming-Chuan | e541747 | 2024-03-13 09:42:33 -0700 | [diff] [blame] | 44 | # When using legacy flags like --android_crosstool_top, --android_cpu, and --fat_apk_cpu |
| 45 | config_setting( |
| 46 | name = "config_android-legacy-default-crosstool", |
| 47 | values = { |
| 48 | # Default of `--android_crosstool_top` |
| 49 | "crosstool_top": "//external:android/crosstool", |
| 50 | }, |
| 51 | ) |
| 52 | |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 53 | config_setting( |
| 54 | name = "config_android-stlport", |
| 55 | values = { |
| 56 | "crosstool_top": "@androidndk//:toolchain-stlport", |
| 57 | }, |
| 58 | ) |
| 59 | |
| 60 | config_setting( |
| 61 | name = "config_android-libcpp", |
| 62 | values = { |
| 63 | "crosstool_top": "@androidndk//:toolchain-libcpp", |
| 64 | }, |
| 65 | ) |
| 66 | |
| 67 | config_setting( |
| 68 | name = "config_android-gnu-libstdcpp", |
| 69 | values = { |
| 70 | "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp", |
| 71 | }, |
| 72 | ) |
| 73 | |
| 74 | config_setting( |
| 75 | name = "config_android-default", |
| 76 | values = { |
| 77 | "crosstool_top": "@androidndk//:default_crosstool", |
| 78 | }, |
| 79 | ) |
| 80 | |
Joshua Haberman | 2dc7679 | 2022-05-23 20:59:31 +0000 | [diff] [blame] | 81 | config_setting( |
| 82 | name = "config_win32", |
| 83 | values = { |
| 84 | "cpu": "win32", |
| 85 | }, |
| 86 | ) |
| 87 | |
| 88 | config_setting( |
| 89 | name = "config_win64", |
| 90 | values = { |
| 91 | "cpu": "win64", |
| 92 | }, |
| 93 | ) |
| 94 | |
deannagarcia | 15bd2c2 | 2023-03-08 15:36:57 -0800 | [diff] [blame] | 95 | selects.config_setting_group( |
| 96 | name = "config_win", |
| 97 | match_any = [ |
| 98 | ":config_win32", |
| 99 | ":config_win64", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 100 | ], |
deannagarcia | 15bd2c2 | 2023-03-08 15:36:57 -0800 | [diff] [blame] | 101 | ) |
| 102 | |
Mike Kruskal | 5888882 | 2023-03-01 13:45:10 -0800 | [diff] [blame] | 103 | config_setting( |
| 104 | name = "config_osx_aarch64", |
| 105 | values = {"cpu": "osx-aarch_64"}, |
| 106 | ) |
| 107 | |
| 108 | config_setting( |
| 109 | name = "config_osx_x86_64", |
deannagarcia | 15bd2c2 | 2023-03-08 15:36:57 -0800 | [diff] [blame] | 110 | values = {"cpu": "osx-x86_64"}, |
Mike Kruskal | 5888882 | 2023-03-01 13:45:10 -0800 | [diff] [blame] | 111 | ) |
| 112 | |
| 113 | selects.config_setting_group( |
| 114 | name = "config_osx", |
| 115 | match_any = [ |
Mike Kruskal | 5888882 | 2023-03-01 13:45:10 -0800 | [diff] [blame] | 116 | ":config_osx_aarch64", |
| 117 | ":config_osx_x86_64", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 118 | ], |
Mike Kruskal | 5888882 | 2023-03-01 13:45:10 -0800 | [diff] [blame] | 119 | ) |
| 120 | |
David L. Jones | 52655b1 | 2022-05-06 12:11:46 -0700 | [diff] [blame] | 121 | # Internal testing: |
| 122 | |
| 123 | starlark_cc_proto_library( |
| 124 | name = "any_cc_proto", |
| 125 | visibility = ["//visibility:private"], |
| 126 | deps = ["//:any_proto"], |
| 127 | ) |
| 128 | |
| 129 | starlark_cc_proto_library( |
| 130 | name = "api_cc_proto", |
| 131 | visibility = ["//visibility:private"], |
| 132 | deps = ["//:api_proto"], |
| 133 | ) |
| 134 | |
| 135 | starlark_cc_proto_library( |
| 136 | name = "compiler_plugin_cc_proto", |
| 137 | visibility = ["//visibility:private"], |
| 138 | deps = ["//:compiler_plugin_proto"], |
| 139 | ) |
| 140 | |
| 141 | starlark_cc_proto_library( |
| 142 | name = "descriptor_cc_proto", |
| 143 | visibility = ["//visibility:private"], |
| 144 | deps = ["//:descriptor_proto"], |
| 145 | ) |
| 146 | |
| 147 | starlark_cc_proto_library( |
| 148 | name = "duration_cc_proto", |
| 149 | visibility = ["//visibility:private"], |
| 150 | deps = ["//:duration_proto"], |
| 151 | ) |
| 152 | |
| 153 | starlark_cc_proto_library( |
| 154 | name = "empty_cc_proto", |
| 155 | visibility = ["//visibility:private"], |
| 156 | deps = ["//:empty_proto"], |
| 157 | ) |
| 158 | |
| 159 | starlark_cc_proto_library( |
| 160 | name = "field_mask_cc_proto", |
| 161 | visibility = ["//visibility:private"], |
| 162 | deps = ["//:field_mask_proto"], |
| 163 | ) |
| 164 | |
| 165 | starlark_cc_proto_library( |
| 166 | name = "source_context_cc_proto", |
| 167 | visibility = ["//visibility:private"], |
| 168 | deps = ["//:source_context_proto"], |
| 169 | ) |
| 170 | |
| 171 | starlark_cc_proto_library( |
| 172 | name = "struct_cc_proto", |
| 173 | visibility = ["//visibility:private"], |
| 174 | deps = ["//:struct_proto"], |
| 175 | ) |
| 176 | |
| 177 | starlark_cc_proto_library( |
| 178 | name = "timestamp_cc_proto", |
| 179 | visibility = ["//visibility:private"], |
| 180 | deps = ["//:timestamp_proto"], |
| 181 | ) |
| 182 | |
| 183 | starlark_cc_proto_library( |
| 184 | name = "type_cc_proto", |
| 185 | visibility = ["//visibility:private"], |
| 186 | deps = ["//:type_proto"], |
| 187 | ) |
| 188 | |
| 189 | starlark_cc_proto_library( |
| 190 | name = "wrappers_cc_proto", |
| 191 | visibility = ["//visibility:private"], |
| 192 | deps = ["//:wrappers_proto"], |
| 193 | ) |
| 194 | |
| 195 | cc_proto_blacklist_test( |
| 196 | name = "cc_proto_blacklist_test", |
| 197 | deps = [ |
| 198 | ":any_cc_proto", |
| 199 | ":api_cc_proto", |
| 200 | ":compiler_plugin_cc_proto", |
| 201 | ":descriptor_cc_proto", |
| 202 | ":duration_cc_proto", |
| 203 | ":empty_cc_proto", |
| 204 | ":field_mask_cc_proto", |
| 205 | ":source_context_cc_proto", |
| 206 | ":struct_cc_proto", |
| 207 | ":timestamp_cc_proto", |
| 208 | ":type_cc_proto", |
| 209 | ":wrappers_cc_proto", |
| 210 | ], |
| 211 | ) |
| 212 | |
| 213 | pkg_files( |
| 214 | name = "dist_files", |
| 215 | srcs = glob(["*"]), |
| 216 | strip_prefix = strip_prefix.from_root(""), |
| 217 | visibility = ["//pkg:__pkg__"], |
| 218 | ) |