Debian Codegraph @

third_party/upb/python/py_extension.bzl

raw
1 """Macro to support py_extension """
2
3 load("@bazel_skylib//lib:selects.bzl", "selects")
4
5 def py_extension(name, srcs, copts, deps = []):
6 """Creates a C++ library to extend python
7
8 Args:
9 name: Name of the target
10 srcs: List of source files to create the target
11 copts: List of C++ compile options to use
12 deps: Libraries that the target depends on
13 """
14
15 native.cc_binary(
16 name = name + "_binary",
17 srcs = srcs,
18 copts = copts + ["-fvisibility=hidden"],
19 linkopts = selects.with_or({
20 (
21 "//python/dist:osx-x86_64_cpu",
22 "//python/dist:osx-aarch64_cpu",
23 ): ["-undefined", "dynamic_lookup"],
24 "//python/dist:win32_cpu": ["-static-libgcc"],
25 "//conditions:default": [],
26 }),
27 linkshared = True,
28 linkstatic = True,
29 deps = deps + select({
30 "//python:limited_api_3.7": ["@python-3.7.0//:python_headers"],
31 "//python:full_api_3.7_win32": ["@nuget_python_i686_3.7.0//:python_full_api"],
32 "//python:full_api_3.7_win64": ["@nuget_python_x86-64_3.7.0//:python_full_api"],
33 "//python:full_api_3.8_win32": ["@nuget_python_i686_3.8.0//:python_full_api"],
34 "//python:full_api_3.8_win64": ["@nuget_python_x86-64_3.8.0//:python_full_api"],
35 "//python:full_api_3.9_win32": ["@nuget_python_i686_3.9.0//:python_full_api"],
36 "//python:full_api_3.9_win64": ["@nuget_python_x86-64_3.9.0//:python_full_api"],
37 "//python:limited_api_3.10_win32": ["@nuget_python_i686_3.10.0//:python_limited_api"],
38 "//python:limited_api_3.10_win64": ["@nuget_python_x86-64_3.10.0//:python_limited_api"],
39 "//conditions:default": ["@system_python//:python_headers"],
40 }),
41 )
42
43 EXT_SUFFIX = ".abi3.so"
44 output_file = "google/_upb/" + name + EXT_SUFFIX
45
46 native.genrule(
47 name = "copy" + name,
48 srcs = [":" + name + "_binary"],
49 outs = [output_file],
50 cmd = "cp $< $@",
51 visibility = ["//python:__subpackages__"],
52 )
53
54 native.py_library(
55 name = name,
56 data = [output_file],
57 imports = ["."],
58 visibility = ["//python:__subpackages__"],
59 )