-
I have C++ module that I use pybind11_bazel to compile and then pass on to python rules and eventually generate a wheel. For one version - works great. The docs and examples show that you can use multiple versions of python using the extension with multiple calls to python.toolchain:
and then use like this:
This makes sense - but I can't seem to figure out how to access the equivalent of "@rules_python//python/cc:current_py_cc_headers" for different versions, which you need to pass on to pybind11 in order to have the correct headers for multi-version module builds. Any ideas? I can't seem to find any examples, and I am learning Bazel, so the source code still doesn't make sense to me yet beyond how to use it (limited). Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Thanks for giving current_py_cc_headers a try! It's the same target regardless of version. Using If you run |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation! I just figured out the right thing to do though after reading the docs a bit closer - this seems to get me there or at least - I don't get errors:
Then later:
I have some more experimenting to do, and I'd like to figure out how to wrap this up into a module extension so I could just do something like "pybind11.version = 3.8" and "pybind11.version=3.11" - but obviously - pybind11_bazel is a different project - I didn't want to ask to many questions about it here, but this, I think, is key to the interop. Thanks again - this is great work - BTW! Hopefully this little nugget helps someone. First steps would be duplication - similar to the multi-version example here. Later - figure out how to abstract it so I can just write "version=x.y" |
Beta Was this translation helpful? Give feedback.
-
Using If you're OK with having all consuming py_binary's closely coupled to the python version your pybind library, then it'll work ok. If you have potentially different (or unknowable in advance) python versions consuming your pybind library, then your best option is to use
The thing you want to do is use a transition to set the HTH |
Beta Was this translation helpful? Give feedback.
-
I totally agree with this. What I can't seem to figure out how to do is "switch" between python versions when building. For example - I'd like to create a wheel for python3.8 and a wheel for python3.11 - but I don't know how to get it to build for anything other than one of the python toolchains I declare. I can't seem to make the connection that allows me to switch toolchains. In the module, I can declare which versions I want to use, I see how to use it to switch between py_binary_X_Y, but I don't see how to pass that to pybind11.
BTW - thank you again for entertaining my questions - I realize I am basically asking how to use 2 rule sets that are not related maintainer-wise. |
Beta Was this translation helpful? Give feedback.
-
To switch, set the command line or use a transition. Command line: Set Transition: Right now, the only easy way to use the transitions is through the e.g. Note that you can only switch to a version that a toolchain has been declared for. |
Beta Was this translation helpful? Give feedback.
-
The command line worked perfectly. A few config settings that set the python wheel tags:
With a default value of 3.11, and I can build multiple versions! Thanks for your help getting me started. I can refine as I learn more - but this is really good - at least in my mind..... Thanks!!! |
Beta Was this translation helpful? Give feedback.
To switch, set the command line or use a transition.
Command line: Set
bazel build --@rules_python//python/config_settings:python_version=3.11 //my:pybind
Transition: Right now, the only easy way to use the transitions is through the e.g.
3.8.defs%py_binary
wrappers. Ideally, py_package/py_wheel would let you set the version directly via an attribute (PRs welcome to add such functionality). Otherwise, you have to write your own wrapper rule to do the transition; you can look at python/config_settings/transition.bzl as an example (its what the py_binary wrappers use).Note that you can only switch to a version that a toolchain has been declared for.