aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/py
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2018-03-06 18:48:01 +0100
committerGravatar Gunhan Gulsoy <gunan@google.com>2018-03-06 09:48:01 -0800
commit1f441c191f9a6d8f27b32b1c19c55f76aaf9e387 (patch)
tree153d9b0f4bb680fb4c7ed16fd35a709099f08347 /third_party/py
parentc6a12c77a50778e28de3590f4618bc2b62f3ecab (diff)
Windows: Use cc_import to import python lib properly (#17474)
Previously, we put python.lib in data attribute of a cc_library and manually added the link option. That caused the build to be non-hermetic. This change fixed the problem.
Diffstat (limited to 'third_party/py')
-rw-r--r--third_party/py/BUILD.tpl22
1 files changed, 14 insertions, 8 deletions
diff --git a/third_party/py/BUILD.tpl b/third_party/py/BUILD.tpl
index de06ad5f27..1dd8ab433a 100644
--- a/third_party/py/BUILD.tpl
+++ b/third_party/py/BUILD.tpl
@@ -2,20 +2,26 @@ licenses(["restricted"])
package(default_visibility = ["//visibility:public"])
+# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib
+# See https://docs.python.org/3/extending/windows.html
+cc_import(
+ name = "python_lib",
+ interface_library = select({
+ ":windows": ":python_import_lib",
+ # A placeholder for Unix platforms which makes --no_build happy.
+ "//conditions:default": "not-existing.lib",
+ }),
+ system_provided = 1,
+)
+
cc_library(
name = "python_headers",
hdrs = [":python_include"],
- data = select({
- ":windows": [":python_import_lib"],
+ deps = select({
+ ":windows": [":python_lib"],
"//conditions:default": [],
}),
includes = ["python_include"],
- linkopts = select({
- # TODO(pcloudy): Ideally, this should just go into deps after resolving
- # https://github.com/bazelbuild/bazel/issues/3237,
- ":windows": ["$(locations :python_import_lib)"],
- "//conditions:default": [],
- }),
)
cc_library(