|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +licenses(["restricted"]) |
| 15 | + |
| 16 | +package(default_visibility = ["//visibility:public"]) |
| 17 | + |
| 18 | +# Point both runtimes to the same python binary to ensure we always |
| 19 | +# use the python binary specified by ./configure.py script. |
| 20 | +load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") |
| 21 | + |
| 22 | +py_runtime( |
| 23 | + name = "py2_runtime", |
| 24 | + interpreter_path = "%{PYTHON_BIN_PATH}", |
| 25 | + python_version = "PY2", |
| 26 | +) |
| 27 | + |
| 28 | +py_runtime( |
| 29 | + name = "py3_runtime", |
| 30 | + interpreter_path = "%{PYTHON_BIN_PATH}", |
| 31 | + python_version = "PY3", |
| 32 | +) |
| 33 | + |
| 34 | +py_runtime_pair( |
| 35 | + name = "py_runtime_pair", |
| 36 | + py2_runtime = ":py2_runtime", |
| 37 | + py3_runtime = ":py3_runtime", |
| 38 | +) |
| 39 | + |
| 40 | +toolchain( |
| 41 | + name = "py_toolchain", |
| 42 | + toolchain = ":py_runtime_pair", |
| 43 | + toolchain_type = "@bazel_tools//tools/python:toolchain_type", |
| 44 | + target_compatible_with = [%{PLATFORM_CONSTRAINT}], |
| 45 | + exec_compatible_with = [%{PLATFORM_CONSTRAINT}], |
| 46 | +) |
| 47 | + |
| 48 | +# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib |
| 49 | +# See https://docs.python.org/3/extending/windows.html |
| 50 | +cc_import( |
| 51 | + name = "python_lib", |
| 52 | + interface_library = select({ |
| 53 | + ":windows": ":python_import_lib", |
| 54 | + # A placeholder for Unix platforms which makes --no_build happy. |
| 55 | + "//conditions:default": "not-existing.lib", |
| 56 | + }), |
| 57 | + system_provided = 1, |
| 58 | +) |
| 59 | + |
| 60 | +cc_library( |
| 61 | + name = "python_headers", |
| 62 | + hdrs = [":python_include"], |
| 63 | + deps = select({ |
| 64 | + ":windows": [":python_lib"], |
| 65 | + "//conditions:default": [], |
| 66 | + }), |
| 67 | + includes = ["python_include"], |
| 68 | +) |
| 69 | + |
| 70 | +cc_library( |
| 71 | + name = "numpy_headers", |
| 72 | + hdrs = [":numpy_include"], |
| 73 | + includes = ["numpy_include"], |
| 74 | +) |
| 75 | + |
| 76 | +config_setting( |
| 77 | + name = "windows", |
| 78 | + values = {"cpu": "x64_windows"}, |
| 79 | + visibility = ["//visibility:public"], |
| 80 | +) |
| 81 | + |
| 82 | +%{PYTHON_INCLUDE_GENRULE} |
| 83 | +%{NUMPY_INCLUDE_GENRULE} |
| 84 | +%{PYTHON_IMPORT_LIB_GENRULE} |
0 commit comments