Debian Codegraph @

third_party/upb/python/BUILD

raw
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
27 load("//python:py_extension.bzl", "py_extension")
28 # end:github_only
29
30 load("@bazel_skylib//lib:selects.bzl", "selects")
31 load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
32 load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
33
34 licenses(["notice"])
35
36 package(
37 default_visibility = ["//python/dist:__pkg__"],
38 )
39
40 LIMITED_API_FLAG_SELECT = {
41 ":limited_api_3.7": ["-DPy_LIMITED_API=0x03070000"],
42 ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"],
43 "//conditions:default": [],
44 }
45
46 bool_flag(
47 name = "limited_api",
48 build_setting_default = False,
49 )
50
51 string_flag(
52 name = "python_version",
53 build_setting_default = "system",
54 values = [
55 "system",
56 "37",
57 "38",
58 "39",
59 "310",
60 ],
61 )
62
63 config_setting(
64 name = "limited_api_3.7",
65 flag_values = {
66 ":limited_api": "True",
67 ":python_version": "37",
68 },
69 )
70
71 config_setting(
72 name = "full_api_3.7_win32",
73 flag_values = {
74 ":limited_api": "False",
75 ":python_version": "37",
76 },
77 values = {"cpu": "win32"},
78 )
79
80 config_setting(
81 name = "full_api_3.7_win64",
82 flag_values = {
83 ":limited_api": "False",
84 ":python_version": "37",
85 },
86 values = {"cpu": "win64"},
87 )
88
89 selects.config_setting_group(
90 name = "full_api_3.7",
91 match_any = [
92 ":full_api_3.7_win32",
93 ":full_api_3.7_win64",
94 ],
95 )
96
97 config_setting(
98 name = "full_api_3.8_win32",
99 flag_values = {
100 ":limited_api": "False",
101 ":python_version": "38",
102 },
103 values = {"cpu": "win32"},
104 )
105
106 config_setting(
107 name = "full_api_3.8_win64",
108 flag_values = {
109 ":limited_api": "False",
110 ":python_version": "38",
111 },
112 values = {"cpu": "win64"},
113 )
114
115 selects.config_setting_group(
116 name = "full_api_3.8",
117 match_any = [
118 ":full_api_3.8_win32",
119 ":full_api_3.8_win64",
120 ],
121 )
122
123 config_setting(
124 name = "full_api_3.9_win32",
125 flag_values = {
126 ":limited_api": "False",
127 ":python_version": "39",
128 },
129 values = {"cpu": "win32"},
130 )
131
132 config_setting(
133 name = "full_api_3.9_win64",
134 flag_values = {
135 ":limited_api": "False",
136 ":python_version": "39",
137 },
138 values = {"cpu": "win64"},
139 )
140
141 selects.config_setting_group(
142 name = "full_api_3.9",
143 match_any = [
144 "full_api_3.9_win32",
145 ":full_api_3.9_win64",
146 ],
147 )
148
149 config_setting(
150 name = "limited_api_3.10_win32",
151 flag_values = {
152 ":limited_api": "True",
153 ":python_version": "310",
154 },
155 values = {"cpu": "win32"},
156 )
157
158 config_setting(
159 name = "limited_api_3.10_win64",
160 flag_values = {
161 ":limited_api": "True",
162 ":python_version": "310",
163 },
164 values = {"cpu": "win64"},
165 )
166
167 selects.config_setting_group(
168 name = "limited_api_3.10",
169 match_any = [
170 ":limited_api_3.10_win32",
171 ":limited_api_3.10_win64",
172 ],
173 )
174
175 py_extension(
176 name = "_message",
177 srcs = [
178 "convert.c",
179 "convert.h",
180 "descriptor.c",
181 "descriptor.h",
182 "descriptor_containers.c",
183 "descriptor_containers.h",
184 "descriptor_pool.c",
185 "descriptor_pool.h",
186 "extension_dict.c",
187 "extension_dict.h",
188 "map.c",
189 "map.h",
190 "message.c",
191 "message.h",
192 "protobuf.c",
193 "protobuf.h",
194 "python_api.h",
195 "repeated.c",
196 "repeated.h",
197 "unknown_fields.c",
198 "unknown_fields.h",
199 ],
200 copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [
201 # The Python API requires patterns that are ISO C incompatible, like
202 # casts between function pointers and object pointers.
203 "-Wno-pedantic",
204 ],
205 deps = [
206 "//:collections",
207 "//:descriptor_upb_proto_reflection",
208 "//:reflection",
209 "//:table",
210 "//:textformat",
211 "//:upb",
212 "//upb/util:compare",
213 "//upb/util:def_to_proto",
214 "//upb/util:required_fields",
215 ],
216 )