Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 1 | # Copyright (c) 2009-2021, Google LLC |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style |
| 5 | # license that can be found in the LICENSE file or at |
| 6 | # https://developers.google.com/open-source/licenses/bsd |
| 7 | |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 8 | load("@bazel_skylib//lib:selects.bzl", "selects") |
| 9 | load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 10 | |
| 11 | # begin:github_only |
aiuto | 3ab1276 | 2024-02-13 09:06:30 -0800 | [diff] [blame] | 12 | load("@rules_pkg//pkg:mappings.bzl", "pkg_files") |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 13 | load("//python:build_targets.bzl", "build_targets") |
Protobuf Team Bot | 83ec410 | 2024-03-26 18:50:37 -0700 | [diff] [blame] | 14 | load("//python:py_extension.bzl", "py_extension") |
Protobuf Team Bot | d7f032a | 2024-04-03 01:34:28 -0700 | [diff] [blame] | 15 | load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") |
Adam Cozzette | 4ec9170 | 2023-12-28 14:40:25 -0800 | [diff] [blame] | 16 | |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 17 | build_targets(name = "python") |
| 18 | # end:github_only |
| 19 | |
| 20 | licenses(["notice"]) |
| 21 | |
| 22 | package( |
| 23 | # begin:google_only |
Adam Cozzette | 4ec9170 | 2023-12-28 14:40:25 -0800 | [diff] [blame] | 24 | # default_applicable_licenses = ["//upb:license"], |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 25 | # end:google_only |
| 26 | default_visibility = ["//python/dist:__pkg__"], |
| 27 | ) |
| 28 | |
| 29 | LIMITED_API_FLAG_SELECT = { |
Adam Cozzette | 8f831e9 | 2023-09-28 16:10:31 -0700 | [diff] [blame] | 30 | ":limited_api_3.8": ["-DPy_LIMITED_API=0x03080000"], |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 31 | ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"], |
| 32 | "//conditions:default": [], |
| 33 | } |
| 34 | |
| 35 | bool_flag( |
| 36 | name = "limited_api", |
| 37 | build_setting_default = True, |
| 38 | ) |
| 39 | |
| 40 | string_flag( |
| 41 | name = "python_version", |
| 42 | build_setting_default = "system", |
| 43 | values = [ |
| 44 | "system", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 45 | "38", |
| 46 | "39", |
| 47 | "310", |
Adam Cozzette | 8f831e9 | 2023-09-28 16:10:31 -0700 | [diff] [blame] | 48 | "311", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 49 | ], |
| 50 | ) |
| 51 | |
| 52 | config_setting( |
Adam Cozzette | 8f831e9 | 2023-09-28 16:10:31 -0700 | [diff] [blame] | 53 | name = "limited_api_3.8", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 54 | flag_values = { |
| 55 | ":limited_api": "True", |
Adam Cozzette | 8f831e9 | 2023-09-28 16:10:31 -0700 | [diff] [blame] | 56 | ":python_version": "38", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 57 | }, |
| 58 | ) |
| 59 | |
| 60 | config_setting( |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 61 | name = "full_api_3.8_win32", |
| 62 | flag_values = { |
| 63 | ":limited_api": "False", |
| 64 | ":python_version": "38", |
| 65 | }, |
| 66 | values = {"cpu": "win32"}, |
| 67 | ) |
| 68 | |
| 69 | config_setting( |
| 70 | name = "full_api_3.8_win64", |
| 71 | flag_values = { |
| 72 | ":limited_api": "False", |
| 73 | ":python_version": "38", |
| 74 | }, |
| 75 | values = {"cpu": "win64"}, |
| 76 | ) |
| 77 | |
| 78 | selects.config_setting_group( |
| 79 | name = "full_api_3.8", |
| 80 | match_any = [ |
| 81 | ":full_api_3.8_win32", |
| 82 | ":full_api_3.8_win64", |
| 83 | ], |
| 84 | ) |
| 85 | |
| 86 | config_setting( |
| 87 | name = "full_api_3.9_win32", |
| 88 | flag_values = { |
| 89 | ":limited_api": "False", |
| 90 | ":python_version": "39", |
| 91 | }, |
| 92 | values = {"cpu": "win32"}, |
| 93 | ) |
| 94 | |
| 95 | config_setting( |
| 96 | name = "full_api_3.9_win64", |
| 97 | flag_values = { |
| 98 | ":limited_api": "False", |
| 99 | ":python_version": "39", |
| 100 | }, |
| 101 | values = {"cpu": "win64"}, |
| 102 | ) |
| 103 | |
| 104 | selects.config_setting_group( |
| 105 | name = "full_api_3.9", |
| 106 | match_any = [ |
| 107 | "full_api_3.9_win32", |
| 108 | ":full_api_3.9_win64", |
| 109 | ], |
| 110 | ) |
| 111 | |
| 112 | config_setting( |
| 113 | name = "limited_api_3.10_win32", |
| 114 | flag_values = { |
| 115 | ":limited_api": "True", |
| 116 | ":python_version": "310", |
| 117 | }, |
| 118 | values = {"cpu": "win32"}, |
| 119 | ) |
| 120 | |
| 121 | config_setting( |
| 122 | name = "limited_api_3.10_win64", |
| 123 | flag_values = { |
| 124 | ":limited_api": "True", |
| 125 | ":python_version": "310", |
| 126 | }, |
| 127 | values = {"cpu": "win64"}, |
| 128 | ) |
| 129 | |
| 130 | selects.config_setting_group( |
| 131 | name = "limited_api_3.10", |
| 132 | match_any = [ |
| 133 | ":limited_api_3.10_win32", |
| 134 | ":limited_api_3.10_win64", |
| 135 | ], |
| 136 | ) |
| 137 | |
| 138 | # begin:github_only |
| 139 | _message_target_compatible_with = { |
Adam Cozzette | 4ec9170 | 2023-12-28 14:40:25 -0800 | [diff] [blame] | 140 | "@platforms//os:windows": ["@platforms//:incompatible"], |
| 141 | "@system_python//:none": ["@platforms//:incompatible"], |
| 142 | "@system_python//:unsupported": ["@platforms//:incompatible"], |
| 143 | "//conditions:default": [], |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | # end:github_only |
| 147 | # begin:google_only |
| 148 | # _message_target_compatible_with = { |
| 149 | # "@platforms//os:windows": ["@platforms//:incompatible"], |
| 150 | # "//conditions:default": [], |
| 151 | # } |
| 152 | # end:google_only |
| 153 | |
| 154 | filegroup( |
| 155 | name = "message_srcs", |
| 156 | srcs = [ |
| 157 | "convert.c", |
| 158 | "convert.h", |
| 159 | "descriptor.c", |
| 160 | "descriptor.h", |
| 161 | "descriptor_containers.c", |
| 162 | "descriptor_containers.h", |
| 163 | "descriptor_pool.c", |
| 164 | "descriptor_pool.h", |
| 165 | "extension_dict.c", |
| 166 | "extension_dict.h", |
| 167 | "map.c", |
| 168 | "map.h", |
| 169 | "message.c", |
| 170 | "message.h", |
| 171 | "protobuf.c", |
| 172 | "protobuf.h", |
| 173 | "python_api.h", |
| 174 | "repeated.c", |
| 175 | "repeated.h", |
| 176 | "unknown_fields.c", |
| 177 | "unknown_fields.h", |
| 178 | ], |
| 179 | # begin:google_only |
Adam Cozzette | 4ec9170 | 2023-12-28 14:40:25 -0800 | [diff] [blame] | 180 | # compatible_with = ["//buildenv/target:non_prod"], |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 181 | # end:google_only |
| 182 | ) |
| 183 | |
| 184 | py_extension( |
| 185 | name = "_message", |
| 186 | srcs = [":message_srcs"], |
| 187 | copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [ |
| 188 | # The Python API requires patterns that are ISO C incompatible, like |
| 189 | # casts between function pointers and object pointers. |
| 190 | "-Wno-pedantic", |
| 191 | ], |
| 192 | target_compatible_with = select(_message_target_compatible_with), |
| 193 | deps = [ |
Adam Cozzette | 4ec9170 | 2023-12-28 14:40:25 -0800 | [diff] [blame] | 194 | "//third_party/utf8_range", |
Eric Salo | b997cb6 | 2023-12-21 08:09:54 -0800 | [diff] [blame] | 195 | "//upb:base", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 196 | "//upb:descriptor_upb_proto_reflection", |
| 197 | "//upb:eps_copy_input_stream", |
Eric Salo | 07fba1d | 2023-09-29 14:50:56 -0700 | [diff] [blame] | 198 | "//upb:message", |
Eric Salo | c69ed47 | 2024-02-09 13:37:03 -0800 | [diff] [blame] | 199 | "//upb:message_compare", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 200 | "//upb:message_copy", |
| 201 | "//upb:port", |
| 202 | "//upb:reflection", |
| 203 | "//upb:text", |
| 204 | "//upb:wire_reader", |
Eric Salo | 64dbf0d | 2024-01-01 18:19:56 -0800 | [diff] [blame] | 205 | "//upb/hash", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 206 | "//upb/util:def_to_proto", |
| 207 | "//upb/util:required_fields", |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 208 | ], |
| 209 | ) |