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 8load("@bazel_skylib//lib:selects.bzl", "selects") 9load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") 10load("@rules_pkg//pkg:mappings.bzl", "pkg_files") 11load("//python:build_targets.bzl", "build_targets") 12load("//python:py_extension.bzl", "py_extension") 13load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") 14 15build_targets(name = "python") 16 17licenses(["notice"]) 18 19package( 20 default_applicable_licenses = ["//:license"], 21 default_visibility = ["//python/dist:__pkg__"], 22) 23 24LIMITED_API_FLAG_SELECT = { 25 ":limited_api_3.8": ["-DPy_LIMITED_API=0x03080000"], 26 ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"], 27 "//conditions:default": [], 28} 29 30bool_flag( 31 name = "limited_api", 32 build_setting_default = True, 33) 34 35string_flag( 36 name = "python_version", 37 build_setting_default = "system", 38 values = [ 39 "system", 40 "38", 41 "39", 42 "310", 43 "311", 44 ], 45) 46 47config_setting( 48 name = "limited_api_3.8", 49 flag_values = { 50 ":limited_api": "True", 51 ":python_version": "38", 52 }, 53) 54 55config_setting( 56 name = "full_api_3.8_win32", 57 flag_values = { 58 ":limited_api": "False", 59 ":python_version": "38", 60 }, 61 values = {"cpu": "win32"}, 62) 63 64config_setting( 65 name = "full_api_3.8_win64", 66 flag_values = { 67 ":limited_api": "False", 68 ":python_version": "38", 69 }, 70 values = {"cpu": "win64"}, 71) 72 73selects.config_setting_group( 74 name = "full_api_3.8", 75 match_any = [ 76 ":full_api_3.8_win32", 77 ":full_api_3.8_win64", 78 ], 79) 80 81config_setting( 82 name = "full_api_3.9_win32", 83 flag_values = { 84 ":limited_api": "False", 85 ":python_version": "39", 86 }, 87 values = {"cpu": "win32"}, 88) 89 90config_setting( 91 name = "full_api_3.9_win64", 92 flag_values = { 93 ":limited_api": "False", 94 ":python_version": "39", 95 }, 96 values = {"cpu": "win64"}, 97) 98 99selects.config_setting_group( 100 name = "full_api_3.9", 101 match_any = [ 102 "full_api_3.9_win32", 103 ":full_api_3.9_win64", 104 ], 105) 106 107config_setting( 108 name = "limited_api_3.10_win32", 109 flag_values = { 110 ":limited_api": "True", 111 ":python_version": "310", 112 }, 113 values = {"cpu": "win32"}, 114) 115 116config_setting( 117 name = "limited_api_3.10_win64", 118 flag_values = { 119 ":limited_api": "True", 120 ":python_version": "310", 121 }, 122 values = {"cpu": "win64"}, 123) 124 125selects.config_setting_group( 126 name = "limited_api_3.10", 127 match_any = [ 128 ":limited_api_3.10_win32", 129 ":limited_api_3.10_win64", 130 ], 131) 132 133_message_target_compatible_with = { 134 "@platforms//os:windows": ["@platforms//:incompatible"], 135 "@system_python//:none": ["@platforms//:incompatible"], 136 "@system_python//:unsupported": ["@platforms//:incompatible"], 137 "//conditions:default": [], 138} 139 140filegroup( 141 name = "message_srcs", 142 srcs = [ 143 "convert.c", 144 "convert.h", 145 "descriptor.c", 146 "descriptor.h", 147 "descriptor_containers.c", 148 "descriptor_containers.h", 149 "descriptor_pool.c", 150 "descriptor_pool.h", 151 "extension_dict.c", 152 "extension_dict.h", 153 "map.c", 154 "map.h", 155 "message.c", 156 "message.h", 157 "protobuf.c", 158 "protobuf.h", 159 "python_api.h", 160 "repeated.c", 161 "repeated.h", 162 "unknown_fields.c", 163 "unknown_fields.h", 164 ], 165) 166 167py_extension( 168 name = "_message", 169 srcs = [":message_srcs"], 170 copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [ 171 # The Python API requires patterns that are ISO C incompatible, like 172 # casts between function pointers and object pointers. 173 "-Wno-pedantic", 174 ], 175 target_compatible_with = select(_message_target_compatible_with), 176 deps = [ 177 "//src/google/protobuf:descriptor_upb_reflection_proto", 178 "//third_party/utf8_range", 179 "//upb:base", 180 "//upb:eps_copy_input_stream", 181 "//upb:message", 182 "//upb:message_compare", 183 "//upb:message_copy", 184 "//upb:port", 185 "//upb:reflection", 186 "//upb:text", 187 "//upb:wire_reader", 188 "//upb/hash", 189 "//upb/util:def_to_proto", 190 "//upb/util:required_fields", 191 ], 192) 193