File: python_downloads.bzl

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (7)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Helper methods to download different python versions"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

limited_api_build_file = """
cc_library(
    name = "python_headers",
    hdrs = glob(["**/Include/**/*.h"]),
    strip_include_prefix = "Python-{}/Include",
    visibility = ["//visibility:public"],
)
"""

def python_source_archive(name, sha256):
    """Helper method to create a python_headers target that will work for linux and macos.

    Args:
      name: The name of the target, should be in the form python_{VERSION}
      sha256: The sha256 of the python package for the specified version
    """
    version = name.split("-")[1]
    http_archive(
        name = name,
        urls = [
            "https://www.python.org/ftp/python/{0}/Python-{0}.tgz"
                .format(version),
        ],
        sha256 = sha256,
        build_file_content = limited_api_build_file.format(version),
        patch_cmds = [
            "echo '#define SIZEOF_WCHAR_T 4' > Python-{}/Include/pyconfig.h"
                .format(version),
        ],
    )

nuget_build_file = """
cc_import(
    name = "python_full_api",
    hdrs = glob(["**/*.h"]),
    shared_library = "python{0}.dll",
    interface_library = "libs/python{0}.lib",
    visibility = ["@com_google_protobuf//python:__pkg__"],
)

cc_import(
    name = "python_limited_api",
    hdrs = glob(["**/*.h"]),
    shared_library = "python{1}.dll",
    interface_library = "libs/python{1}.lib",
    visibility = ["@com_google_protobuf//python:__pkg__"],
)
"""

def python_nuget_package(name, sha256):
    """Helper method to create full and limited api dependencies for windows using nuget

    Args:
      name: The name of the target, should be in the form nuget_python_{CPU}_{VERSION}
      sha256: The sha256 of the nuget package for that version
    """
    cpu = name.split("_")[2]
    version = name.split("_")[3]

    full_api_lib_number = version.split(".")[0] + version.split(".")[1]
    limited_api_lib_number = version.split(".")[0]

    folder_name_dict = {
        "i686": "pythonx86",
        "x86-64": "python",
    }

    http_archive(
        name = name,
        urls = [
            "https://www.nuget.org/api/v2/package/{}/{}"
                .format(folder_name_dict[cpu], version),
        ],
        sha256 = sha256,
        strip_prefix = "tools",
        build_file_content =
            nuget_build_file.format(full_api_lib_number, limited_api_lib_number),
        type = "zip",
        patch_cmds = ["cp -r include/* ."],
    )