blob: 3e34bbdbc48b8acec310f32d2d2789a780b7ec72 [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001# 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 Cozzette501ecec2023-09-26 14:36:20 -07008load("@bazel_skylib//lib:selects.bzl", "selects")
9load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
Adam Cozzette501ecec2023-09-26 14:36:20 -070010
11# begin:github_only
aiuto3ab12762024-02-13 09:06:30 -080012load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
Adam Cozzette501ecec2023-09-26 14:36:20 -070013load("//python:build_targets.bzl", "build_targets")
Protobuf Team Bot83ec4102024-03-26 18:50:37 -070014load("//python:py_extension.bzl", "py_extension")
Protobuf Team Botd7f032a2024-04-03 01:34:28 -070015load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
Adam Cozzette4ec91702023-12-28 14:40:25 -080016
Adam Cozzette501ecec2023-09-26 14:36:20 -070017build_targets(name = "python")
18# end:github_only
19
20licenses(["notice"])
21
22package(
23 # begin:google_only
Adam Cozzette4ec91702023-12-28 14:40:25 -080024 # default_applicable_licenses = ["//upb:license"],
Adam Cozzette501ecec2023-09-26 14:36:20 -070025 # end:google_only
26 default_visibility = ["//python/dist:__pkg__"],
27)
28
29LIMITED_API_FLAG_SELECT = {
Adam Cozzette8f831e92023-09-28 16:10:31 -070030 ":limited_api_3.8": ["-DPy_LIMITED_API=0x03080000"],
Adam Cozzette501ecec2023-09-26 14:36:20 -070031 ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"],
32 "//conditions:default": [],
33}
34
35bool_flag(
36 name = "limited_api",
37 build_setting_default = True,
38)
39
40string_flag(
41 name = "python_version",
42 build_setting_default = "system",
43 values = [
44 "system",
Adam Cozzette501ecec2023-09-26 14:36:20 -070045 "38",
46 "39",
47 "310",
Adam Cozzette8f831e92023-09-28 16:10:31 -070048 "311",
Adam Cozzette501ecec2023-09-26 14:36:20 -070049 ],
50)
51
52config_setting(
Adam Cozzette8f831e92023-09-28 16:10:31 -070053 name = "limited_api_3.8",
Adam Cozzette501ecec2023-09-26 14:36:20 -070054 flag_values = {
55 ":limited_api": "True",
Adam Cozzette8f831e92023-09-28 16:10:31 -070056 ":python_version": "38",
Adam Cozzette501ecec2023-09-26 14:36:20 -070057 },
58)
59
60config_setting(
Adam Cozzette501ecec2023-09-26 14:36:20 -070061 name = "full_api_3.8_win32",
62 flag_values = {
63 ":limited_api": "False",
64 ":python_version": "38",
65 },
66 values = {"cpu": "win32"},
67)
68
69config_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
78selects.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
86config_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
95config_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
104selects.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
112config_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
121config_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
130selects.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 Cozzette4ec91702023-12-28 14:40:25 -0800140 "@platforms//os:windows": ["@platforms//:incompatible"],
141 "@system_python//:none": ["@platforms//:incompatible"],
142 "@system_python//:unsupported": ["@platforms//:incompatible"],
143 "//conditions:default": [],
Adam Cozzette501ecec2023-09-26 14:36:20 -0700144}
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
154filegroup(
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 Cozzette4ec91702023-12-28 14:40:25 -0800180 # compatible_with = ["//buildenv/target:non_prod"],
Adam Cozzette501ecec2023-09-26 14:36:20 -0700181 # end:google_only
182)
183
184py_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 Cozzette4ec91702023-12-28 14:40:25 -0800194 "//third_party/utf8_range",
Eric Salob997cb62023-12-21 08:09:54 -0800195 "//upb:base",
Adam Cozzette501ecec2023-09-26 14:36:20 -0700196 "//upb:descriptor_upb_proto_reflection",
197 "//upb:eps_copy_input_stream",
Eric Salo07fba1d2023-09-29 14:50:56 -0700198 "//upb:message",
Eric Saloc69ed472024-02-09 13:37:03 -0800199 "//upb:message_compare",
Adam Cozzette501ecec2023-09-26 14:36:20 -0700200 "//upb:message_copy",
201 "//upb:port",
202 "//upb:reflection",
203 "//upb:text",
204 "//upb:wire_reader",
Eric Salo64dbf0d2024-01-01 18:19:56 -0800205 "//upb/hash",
Adam Cozzette501ecec2023-09-26 14:36:20 -0700206 "//upb/util:def_to_proto",
207 "//upb/util:required_fields",
Adam Cozzette501ecec2023-09-26 14:36:20 -0700208 ],
209)