Skip to content

python and rust interoperability #2465

@johnynek

Description

@johnynek

The PyO3 library provides a tool, maturin to help in connecting python and rust. Using that tool in a bazel repo opens a lot of new challenged in that it is suggested to be installed with pip and ideally we want a hermetic and reproducible build. Even if that part is tractable, it is still not a solved problem how to link the libraries.

It would be great to have some rules like:

rust_library(
    name = "string_sum",
    srcs = ["string_sum.rs"],
) 

py_rust_library(
    name = "py_string_sum",
    srcs = [], # optionally some additional python code
    deps = [":string_sum"], # either rust_library or py_library dependencies here
)

py_library(
    name = "some_python",
    srcs = ...
)

rust_py_library(
    name = "call_some_py",
    srcs = [], # optionally some rust code here to wrap calling python
    deps = [":some_python", ... ] # we can depend on py_library or rust_library here
)

It seems like putting a solution to this in these rules is the right place for it since I think it would need to interop pretty tightly with rules_rust and maybe less tightly with rules_python (which are still just a wrapper of native python support). On the python side, it seems PyInfo provider may be enough to make things work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions