File: py_extension.bzl

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (60 lines) | stat: -rw-r--r-- 2,035 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Macro to support py_extension """

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_python//python:py_library.bzl", "py_library")

def py_extension(name, srcs, copts, deps = [], **kwargs):
    """Creates a C++ library to extend python

    Args:
      name: Name of the target
      srcs: List of source files to create the target
      copts: List of C++ compile options to use
      deps: Libraries that the target depends on
    """

    native.cc_binary(
        name = name + "_binary",
        srcs = srcs,
        copts = copts + ["-fvisibility=hidden"],
        linkopts = selects.with_or({
            (
                "//python/dist:osx_x86_64",
                "//python/dist:osx_aarch64",
            ): ["-Wl,-undefined,dynamic_lookup"],
            "//python/dist:windows_x86_32": ["-static-libgcc"],
            "//conditions:default": [],
        }),
        linkshared = True,
        linkstatic = True,
        deps = deps + select({
            "//python:limited_api_3.9": ["@python-3.9.0//:python_headers"],
            "//python:full_api_3.9_win32": ["@nuget_python_i686_3.9.0//:python_full_api"],
            "//python:full_api_3.9_win64": ["@nuget_python_x86-64_3.9.0//:python_full_api"],
            "//python:limited_api_3.10_win32": ["@nuget_python_i686_3.10.0//:python_limited_api"],
            "//python:limited_api_3.10_win64": ["@nuget_python_x86-64_3.10.0//:python_limited_api"],
            "//conditions:default": ["@system_python//:python_headers"],
        }),
        **kwargs
    )

    EXT_SUFFIX = ".abi3.so"
    output_file = "google/_upb/" + name + EXT_SUFFIX

    native.genrule(
        name = "copy" + name,
        srcs = [":" + name + "_binary"],
        outs = [output_file],
        cmd = "cp $< $@",
        visibility = ["//python:__subpackages__"],
    )

    py_library(
        name = name,
        data = [output_file],
        imports = ["."],
        visibility = [
            "//python:__subpackages__",
            "//conformance:__pkg__",
        ],
    )