abrisco / rules_pyo3

Bazel rules for PyO3
MIT License
3 stars 0 forks source link

How to add pyo3 features #21

Open nudowding opened 4 days ago

nudowding commented 4 days ago

Not sure if this is not implemented, or I just couldn't figure out how to do this.

I need to add the pyo3 feature 'chrono' to include the IntoPy<PyObject> for chrono::NaiveDate.

Is there way to do this when setting up the workspace or specifying the pyo3_extension. If that is not available, it would be a nice thing to add, but not urgent. For now I'm going to wrap the NaiveDates with a local struct.

There is a list of optional features at the bottom of this page https://pyo3.rs/v0.22.3/conversions/tables

abrisco commented 4 days ago

Howdy! Thanks for the post!

For folks who want to customize features on the PyO3 crate should define their own toolchains which is generally fairly simple.

I've defined some simple ones here: https://github.com/abrisco/rules_pyo3/blob/1b5108be33ffa462ce56b5c3a66864e229ca86aa/pyo3/toolchains/BUILD.bazel#L1-L30

But really all this is powered by crates_universe which I've used here: https://github.com/abrisco/rules_pyo3/blob/1b5108be33ffa462ce56b5c3a66864e229ca86aa/pyo3/3rdparty/BUILD.bazel#L1-L65

If you're calling register_pyo3_toolchains in your WORKSPACE file then you'll wanna set register_toolchains = False and then register the one you made so there's no conflicts in toolchain resolution https://github.com/abrisco/rules_pyo3/blob/1b5108be33ffa462ce56b5c3a66864e229ca86aa/pyo3/repositories.bzl#L35

So all that's to say, I think what you want is already implemented and the toolchains are designed to let you customize PyO3. Does that give you something to try and let me know how it goes?

nudowding commented 4 days ago

Ok, let me give that a try. I will probably have some more questions.