• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1licenses(["restricted"])
2
3package(default_visibility = ["//visibility:public"])
4
5# Point both runtimes to the same python binary to ensure we always
6# use the python binary specified by ./configure.py script.
7load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
8
9py_runtime(
10    name = "py2_runtime",
11    interpreter_path = "%{PYTHON_BIN_PATH}",
12    python_version = "PY2",
13)
14
15py_runtime(
16    name = "py3_runtime",
17    interpreter_path = "%{PYTHON_BIN_PATH}",
18    python_version = "PY3",
19)
20
21py_runtime_pair(
22    name = "py_runtime_pair",
23    py2_runtime = ":py2_runtime",
24    py3_runtime = ":py3_runtime",
25)
26
27toolchain(
28    name = "py_toolchain",
29    toolchain = ":py_runtime_pair",
30    toolchain_type = "@bazel_tools//tools/python:toolchain_type",
31    target_compatible_with = [%{PLATFORM_CONSTRAINT}],
32    exec_compatible_with = [%{PLATFORM_CONSTRAINT}],
33)
34
35# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib
36# See https://docs.python.org/3/extending/windows.html
37cc_import(
38    name = "python_lib",
39    interface_library = select({
40        ":windows": ":python_import_lib",
41        # A placeholder for Unix platforms which makes --no_build happy.
42        "//conditions:default": "not-existing.lib",
43    }),
44    system_provided = 1,
45)
46
47cc_library(
48    name = "python_headers",
49    hdrs = [":python_include"],
50    deps = select({
51        ":windows": [":python_lib"],
52        "//conditions:default": [],
53    }),
54    includes = ["python_include"],
55)
56
57cc_library(
58    name = "numpy_headers",
59    hdrs = [":numpy_include"],
60    includes = ["numpy_include"],
61)
62
63config_setting(
64    name = "windows",
65    values = {"cpu": "x64_windows"},
66    visibility = ["//visibility:public"],
67)
68
69%{PYTHON_INCLUDE_GENRULE}
70%{NUMPY_INCLUDE_GENRULE}
71%{PYTHON_IMPORT_LIB_GENRULE}
72