bazel: Cleanup and fix python support

This commit is contained in:
Mizux Seiha
2022-04-12 15:48:21 +02:00
parent 885d26853b
commit 800df7b60b
3 changed files with 49 additions and 12 deletions

View File

@@ -19,13 +19,6 @@ git_repository(
remote = "https://github.com/bazelbuild/platforms.git",
)
# Bazel Python rules.
git_repository(
name = "rules_python",
tag = "0.6.0",
remote = "https://github.com/bazelbuild/rules_python.git",
)
# Abseil-cpp
git_repository(
name = "com_google_absl",
@@ -105,11 +98,12 @@ cc_library(
"""
)
http_archive(
# Python
## Bazel Python rules.
git_repository(
name = "rules_python",
sha256 = "9fcf91dbcc31fde6d1edb15f117246d912c33c36f44cf681976bd886538deba6",
strip_prefix = "rules_python-0.8.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.0.tar.gz",
tag = "0.8.0",
remote = "https://github.com/bazelbuild/rules_python.git",
)
load("@rules_python//python:pip.bzl", "pip_install")
@@ -124,13 +118,15 @@ pip_install(
git_repository(
name = "pybind11_bazel",
commit = "72cbbf1fbc830e487e3012862b7b720001b70672",
patches = ["//patches:pybind11_bazel.patch"], # see pybind/pybind11_bazel#38
patch_args = ["-p1"],
remote = "https://github.com/pybind/pybind11_bazel.git",
)
new_git_repository(
name = "pybind11",
build_file = "@pybind11_bazel//:pybind11.BUILD",
tag = "v2.9.1",
tag = "v2.9.2",
remote = "https://github.com/pybind/pybind11.git",
)

View File

@@ -1,3 +1,4 @@
exports_files([
"re2-2022-02-01.patch",
"pybind11_bazel.patch",
])

View File

@@ -0,0 +1,40 @@
diff --git a/python_configure.bzl b/python_configure.bzl
index 1f5bffa..7809dce 100644
--- a/python_configure.bzl
+++ b/python_configure.bzl
@@ -213,8 +213,14 @@ def _get_python_lib(repository_ctx, python_bin):
"try:\n" +
" library_paths = site.getsitepackages()\n" +
"except AttributeError:\n" +
- " from distutils.sysconfig import get_python_lib\n" +
- " library_paths = [get_python_lib()]\n" +
+ " import sys\n" +
+ " USE_SYSCONFIG = sys.version_info >= (3, 10)\n" +
+ " if not USE_SYSCONFIG:\n" +
+ " from distutils import sysconfig as ds\n" +
+ " library_paths = [ds.get_python_lib(plat_specific=True)]\n" +
+ " else:\n" +
+ " import sysconfig as s\n" +
+ " library_paths = [s.get_path('platlib')]\n" +
"all_paths = set(python_paths + library_paths)\n" +
"paths = []\n" +
"for path in all_paths:\n" +
@@ -251,9 +257,15 @@ def _get_python_include(repository_ctx, python_bin):
[
python_bin,
"-c",
- "from __future__ import print_function;" +
- "from distutils import sysconfig;" +
- "print(sysconfig.get_python_inc())",
+ "from __future__ import print_function\n" +
+ "import sys\n" +
+ "USE_SYSCONFIG = sys.version_info >= (3, 10)\n" +
+ "if not USE_SYSCONFIG:\n" +
+ " from distutils import sysconfig as ds\n" +
+ " print(ds.get_python_inc(plat_specific=True))\n" +
+ "else:\n" +
+ " import sysconfig as s\n" +
+ " print(s.get_path('platinclude'))\n",
],
error_msg = "Problem getting python include path.",
error_details = ("Is the Python binary path set up right? " +