From ae160982e3109cafe5caf3d689e0c9d879f46083 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 18 Aug 2021 16:45:42 -0700 Subject: [PATCH] Fixed the Python system headers rule. It now usse python sysconfig to find the include directory. --- bazel/workspace_defs.bzl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bazel/workspace_defs.bzl b/bazel/workspace_defs.bzl index 1706d61fe3..18d985fdad 100644 --- a/bazel/workspace_defs.bzl +++ b/bazel/workspace_defs.bzl @@ -35,12 +35,11 @@ cc_library( """ def _find_python_dir(repository_ctx): - versions = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] - for version in versions: - path = "/usr/include/python" + version - if repository_ctx.path(path + "/" + "Python.h").exists: - return path - fail("No Python headers found in /usr/include/python3.* (require 3.6 or newer)") + py_program = "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'), end='')" + result = repository_ctx.execute(["python3", "-c", py_program]) + if result.return_code != 0: + fail("No python3 executable available on the system") + return result.stdout def _python_headers_impl(repository_ctx): path = _find_python_dir(repository_ctx) @@ -61,9 +60,8 @@ def _python_headers_impl(repository_ctx): # deps = ["@python_headers_repo//:python_headers"], # ) # -# The headers will be from any version of Python >=3.6. This is intended for -# use with the Python "limited API," which only exposes symbols that are ABI -# compatible from version to version. +# The headers should correspond to the version of python obtained by running +# the `python3` command on the system. python_headers = repository_rule( implementation = _python_headers_impl, local = True,