Exposed python headers from toolchains as cc_library (#666)
* Exposed python headers in hermetic toolchains
* Update naming
diff --git a/python/private/toolchains_repo.bzl b/python/private/toolchains_repo.bzl
index cbf0216..13a54aa 100644
--- a/python/private/toolchains_repo.bzl
+++ b/python/private/toolchains_repo.bzl
@@ -89,7 +89,9 @@
package(default_visibility = ["//visibility:public"])
exports_files(["defs.bzl"])
alias(name = "files", actual = "@{py_repository}_{host_platform}//:files")
+alias(name = "includes", actual = "@{py_repository}_{host_platform}//:includes")
alias(name = "py3_runtime", actual = "@{py_repository}_{host_platform}//:py3_runtime")
+alias(name = "python_headers", actual = "@{py_repository}_{host_platform}//:python_headers")
alias(name = "python_runtimes", actual = "@{py_repository}_{host_platform}//:python_runtimes")
alias(name = "python3", actual = "@{py_repository}_{host_platform}//:{python3_binary_path}")
""".format(
diff --git a/python/repositories.bzl b/python/repositories.bzl
index d4b113f..3575ea8 100644
--- a/python/repositories.bzl
+++ b/python/repositories.bzl
@@ -41,6 +41,7 @@
platform = rctx.attr.platform
python_version = rctx.attr.python_version
+ python_short_version = python_version.rpartition(".")[0]
release_filename = rctx.attr.release_filename
url = rctx.attr.url
@@ -88,7 +89,6 @@
if "windows" in rctx.os.name:
distutils_path = "Lib/distutils/distutils.cfg"
else:
- python_short_version = python_version.rpartition(".")[0]
distutils_path = "lib/python{}/distutils/distutils.cfg".format(python_short_version)
if rctx.attr.distutils:
rctx.file(distutils_path, rctx.read(rctx.attr.distutils))
@@ -130,6 +130,21 @@
),
)
+filegroup(
+ name = "includes",
+ srcs = glob(["include/**/*.h"]),
+)
+
+cc_library(
+ name = "python_headers",
+ hdrs = [":includes"],
+ includes = [
+ "include",
+ "include/python{python_version}",
+ "include/python{python_version}m",
+ ],
+)
+
exports_files(["{python_path}"])
py_runtime(
@@ -146,6 +161,7 @@
)
""".format(
python_path = python_bin,
+ python_version = python_short_version,
)
rctx.file("BUILD.bazel", build_content)