| # Copyright (c) 2009-2021, Google LLC |
| # All rights reserved. |
| # |
| # Use of this source code is governed by a BSD-style |
| # license that can be found in the LICENSE file or at |
| # https://developers.google.com/open-source/licenses/bsd |
| |
| load("@bazel_skylib//lib:selects.bzl", "selects") |
| load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") |
| load("@rules_pkg//pkg:mappings.bzl", "pkg_files") |
| load("//python:build_targets.bzl", "build_targets") |
| load("//python:py_extension.bzl", "py_extension") |
| load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") |
| |
| build_targets(name = "python") |
| |
| licenses(["notice"]) |
| |
| package( |
| default_applicable_licenses = ["//:license"], |
| default_visibility = ["//python/dist:__pkg__"], |
| ) |
| |
| LIMITED_API_FLAG_SELECT = { |
| ":limited_api_3.9": ["-DPy_LIMITED_API=0x03090000"], |
| ":limited_api_3.10": ["-DPy_LIMITED_API=0x030a0000"], |
| "//conditions:default": [], |
| } |
| |
| bool_flag( |
| name = "limited_api", |
| build_setting_default = True, |
| ) |
| |
| string_flag( |
| name = "python_version", |
| build_setting_default = "system", |
| values = [ |
| "system", |
| "39", |
| "310", |
| "311", |
| ], |
| ) |
| |
| config_setting( |
| name = "limited_api_3.9", |
| flag_values = { |
| ":limited_api": "True", |
| ":python_version": "39", |
| }, |
| ) |
| |
| config_setting( |
| name = "full_api_3.9_win32", |
| flag_values = { |
| ":limited_api": "False", |
| ":python_version": "39", |
| }, |
| values = {"cpu": "win32"}, |
| ) |
| |
| config_setting( |
| name = "full_api_3.9_win64", |
| flag_values = { |
| ":limited_api": "False", |
| ":python_version": "39", |
| }, |
| values = {"cpu": "win64"}, |
| ) |
| |
| selects.config_setting_group( |
| name = "full_api_3.9", |
| match_any = [ |
| "full_api_3.9_win32", |
| ":full_api_3.9_win64", |
| ], |
| ) |
| |
| config_setting( |
| name = "limited_api_3.10_win32", |
| flag_values = { |
| ":limited_api": "True", |
| ":python_version": "310", |
| }, |
| values = {"cpu": "win32"}, |
| ) |
| |
| config_setting( |
| name = "limited_api_3.10_win64", |
| flag_values = { |
| ":limited_api": "True", |
| ":python_version": "310", |
| }, |
| values = {"cpu": "win64"}, |
| ) |
| |
| selects.config_setting_group( |
| name = "limited_api_3.10", |
| match_any = [ |
| ":limited_api_3.10_win32", |
| ":limited_api_3.10_win64", |
| ], |
| ) |
| |
| _message_target_compatible_with = { |
| "@platforms//os:windows": ["@platforms//:incompatible"], |
| "@system_python//:none": ["@platforms//:incompatible"], |
| "@system_python//:unsupported": ["@platforms//:incompatible"], |
| "//conditions:default": [], |
| } |
| |
| filegroup( |
| name = "message_srcs", |
| srcs = [ |
| "convert.c", |
| "convert.h", |
| "descriptor.c", |
| "descriptor.h", |
| "descriptor_containers.c", |
| "descriptor_containers.h", |
| "descriptor_pool.c", |
| "descriptor_pool.h", |
| "extension_dict.c", |
| "extension_dict.h", |
| "map.c", |
| "map.h", |
| "message.c", |
| "message.h", |
| "protobuf.c", |
| "protobuf.h", |
| "python_api.h", |
| "repeated.c", |
| "repeated.h", |
| "unknown_fields.c", |
| "unknown_fields.h", |
| ], |
| ) |
| |
| py_extension( |
| name = "_message", |
| srcs = [":message_srcs"], |
| copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [ |
| # The Python API requires patterns that are ISO C incompatible, like |
| # casts between function pointers and object pointers. |
| "-Wno-pedantic", |
| ], |
| target_compatible_with = select(_message_target_compatible_with), |
| deps = [ |
| "//src/google/protobuf:descriptor_upb_reflection_proto", |
| "//third_party/utf8_range", |
| "//upb:base", |
| "//upb:eps_copy_input_stream", |
| "//upb:message", |
| "//upb:message_compare", |
| "//upb:message_copy", |
| "//upb:port", |
| "//upb:reflection", |
| "//upb:text", |
| "//upb:wire_reader", |
| "//upb/hash", |
| "//upb/util:def_to_proto", |
| "//upb/util:required_fields", |
| ], |
| ) |