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 57# This alias is exists for the use of targets in the @llvm-project dependency, 58# which expect a python_headers target called @python_runtime//:headers. We use 59# a repo_mapping to alias python_runtime to this package, and an alias to create 60# the correct target. 61alias( 62 name = "headers", 63 actual = ":python_headers", 64) 65 66cc_library( 67 name = "numpy_headers", 68 hdrs = [":numpy_include"], 69 includes = ["numpy_include"], 70) 71 72config_setting( 73 name = "windows", 74 values = {"cpu": "x64_windows"}, 75 visibility = ["//visibility:public"], 76) 77 78%{PYTHON_INCLUDE_GENRULE} 79%{NUMPY_INCLUDE_GENRULE} 80%{PYTHON_IMPORT_LIB_GENRULE} 81