1# Copyright (c) 2009-2021, Google LLC 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# * Redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer. 8# * Redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution. 11# * Neither the name of Google LLC nor the 12# names of its contributors may be used to endorse or promote products 13# derived from this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY 19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26# begin:github_only 27load("//python:py_extension.bzl", "py_extension") 28# end:github_only 29 30load("@bazel_skylib//lib:selects.bzl", "selects") 31load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") 32load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") 33 34# begin:github_only 35load("@rules_pkg//:mappings.bzl", "pkg_files") 36# end:github_only 37 38licenses(["notice"]) 39 40package( 41 default_visibility = ["//python/dist:__pkg__"], 42) 43 44LIMITED_API_FLAG_SELECT = { 45 ":limited_api_3.7": ["-DPy_LIMITED_API=0x03070000"], 46 ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"], 47 "//conditions:default": [], 48} 49 50bool_flag( 51 name = "limited_api", 52 build_setting_default = True, 53) 54 55string_flag( 56 name = "python_version", 57 build_setting_default = "system", 58 values = [ 59 "system", 60 "37", 61 "38", 62 "39", 63 "310", 64 ], 65) 66 67config_setting( 68 name = "limited_api_3.7", 69 flag_values = { 70 ":limited_api": "True", 71 ":python_version": "37", 72 }, 73) 74 75config_setting( 76 name = "full_api_3.7_win32", 77 flag_values = { 78 ":limited_api": "False", 79 ":python_version": "37", 80 }, 81 values = {"cpu": "win32"}, 82) 83 84config_setting( 85 name = "full_api_3.7_win64", 86 flag_values = { 87 ":limited_api": "False", 88 ":python_version": "37", 89 }, 90 values = {"cpu": "win64"}, 91) 92 93selects.config_setting_group( 94 name = "full_api_3.7", 95 match_any = [ 96 ":full_api_3.7_win32", 97 ":full_api_3.7_win64", 98 ], 99) 100 101config_setting( 102 name = "full_api_3.8_win32", 103 flag_values = { 104 ":limited_api": "False", 105 ":python_version": "38", 106 }, 107 values = {"cpu": "win32"}, 108) 109 110config_setting( 111 name = "full_api_3.8_win64", 112 flag_values = { 113 ":limited_api": "False", 114 ":python_version": "38", 115 }, 116 values = {"cpu": "win64"}, 117) 118 119selects.config_setting_group( 120 name = "full_api_3.8", 121 match_any = [ 122 ":full_api_3.8_win32", 123 ":full_api_3.8_win64", 124 ], 125) 126 127config_setting( 128 name = "full_api_3.9_win32", 129 flag_values = { 130 ":limited_api": "False", 131 ":python_version": "39", 132 }, 133 values = {"cpu": "win32"}, 134) 135 136config_setting( 137 name = "full_api_3.9_win64", 138 flag_values = { 139 ":limited_api": "False", 140 ":python_version": "39", 141 }, 142 values = {"cpu": "win64"}, 143) 144 145selects.config_setting_group( 146 name = "full_api_3.9", 147 match_any = [ 148 "full_api_3.9_win32", 149 ":full_api_3.9_win64", 150 ], 151) 152 153config_setting( 154 name = "limited_api_3.10_win32", 155 flag_values = { 156 ":limited_api": "True", 157 ":python_version": "310", 158 }, 159 values = {"cpu": "win32"}, 160) 161 162config_setting( 163 name = "limited_api_3.10_win64", 164 flag_values = { 165 ":limited_api": "True", 166 ":python_version": "310", 167 }, 168 values = {"cpu": "win64"}, 169) 170 171selects.config_setting_group( 172 name = "limited_api_3.10", 173 match_any = [ 174 ":limited_api_3.10_win32", 175 ":limited_api_3.10_win64", 176 ], 177) 178 179# begin:github_only 180_message_target_compatible_with = { 181 "@platforms//os:windows": ["@platforms//:incompatible"], 182 "@system_python//:none": ["@platforms//:incompatible"], 183 "@system_python//:unsupported": ["@platforms//:incompatible"], 184 "//conditions:default": [], 185} 186 187pkg_files( 188 name = "message_extension", 189 srcs = [":message_srcs"], 190 prefix = "python/", 191) 192# end:github_only 193# begin:google_only 194# _message_target_compatible_with = { 195# "@platforms//os:windows": ["@platforms//:incompatible"], 196# "//conditions:default": [], 197# } 198# end:google_only 199 200filegroup( 201 name = "message_srcs", 202 srcs = [ 203 "convert.c", 204 "convert.h", 205 "descriptor.c", 206 "descriptor.h", 207 "descriptor_containers.c", 208 "descriptor_containers.h", 209 "descriptor_pool.c", 210 "descriptor_pool.h", 211 "extension_dict.c", 212 "extension_dict.h", 213 "map.c", 214 "map.h", 215 "message.c", 216 "message.h", 217 "protobuf.c", 218 "protobuf.h", 219 "python_api.h", 220 "repeated.c", 221 "repeated.h", 222 "unknown_fields.c", 223 "unknown_fields.h", 224 ], 225 # begin:google_only 226# compatible_with = ["//buildenv/target:non_prod"], 227 # end:google_only 228) 229 230py_extension( 231 name = "_message", 232 srcs = [":message_srcs"], 233 copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [ 234 # The Python API requires patterns that are ISO C incompatible, like 235 # casts between function pointers and object pointers. 236 "-Wno-pedantic", 237 ], 238 target_compatible_with = select(_message_target_compatible_with), 239 deps = [ 240 "//:collections", 241 "//:descriptor_upb_proto_reflection", 242 "//:eps_copy_input_stream", 243 "//:hash", 244 "//:port", 245 "//:reflection", 246 "//:textformat", 247 "//:upb", 248 "//:wire", 249 "//:wire_reader", 250 "//:wire_types", 251 "//upb/util:compare", 252 "//upb/util:def_to_proto", 253 "//upb/util:required_fields", 254 ], 255) 256