|
43 | 43 | //! PyO3 uses `rustc`'s `--cfg` flags to enable or disable code used for different Python versions.
|
44 | 44 | //! If you want to do this for your own crate, you can do so with the [`pyo3-build-config`] crate.
|
45 | 45 | //!
|
46 |
| -//! - `Py_3_7`, `Py_3_8`, `Py_3_9`, `Py_3_10`: Marks code that is only enabled when |
47 |
| -//! compiling for a given minimum Python version. |
| 46 | +//! - `Py_3_7`, `Py_3_8`, `Py_3_9`, `Py_3_10`, `Py_3_11`, `Py_3_12`, `Py_3_13`: Marks code that is |
| 47 | +//! only enabled when compiling for a given minimum Python version. |
48 | 48 | //! - `Py_LIMITED_API`: Marks code enabled when the `abi3` feature flag is enabled.
|
| 49 | +//! - `Py_GIL_DISABLED`: Marks code that runs only in the free-threaded build of CPython. |
49 | 50 | //! - `PyPy` - Marks code enabled when compiling for PyPy.
|
| 51 | +//! - `GraalPy` - Marks code enabled when compiling for GraalPy. |
| 52 | +//! |
| 53 | +//! Additionally, you can query for the values `Py_DEBUG`, `Py_REF_DEBUG`, |
| 54 | +//! `Py_TRACE_REFS`, and `COUNT_ALLOCS` from `py_sys_config` to query for the |
| 55 | +//! corresponding C build-time defines. For example, to conditionally define |
| 56 | +//! debug code using `Py_DEBUG`, you could do: |
| 57 | +//! |
| 58 | +//! ```rust,ignore |
| 59 | +//! #[cfg(py_sys_config = "Py_DEBUG")] |
| 60 | +//! println!("only runs if python was compiled with Py_DEBUG") |
| 61 | +//! ``` |
| 62 | +//! |
| 63 | +//! To use these attributes, add [`pyo3-build-config`] as a build dependency in |
| 64 | +//! your `Cargo.toml`: |
| 65 | +//! |
| 66 | +//! ```toml |
| 67 | +//! [build-dependency] |
| 68 | +//! pyo3-build-config = "VER" |
| 69 | +//! ``` |
| 70 | +//! |
| 71 | +//! And then either create a new `build.rs` file in the project root or modify |
| 72 | +//! the existing `build.rs` file to call `use_pyo3_cfgs()`: |
| 73 | +//! |
| 74 | +//! ```rust,ignore |
| 75 | +//! fn main() { |
| 76 | +//! pyo3_build_config::use_pyo3_cfgs(); |
| 77 | +//! } |
| 78 | +//! ``` |
50 | 79 | //!
|
51 | 80 | //! # Minimum supported Rust and Python versions
|
52 | 81 | //!
|
|
0 commit comments