"""Tink rules for python."""

def tink_pybind_extension(
        name,
        srcs = [],
        hdrs = [],
        copts = [],
        features = ["-use_header_modules"],
        deps = []):
    """
    Pybind Extension for Tink.

    Creates Bazel targets for a pybind module:
    - A py_library with the taret name
    - A cc_binary with the target name.so
    - A cc_library with the target name_cc

    Args:
      name: name of the target
      srcs: source files corresponding to the target
      hdrs: header files corresponding to the target
      copts: flags for the compiler
      features: features enabled for Bazel
      deps: dependencies of the target

    Returns:
      A py_library target.
    """
    shared_lib_name = name + ".so"
    cc_library_name = name + "_cc"
    native.cc_binary(
        name = shared_lib_name,
        linkshared = 1,
        linkstatic = 1,
        srcs = srcs + hdrs,
        copts = copts,
        features = features,
        deps = deps,
    )
    native.cc_library(
        name = cc_library_name,
        srcs = srcs,
        hdrs = hdrs,
        deps = deps,
        alwayslink = True,
    )
    return native.py_library(
        name = name,
        data = [shared_lib_name],
    )

def tink_pybind_library(
        name,
        copts = [],
        features = ["-use_header_modules"],
        tags = [],
        deps = [],
        **kwargs):
    native.cc_library(
        name = name,
        copts = copts,
        features = features,
        tags = tags,
        deps = deps,
        **kwargs
    )

@@ -1146,18 +1146,119 @@
   )%0A
+%0A
     
-return
+# Extract Python targets from deps%0A    pybind_deps = %5Bdep%5B:-3%5D for dep in deps if dep.endswith(%22_cc%22)%5D%0A   
  nat
@@ -1328,16 +1328,44 @@
 _name%5D,%0A
+        deps = pybind_deps,%0A
     )%0A%0Ad

Fix tink_pybind_extension to include python dependencies for python targets.