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 is built with wrong config when building for 3.13t with abi3 and generate-import-lib both enabled #2385

Open
2 tasks
kahojyun opened this issue Dec 16, 2024 · 6 comments · May be fixed by PyO3/pyo3#4808
Open
2 tasks
Labels
bug Something isn't working

Comments

@kahojyun
Copy link

Bug Description

When debugging #2368, I notice that if both of abi3 and generate-import-lib are enabled, maturin build -i 3.13t doesn't generate PYO3_CONFIG_FILE for pyo3-build-config to read and pyo3 will be built with whatever python interpreter it can find from PATH.

Your maturin version (maturin --version)

maturin 1.7.8

Your Python version (python -V)

Python 3.12.7

Your pip version (pip -V)

pip 24.2

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

  1. Enable both abi3 and generate-import-lib features
pyo3 = { version = "0.23.3", features = ["abi3-py39", "generate-import-lib"] }
  1. Reference GILProtected which is not available in free-threaded python 3.13t
  2. Build with maturin build -i 3.13t (Python 3.13t not installed so pyo3 can't find interpreter from PATH)
🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.9
⚠️  Warning: Failed to determine python platform
🐍 Not using a specific python interpreter (automatically generating windows import library)
📡 Using build options features from pyproject.toml
⚠️ Warning: CPython 3.13t does not yet support abi3 so the build artifacts will be version-specific.
   Compiling shlex v1.3.0
   Compiling target-lexicon v0.12.16
   Compiling once_cell v1.20.2
   Compiling proc-macro2 v1.0.92
   Compiling unicode-ident v1.0.14
   Compiling autocfg v1.4.0
   Compiling libc v0.2.168
   Compiling heck v0.5.0
   Compiling indoc v2.0.5
   Compiling unindent v0.2.3
   Compiling cfg-if v1.0.0
   Compiling cc v1.2.4
   Compiling memoffset v0.9.1
   Compiling python3-dll-a v0.2.11
   Compiling quote v1.0.37
   Compiling pyo3-build-config v0.23.3
   Compiling syn v2.0.90
   Compiling pyo3-ffi v0.23.3
   Compiling pyo3-macros-backend v0.23.3
   Compiling pyo3 v0.23.3
   Compiling pyo3-macros v0.23.3
   Compiling wrong-lib v0.1.0 (E:\wrong-lib)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 10.06s
📦 Built wheel for CPython 3.13t to E:\wrong-lib\target\wheels\wrong_lib-0.1.0-cp313-cp313t-win_amd64.whl

Expected: compilation error
4. Remove abi3 feature, compilation fails as expected

🔗 Found pyo3 bindings
⚠️  Warning: Failed to determine python platform
🐍 Found CPython 3.13t
📡 Using build options features from pyproject.toml
   Compiling target-lexicon v0.12.16
   Compiling shlex v1.3.0
   Compiling once_cell v1.20.2
   Compiling proc-macro2 v1.0.92
   Compiling unicode-ident v1.0.14
   Compiling autocfg v1.4.0
   Compiling libc v0.2.168
   Compiling heck v0.5.0
   Compiling indoc v2.0.5
   Compiling cfg-if v1.0.0
   Compiling unindent v0.2.3
   Compiling cc v1.2.4
   Compiling memoffset v0.9.1
   Compiling python3-dll-a v0.2.11
   Compiling pyo3-build-config v0.23.3
   Compiling quote v1.0.37
   Compiling syn v2.0.90
   Compiling pyo3-ffi v0.23.3
   Compiling pyo3-macros-backend v0.23.3
   Compiling pyo3 v0.23.3
   Compiling pyo3-macros v0.23.3
   Compiling wrong-lib v0.1.0 (E:\wrong-lib)
error[E0432]: unresolved import `pyo3::sync::GILProtected`
  --> src\lib.rs:1:24
   |
1  | use pyo3::{prelude::*, sync::GILProtected};
   |                        ^^^^^^^^^^^^^^^^^^ no `GILProtected` in `sync`
   |
note: found an item that was configured out
  --> E:\packages\cargo\registry\src\index.crates.io-6f17d22bba15001f\pyo3-0.23.3\src\sync.rs:47:12
   |
47 | pub struct GILProtected<T> {
   |            ^^^^^^^^^^^^
note: the item is gated here
  --> E:\packages\cargo\registry\src\index.crates.io-6f17d22bba15001f\pyo3-0.23.3\src\sync.rs:46:1
   |
46 | #[cfg(not(Py_GIL_DISABLED))]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
error: could not compile `wrong-lib` (lib) due to 1 previous error
💥 maturin failed
  Caused by: Failed to build a native library through cargo
  Caused by: Cargo build finished with "exit code: 101": `"cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "E:\\wrong-lib\\Cargo.toml" "--lib"`
@kahojyun kahojyun added the bug Something isn't working label Dec 16, 2024
@kahojyun
Copy link
Author

It seems that the combination of abi3, generate-import-lib and non-abi3-compatible version like 3.13t will confuse pyo3 and maturin. Are users supposed to make these features optional and provide coherent feature combinations in CI?

@messense
Copy link
Member

Are users supposed to make these features optional and provide coherent feature combinations in CI?

No, abi3 and generate-import-lib are supposed to work well together.

@messense
Copy link
Member

Feel free to investigate and send PRs to fix it, I don't have much experience developing on Windows, help appreciated!

@CastilloDel
Copy link

Hello! Do you think this is related to this error?

📦 Built wheel for abi3 Python ≥ 3.8 to /home/jenkins/agent/workspace/edaq-cache/wheels/edaq-0.2.0-cp38-abi3-win_amd64.whl
⚠️ Warning: PyPy 3.10, CPython 3.13t, PyPy 3.9, PyPy 3.8 does not yet support abi3 so the build artifacts will be version-specific.
Compiling qps-client-python v0.2.0 (/home/jenkins/agent/workspace/EDAQ_devrelease_master/qps-client-python)
Finished `release` profile [optimized] target(s) in 9.39s
📦 Built wheel for CPython 3.13t to /home/jenkins/agent/workspace/edaq-cache/wheels/edaq-0.2.0-cp313-cp313t-win_amd64.whl
Compiling pyo3-build-config v0.23.3
Compiling qps-client-python v0.2.0 (/home/jenkins/agent/workspace/EDAQ_devrelease_master/qps-client-python)
Compiling pyo3-macros-backend v0.23.3
Compiling pyo3-ffi v0.23.3
Compiling pyo3 v0.23.3
error: failed to run custom build command for `pyo3-ffi v0.23.3`

Caused by:
  process didn't exit successfully: `/home/jenkins/agent/workspace/edaq-cache/release/build/pyo3-ffi-baac11c082c1bee1/build-script-build` (exit status: 1)
  --- stdout
  cargo:rustc-check-cfg=cfg(Py_LIMITED_API)
  cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)
  cargo:rustc-check-cfg=cfg(PyPy)
  cargo:rustc-check-cfg=cfg(GraalPy)
  cargo:rustc-check-cfg=cfg(py_sys_config, values("Py_DEBUG", "Py_REF_DEBUG", "Py_TRACE_REFS", "COUNT_ALLOCS"))
  cargo:rustc-check-cfg=cfg(invalid_from_utf8_lint)
  cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)
  cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)
  cargo:rustc-check-cfg=cfg(diagnostic_namespace)
  cargo:rustc-check-cfg=cfg(c_str_lit)
  cargo:rustc-check-cfg=cfg(rustc_has_once_lock)
  cargo:rustc-check-cfg=cfg(Py_3_7)
  cargo:rustc-check-cfg=cfg(Py_3_8)
  cargo:rustc-check-cfg=cfg(Py_3_9)
  cargo:rustc-check-cfg=cfg(Py_3_10)
  cargo:rustc-check-cfg=cfg(Py_3_11)
  cargo:rustc-check-cfg=cfg(Py_3_12)
  cargo:rustc-check-cfg=cfg(Py_3_13)

  --- stderr
  error: failed to generate python3.dll import library
  caused by:
    - 0: Unsupported PyPy version

It started appearing after updating pyo3 from 0.20 to 0.23. Otherwise, I can create a new issue

Thanks!

@messense
Copy link
Member

@CastilloDel That was a pyo3 bug, fixed in PyO3/pyo3#4806

@CastilloDel
Copy link

Perfect! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants