diff --git a/python/private/toolchains_repo.bzl b/python/private/toolchains_repo.bzl index cbf02160c7..13a54aa7e1 100644 --- a/python/private/toolchains_repo.bzl +++ b/python/private/toolchains_repo.bzl @@ -89,7 +89,9 @@ def _resolved_interpreter_os_alias_impl(rctx): 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 d4b113f596..3575ea8267 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -41,6 +41,7 @@ def _python_repository_impl(rctx): 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 @@ def _python_repository_impl(rctx): 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( ), ) +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 @@ py_runtime_pair( ) """.format( python_path = python_bin, + python_version = python_short_version, ) rctx.file("BUILD.bazel", build_content)