liningpan / pyo3-bazel-example

Apache License 2.0
8 stars 1 forks source link

Example of rust loading python and python loading rust? #2

Open sthornington opened 3 weeks ago

sthornington commented 3 weeks ago

Hi! Thanks for all your work on this. Could you point me to an example of using these rules to:

  1. make a rust binary which loads a python script to call a python function?
  2. make a python extension module in rust to load and call from python?

I'm having some difficulty doing both in the same build since crate_universe wants to make the union of the pyo3 features, and if I am not mistaken, the former needs pyo3 without extension-module and the latter needs it with extension-module ?

liningpan commented 1 week ago

This repository basically shows your second use case, or calling an extension module written in rust from python. The extension-module feature flag is declared in Cargo.toml file and translated by rules_rust crate_universe system.

I don't have any experience with your first use case. I suspect that it won't be easy with bazel and might require some runfiles hacks.

sthornington commented 1 week ago

I think I got it working by using the extension-module feature but then in my rust binary that needed to host a Python plugin, linking in the Python toolchain cc deps manually. But I am not confident that it’s all correct and linking to the right things yet…