|
|
|
# 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.8": ["-DPy_LIMITED_API=0x03080000"],
|
|
|
|
":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",
|
|
|
|
"38",
|
|
|
|
"39",
|
|
|
|
"310",
|
|
|
|
"311",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
config_setting(
|
|
|
|
name = "limited_api_3.8",
|
|
|
|
flag_values = {
|
|
|
|
":limited_api": "True",
|
|
|
|
":python_version": "38",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
config_setting(
|
|
|
|
name = "full_api_3.8_win32",
|
|
|
|
flag_values = {
|
|
|
|
":limited_api": "False",
|
|
|
|
":python_version": "38",
|
|
|
|
},
|
|
|
|
values = {"cpu": "win32"},
|
|
|
|
)
|
|
|
|
|
|
|
|
config_setting(
|
|
|
|
name = "full_api_3.8_win64",
|
|
|
|
flag_values = {
|
|
|
|
":limited_api": "False",
|
|
|
|
":python_version": "38",
|
|
|
|
},
|
|
|
|
values = {"cpu": "win64"},
|
|
|
|
)
|
|
|
|
|
|
|
|
selects.config_setting_group(
|
|
|
|
name = "full_api_3.8",
|
|
|
|
match_any = [
|
|
|
|
":full_api_3.8_win32",
|
|
|
|
":full_api_3.8_win64",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
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 = [
|
Fixed layering check violations once and for all in upb bootstrapping.
Our bootstrapping setup compiles multiple versions of the generated code for `descriptor.proto` and `plugin.proto`, one for each stage of the bootstrap. For source files (`.c`), we can always select the correct version of the file in the BUILD rules, but for header files we need to make sure the correct stage's file is always selected via `#include`.
Previously we used `cc_library(includes=[])` to make it appear as though our bootstrapped headers had the same names as the "real" headers. This allowed a lot of the code to be agnostic to whether a bootstrap header was being used, which simplified things because we did not have to change the code performing the `#include`.
Unfortunately, due to build system limitations, this sometimes led to the incorrect header getting included. This should not have been possible, because we had a clean BUILD graph that should have removed all ambiguity about which header should be available. But in non-sandboxed builds, the compiler was able to find headers that were not actually in `deps=[]`, and worse it preferred those headers over the headers that actually were in `deps=[]`. This led to unintended results and errors about layering check violations.
This CL fixes the problem by removing all use of `includes=[]`. We now spell a full pathname to all bootstrap headers, so this class of errors is no longer possible. Unfortunately this adds some complexity, as we have to hard-code these full paths in several places.
A nice improvement in this CL is that `bootstrap_upb_proto_library()` can now only be used for bootstrapping; it only exposes the `descriptor_bootstrap.h` / `plugin_bootstrap.h` files. Anyone wanting to use the normal `net/proto2/proto/descriptor.upb.h` file should depend on `//net/proto2/proto:descriptor_upb_c_proto` target instead.
PiperOrigin-RevId: 664953196
4 months ago
|
|
|
"//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",
|
|
|
|
],
|
|
|
|
)
|