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

pyo3 fails to build on systems without AtomicI64 #4153

Closed
he32 opened this issue May 3, 2024 · 7 comments
Closed

pyo3 fails to build on systems without AtomicI64 #4153

he32 opened this issue May 3, 2024 · 7 comments

Comments

@he32
Copy link

he32 commented May 3, 2024

An attempt to build pyo3 on a system where the CPU does not provide 64-bit atomic operations (exemplified by 32-bit PowerPC), that results in

error[E0432]: unresolved import `std::sync::atomic::AtomicI64`
 --> /usr/pkgsrc/security/py-bcrypt/work/vendor/pyo3-0.20.0/src/impl_/pymodule.rs:6:25
  |
6 | use std::sync::atomic::{AtomicI64, Ordering};
  |                         ^^^^^^^^^
  |                         |
  |                         no `AtomicI64` in `sync::atomic`
  |                         help: a similar name exists in the module: `AtomicI32`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `pyo3` (lib) due to previous error

It seems to me that pymodule.rs has some checking whether the target supports 64-bit atomics, but then goes on to insist on using AtomicI64 in both "branches" of that test. Is this intentional or is it accidental and fixable?

@adamreichold
Copy link
Member

This is already fixed in the current stable version 0.21.x where we rely on the portable-atomics crates to provide a polyfill on platforms that do not support the relevant atomic types natively. (This is also what you are seeing in the code of the main branch, we always use AtomicI64, but it might be a fallback provided by portable-atomic which is implemented using locks on unsupported platforms.)

@davidhewitt
Copy link
Member

We also fixed this in 0.20.3, so your project should be able to update to the PyO3 patch without needing further changes.

@he32
Copy link
Author

he32 commented May 3, 2024

Thanks for the pointers, I'll try to follow them. This problem was of course encountered in another program which has "vendored" in a particular version of pyo3, and it's not just a simple matter of updating that instance of pyo3.

I must be reading the github source repository in the main branch wrong, then? If I look at the first 19 lines of https://github.com/PyO3/pyo3/blob/main/src/impl_/pymodule.rs I see the "this uses AtomicI64 no matter what" construct still there.

@alex
Copy link
Contributor

alex commented May 3, 2024

https://github.com/PyO3/pyo3/blob/main/src/impl_/pymodule.rs#L5-L18 -- it uses portable-atomic on platforms that don't have a native AtomicI64, and it uses std on other platforms.

@he32
Copy link
Author

he32 commented May 3, 2024

Hm, yes, as I said, "must be reading that wong", and that was what I did. Rust newbie here. Patching in an upgrade to pyo3 0.20.3 in bcrypt 4.2.1 was also a bit easier than I had feared. Anyway, thanks for the attention.

@alex
Copy link
Contributor

alex commented May 3, 2024

I'm one of the bcrypt maintainers. If a release of bcrypt would be helpful, please file an issue over there. We should be able to knock one out easily.

@he32
Copy link
Author

he32 commented May 3, 2024

Ah, thanks, a bcrypt minor update upping the pyo3 to e.g. 0.20.3 would be helpful, even though I now have a fix in place for version 4.2.1.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 3, 2024
Bump pyo3 version from 0.20.0 to 0.20.3, ref.
  https://github.com/PyO3/pyo3/releases/tag/v0.20.3

This so that this package can build on ports without 64-bit
atomic operations.  Ref. PyO3/pyo3#4153

Bump PKGREVISION.
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

4 participants