Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compile errors for abi3 builds #8

Open
mladedav opened this issue Sep 29, 2022 · 4 comments
Open

Add compile errors for abi3 builds #8

mladedav opened this issue Sep 29, 2022 · 4 comments

Comments

@mladedav
Copy link

This crate depends on traits that state Available on non-Py_LIMITED_API only. This basically means that pyo3 must not have the abi3 feature enabled as far as I understand it, but my knowledge here is limited.

If there is a good reason for this, I would propose to at least add compile_error! macros to the crate because now I was left a bit stumped when the compilation of pyo3-chrono failed with 10 errors about non-existing types from pyo3.

An example of the error (there are more but basically the same with different types):

error[E0432]: unresolved imports `pyo3::types::PyDateAccess`, `pyo3::types::PyDeltaAccess`, `pyo3::types::PyTimeAccess`
  --> ...\.cargo\registry\src\github.com-1ecc6299db9ec823\pyo3-chrono-0.5.0\src\lib.rs:33:19
   |
33 | use pyo3::types::{PyDateAccess as _, PyDeltaAccess as _, PyTimeAccess as _};
   |                   ^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^ no `PyTimeAccess` in `types`
   |                   |                  |
   |                   |                  no `PyDeltaAccess` in `types`
   |                   no `PyDateAccess` in `types`
@mladedav
Copy link
Author

I've just noticed that PyDateTime itself is available only non Py_LIMITED_API. That sounds like an obvious reason why this cannot work so the compile_error would be just a nice quality of life improvement for unsuspecting users.

@kangalio
Copy link
Owner

The Py_LIMITED_API cfg is generated in pyo3's build.rs and doesn't apply to dependent crates like pyo3-chrono. And we can't check the abi3 feature either because crates can only gate on their own features: #[cfg(feature = "pyo3/abi3")] does nothing.

I don't think there's anything pyo3-chrono can reasonably implement to catch this error. Except note the gotcha in the documentation, I guess

@kangalio
Copy link
Owner

Folks on the Rust community server said the following (link):

there is this you might be able to parse something out of

"DEP_PYTHON_PYO3_CONFIG",
"696d706c656d656e746174696f6e3d43507974686f6e0a76657273696f6e3d332e31300a7368617265643d747275650a616269333d747275650a6c69625f6e616d653d707974686f6e332e31300a6c69625f6469723d2f7573722f6c69620a657865637574
61626c653d2f7573722f62696e2f707974686f6e0a706f696e7465725f77696474683d36340a6275696c645f666c6167733d0a73757070726573735f6275696c645f7363726970745f6c696e6b5f6c696e65733d66616c73650a",

you need a build script i think
and rely on https://docs.rs/pyo3-build-config/latest/pyo3_build_config/

pyo3 will support chrono itself in a future release, so you could also just tell them to use the master branch

Soo, try the master branch of pyo3 I guess?

@mladedav
Copy link
Author

Thanks for the response, especially for going the extra mile by looking for alternative solutions.

I didn't realize we can't check for features of dependencies. I'd say that pyo3_build_config would be the best way to go as it seems that it exists exactly for cases like this.

I've seen some issues in pyo3 from which it seemed like the maintainers explicitly do not want to support chrono directly but I might have overlooked some later issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants