BUILD 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. load(
  26. "//bazel:build_defs.bzl",
  27. "UPB_DEFAULT_COPTS",
  28. )
  29. load(
  30. "//bazel:py_proto_library.bzl",
  31. "py_proto_library",
  32. )
  33. load(
  34. "@rules_python//python:packaging.bzl",
  35. "py_wheel",
  36. )
  37. cc_binary(
  38. name = "message",
  39. srcs = [
  40. "convert.c",
  41. "convert.h",
  42. "descriptor.c",
  43. "descriptor.h",
  44. "descriptor_containers.c",
  45. "descriptor_containers.h",
  46. "descriptor_pool.c",
  47. "descriptor_pool.h",
  48. "extension_dict.c",
  49. "extension_dict.h",
  50. "map.c",
  51. "map.h",
  52. "message.c",
  53. "message.h",
  54. "protobuf.c",
  55. "protobuf.h",
  56. "python.h",
  57. "repeated.c",
  58. "repeated.h",
  59. ],
  60. copts = UPB_DEFAULT_COPTS + [
  61. # The Python API requires patterns that are ISO C incompatible, like
  62. # casts between function pointers and object pointers.
  63. "-Wno-pedantic",
  64. ],
  65. # We use a linker script to hide all symbols except the entry point for
  66. # the module.
  67. linkopts = select({
  68. "@platforms//os:linux": ["-Wl,--version-script,$(location :version_script.lds)"],
  69. "@platforms//os:macos": ["-Wl,-exported_symbol", "-Wl,_PyInit__message"],
  70. }),
  71. linkshared = True,
  72. linkstatic = True,
  73. deps = [
  74. ":version_script.lds",
  75. "//:reflection",
  76. "//:textformat",
  77. "//:upb",
  78. "//:descriptor_upb_proto_reflection",
  79. "//upb/util:compare",
  80. "//upb/util:def_to_proto",
  81. "//upb/util:required_fields",
  82. "@system_python//:python_headers",
  83. ],
  84. )
  85. cc_binary(
  86. name = "api_implementation",
  87. srcs = [
  88. "api_implementation.c",
  89. ],
  90. # Enable once linker script is available.
  91. #copts = ["-fvisibility=hidden"],
  92. deps = ["@system_python//:python_headers"],
  93. linkshared = True,
  94. linkstatic = True,
  95. )
  96. # Copy the extensions into the location recognized by Python.
  97. # .abi3.so indicates use of the limited API, and cross-version ABI compatibility.
  98. EXT_SUFFIX = ".abi3.so"
  99. genrule(
  100. name = "copy_message",
  101. srcs = [":message"],
  102. outs = ["google/protobuf/pyext/_message" + EXT_SUFFIX],
  103. cmd = "cp $< $@",
  104. )
  105. genrule(
  106. name = "copy_api_implementation",
  107. srcs = [":api_implementation"],
  108. outs = ["google/protobuf/internal/_api_implementation" + EXT_SUFFIX],
  109. cmd = "cp $< $@",
  110. visibility = ["//python:__subpackages__"],
  111. )
  112. filegroup(
  113. name = "extension_files",
  114. srcs = [
  115. "google/protobuf/pyext/_message" + EXT_SUFFIX,
  116. "google/protobuf/internal/_api_implementation" + EXT_SUFFIX,
  117. ],
  118. )
  119. py_library(
  120. name = "message_ext",
  121. data = [":extension_files"],
  122. imports = ["."],
  123. visibility = ["//python:__subpackages__"],
  124. )
  125. py_test(
  126. name = "minimal_test",
  127. srcs = [
  128. "minimal_test.py",
  129. ],
  130. deps = [
  131. "//python:message_ext",
  132. "@com_google_protobuf//:python_srcs",
  133. "@com_google_protobuf//:python_common_test_protos",
  134. "@com_google_protobuf//:python_specific_test_protos",
  135. ],
  136. imports = ["."],
  137. legacy_create_init = False,
  138. )
  139. py_proto_library(
  140. name = "well_known_proto_pb2",
  141. deps = [
  142. "@com_google_protobuf//:any_proto",
  143. "@com_google_protobuf//:api_proto",
  144. "@com_google_protobuf//:compiler_plugin_proto",
  145. "@com_google_protobuf//:descriptor_proto",
  146. "@com_google_protobuf//:duration_proto",
  147. "@com_google_protobuf//:empty_proto",
  148. "@com_google_protobuf//:field_mask_proto",
  149. "@com_google_protobuf//:source_context_proto",
  150. "@com_google_protobuf//:struct_proto",
  151. "@com_google_protobuf//:timestamp_proto",
  152. "@com_google_protobuf//:type_proto",
  153. "@com_google_protobuf//:wrappers_proto",
  154. ],
  155. )
  156. py_wheel(
  157. name = "binary_wheel",
  158. abi = "abi3",
  159. distribution = "protobuf",
  160. python_tag = "cp36",
  161. # TODO(https://github.com/protocolbuffers/upb/issues/502): we need to make
  162. # this a select() that is calculated from the platform we are actually
  163. # building on.
  164. platform = "manylinux2014_x86_64",
  165. version = "4.20.0",
  166. strip_path_prefixes = ["python/"],
  167. deps = [
  168. ":extension_files",
  169. ":well_known_proto_pb2",
  170. # TODO(https://github.com/protocolbuffers/upb/issues/503): currently
  171. # this includes the unit tests. We should filter these out so we are
  172. # only distributing true source files.
  173. "@com_google_protobuf//:python_srcs",
  174. ],
  175. )