Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit deb43b0

Browse files
authored
Exposed python headers from toolchains as cc_library (bazel-contrib#666)
* Exposed python headers in hermetic toolchains * Update naming
1 parent fe30f15 commit deb43b0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

python/private/toolchains_repo.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def _resolved_interpreter_os_alias_impl(rctx):
8989
package(default_visibility = ["//visibility:public"])
9090
exports_files(["defs.bzl"])
9191
alias(name = "files", actual = "@{py_repository}_{host_platform}//:files")
92+
alias(name = "includes", actual = "@{py_repository}_{host_platform}//:includes")
9293
alias(name = "py3_runtime", actual = "@{py_repository}_{host_platform}//:py3_runtime")
94+
alias(name = "python_headers", actual = "@{py_repository}_{host_platform}//:python_headers")
9395
alias(name = "python_runtimes", actual = "@{py_repository}_{host_platform}//:python_runtimes")
9496
alias(name = "python3", actual = "@{py_repository}_{host_platform}//:{python3_binary_path}")
9597
""".format(

python/repositories.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _python_repository_impl(rctx):
4141

4242
platform = rctx.attr.platform
4343
python_version = rctx.attr.python_version
44+
python_short_version = python_version.rpartition(".")[0]
4445
release_filename = rctx.attr.release_filename
4546
url = rctx.attr.url
4647

@@ -88,7 +89,6 @@ def _python_repository_impl(rctx):
8889
if "windows" in rctx.os.name:
8990
distutils_path = "Lib/distutils/distutils.cfg"
9091
else:
91-
python_short_version = python_version.rpartition(".")[0]
9292
distutils_path = "lib/python{}/distutils/distutils.cfg".format(python_short_version)
9393
if rctx.attr.distutils:
9494
rctx.file(distutils_path, rctx.read(rctx.attr.distutils))
@@ -130,6 +130,21 @@ filegroup(
130130
),
131131
)
132132
133+
filegroup(
134+
name = "includes",
135+
srcs = glob(["include/**/*.h"]),
136+
)
137+
138+
cc_library(
139+
name = "python_headers",
140+
hdrs = [":includes"],
141+
includes = [
142+
"include",
143+
"include/python{python_version}",
144+
"include/python{python_version}m",
145+
],
146+
)
147+
133148
exports_files(["{python_path}"])
134149
135150
py_runtime(
@@ -146,6 +161,7 @@ py_runtime_pair(
146161
)
147162
""".format(
148163
python_path = python_bin,
164+
python_version = python_short_version,
149165
)
150166
rctx.file("BUILD.bazel", build_content)
151167

0 commit comments

Comments
 (0)