2019-11-21 15:32:48 -08:00
|
|
|
diff --git bazel/cython_library.bzl bazel/cython_library.bzl
|
2019-12-10 20:33:24 +08:00
|
|
|
index 48b41d74e8..a9bc168e5d 100644
|
2019-11-21 15:32:48 -08:00
|
|
|
--- bazel/cython_library.bzl
|
|
|
|
+++ bazel/cython_library.bzl
|
2019-12-10 20:33:24 +08:00
|
|
|
@@ -7,18 +7,20 @@
|
2019-11-21 15:32:48 -08:00
|
|
|
# been written at cython/cython and tensorflow/tensorflow. We branch from
|
|
|
|
# Tensorflow's version as it is more actively maintained and works for gRPC
|
|
|
|
# Python's needs.
|
|
|
|
-def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
|
2019-12-10 20:33:24 +08:00
|
|
|
+def pyx_library(name, deps=[], copts=[], cc_kwargs={}, py_deps=[], srcs=[], **kwargs):
|
2019-11-21 15:32:48 -08:00
|
|
|
"""Compiles a group of .pyx / .pxd / .py files.
|
2019-12-10 20:33:24 +08:00
|
|
|
|
2019-11-21 15:32:48 -08:00
|
|
|
First runs Cython to create .cpp files for each input .pyx or .py + .pxd
|
2019-12-10 20:33:24 +08:00
|
|
|
- pair. Then builds a shared object for each, passing "deps" to each cc_binary
|
|
|
|
- rule (includes Python headers by default). Finally, creates a py_library rule
|
|
|
|
- with the shared objects and any pure Python "srcs", with py_deps as its
|
|
|
|
- dependencies; the shared objects can be imported like normal Python files.
|
|
|
|
+ pair. Then builds a shared object for each, passing "deps" and `**cc_kwargs`
|
|
|
|
+ to each cc_binary rule (includes Python headers by default). Finally, creates
|
|
|
|
+ a py_library rule with the shared objects and any pure Python "srcs", with py_deps
|
|
|
|
+ as its dependencies; the shared objects can be imported like normal Python files.
|
|
|
|
|
2019-11-21 15:32:48 -08:00
|
|
|
Args:
|
|
|
|
name: Name for the rule.
|
|
|
|
deps: C/C++ dependencies of the Cython (e.g. Numpy headers).
|
|
|
|
+ copts: C/C++ compiler options for Cython
|
2019-12-10 20:33:24 +08:00
|
|
|
+ cc_kwargs: cc_binary extra arguments such as linkstatic, linkopts, features
|
2019-11-21 15:32:48 -08:00
|
|
|
py_deps: Pure Python dependencies of the final library.
|
|
|
|
srcs: .py, .pyx, or .pxd files to either compile or pass through.
|
|
|
|
**kwargs: Extra keyword arguments passed to the py_library.
|
2019-12-10 20:33:24 +08:00
|
|
|
@@ -57,9 +59,11 @@ def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
|
|
|
|
shared_object_name = stem + ".so"
|
2019-11-21 15:32:48 -08:00
|
|
|
native.cc_binary(
|
|
|
|
name=shared_object_name,
|
2019-12-10 20:33:24 +08:00
|
|
|
- srcs=[stem + ".cpp"],
|
|
|
|
+ srcs=[stem + ".cpp"] + cc_kwargs.pop("srcs", []),
|
2019-11-21 15:32:48 -08:00
|
|
|
+ copts=copts,
|
|
|
|
deps=deps + ["@local_config_python//:python_headers"],
|
|
|
|
linkshared=1,
|
2019-12-10 20:33:24 +08:00
|
|
|
+ **cc_kwargs
|
2019-11-21 15:32:48 -08:00
|
|
|
)
|
2019-12-10 20:33:24 +08:00
|
|
|
shared_objects.append(shared_object_name)
|
|
|
|
|
|
|
|
@@ -72,3 +76,4 @@ def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
|
|
|
|
data=shared_objects,
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
+
|
|
|
|
--
|