PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Other
11.56k stars 710 forks source link

pyo3-0.20.0 on ppc32: no `AtomicI64` in `sync::atomic` #3614

Closed mgorny closed 7 months ago

mgorny commented 7 months ago

Bug Description

When building a package (html-py-ever example from setuptools-rust) using pyo3 0.20.0 on ppc32, I'm getting the following error:

error[E0432]: unresolved import `std::sync::atomic::AtomicI64`
 --> /home/mgorny/.cargo/registry/src/index.crates.io-9850fa1df3136423/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

Steps to Reproduce

git clone https://github.com/PyO3/setuptools-rust/
cd setuptools-rust/examples/html-py-ever
python -m build -w

Backtrace

Running `rustc --crate-name pyo3 --edition=2021 /home/mgorny/.cargo/registry/src/index.crates.io-9850fa1df3136423/pyo3-0.20.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=135 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="extension-module"' --cfg 'feature="indoc"' --cfg 'feature="macros"' --cfg 'feature="pyo3-macros"' --cfg 'feature="unindent"' -C metadata=c3280b3684a9dc16 -C extra-filename=-c3280b3684a9dc16 --out-dir /home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps -L dependency=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps --extern cfg_if=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libcfg_if-dd66dfbd15e1f200.rmeta --extern indoc=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libindoc-330c4043caad1819.so --extern libc=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/liblibc-bd25ee420bfedf7b.rmeta --extern memoffset=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libmemoffset-80b40800efcae77e.rmeta --extern parking_lot=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libparking_lot-166554cbb51c52ff.rmeta --extern pyo3_ffi=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libpyo3_ffi-d8ceef02bf595e0b.rmeta --extern pyo3_macros=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libpyo3_macros-b6c77a4bfb6a873a.so --extern unindent=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libunindent-a0d1a359c22931b4.rmeta --cap-lints allow --cfg Py_3_6 --cfg Py_3_7 --cfg Py_3_8 --cfg Py_3_9 --cfg Py_3_10 --cfg Py_3_11 --cfg thread_local_const_init`
error[E0432]: unresolved import `std::sync::atomic::AtomicI64`
 --> /home/mgorny/.cargo/registry/src/index.crates.io-9850fa1df3136423/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

Caused by:
  process didn't exit successfully: `rustc --crate-name pyo3 --edition=2021 /home/mgorny/.cargo/registry/src/index.crates.io-9850fa1df3136423/pyo3-0.20.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=135 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="extension-module"' --cfg 'feature="indoc"' --cfg 'feature="macros"' --cfg 'feature="pyo3-macros"' --cfg 'feature="unindent"' -C metadata=c3280b3684a9dc16 -C extra-filename=-c3280b3684a9dc16 --out-dir /home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps -L dependency=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps --extern cfg_if=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libcfg_if-dd66dfbd15e1f200.rmeta --extern indoc=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libindoc-330c4043caad1819.so --extern libc=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/liblibc-bd25ee420bfedf7b.rmeta --extern memoffset=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libmemoffset-80b40800efcae77e.rmeta --extern parking_lot=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libparking_lot-166554cbb51c52ff.rmeta --extern pyo3_ffi=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libpyo3_ffi-d8ceef02bf595e0b.rmeta --extern pyo3_macros=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libpyo3_macros-b6c77a4bfb6a873a.so --extern unindent=/home/mgorny/setuptools-rust/examples/html-py-ever/target/release/deps/libunindent-a0d1a359c22931b4.rmeta --cap-lints allow --cfg Py_3_6 --cfg Py_3_7 --cfg Py_3_8 --cfg Py_3_9 --cfg Py_3_10 --cfg Py_3_11 --cfg thread_local_const_init` (exit status: 1)
error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib --` failed with code 101

ERROR Backend subprocess exited when trying to invoke build_wheel

Your operating system and version

Gentoo Linux, ppc32 nspawn container on POWER9

Your Python version (python --version)

Python 3.11.6

Your Rust version (rustc --version)

rustc 1.71.1 (eb26296b5 2023-08-03)

Your PyO3 version

0.20.0

How did you install python? Did you use a virtualenv?

Gentoo package. Tested inside a venv (with another venv layer via build) and outside.

Additional Info

I know that C programs using 64-bit atomics need to explicitly link -latomic here. I don't know how that maps to Rust.

messense commented 7 months ago

IMO in Rust we could use the portable-atomic crate.

davidhewitt commented 7 months ago

Does it work if we have that as an optional dependency? Alternatively we could use AtomicBool and a OnceLock pair, which I actually used in my original implementation.

mgorny commented 7 months ago

If you give me a patch, I can test it on this system.

davidhewitt commented 7 months ago

I will try to put something together by end of Sunday. Afraid I'm a little bit behind on OSS this week; was in hospital with my son the two weeks before.

adamreichold commented 7 months ago

I created #3619 as I agree with @messense on using portable-atomic to resolve this. @mgorny Could you give it a try?

An alternative I see is safely casting the interpreter ID to 32-bits (using TryInto) and use that instead of a full 64-bit interpreter ID because 4 billion subinterpreters should be enough for everybody?

mgorny commented 7 months ago

Thank you! I can confirm that the setuptools-rust example builds against your branch on that machine, and the tests pass.