From eaaf382a8c12bc840b253d9ffbc46f378bfaaf54 Mon Sep 17 00:00:00 2001 From: Bas Schoenmaeckers Date: Thu, 16 Apr 2026 17:44:55 +0200 Subject: [PATCH] Add `RustPython` cfg --- pyo3-build-config/src/impl_.rs | 5 +++++ pyo3-build-config/src/lib.rs | 2 ++ pyo3-ffi/build.rs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 6a090d93b75..3d64cb34e4c 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -191,6 +191,7 @@ impl InterpreterConfig { PythonImplementation::CPython => {} PythonImplementation::PyPy => out.push("cargo:rustc-cfg=PyPy".to_owned()), PythonImplementation::GraalPy => out.push("cargo:rustc-cfg=GraalPy".to_owned()), + PythonImplementation::RustPython => out.push("cargo:rustc-cfg=RustPython".to_owned()), } // If Py_GIL_DISABLED is set, do not build with limited API support @@ -780,6 +781,7 @@ pub enum PythonImplementation { CPython, PyPy, GraalPy, + RustPython, } impl PythonImplementation { @@ -813,6 +815,7 @@ impl Display for PythonImplementation { PythonImplementation::CPython => write!(f, "CPython"), PythonImplementation::PyPy => write!(f, "PyPy"), PythonImplementation::GraalPy => write!(f, "GraalVM"), + PythonImplementation::RustPython => write!(f, "RustPython"), } } } @@ -824,6 +827,7 @@ impl FromStr for PythonImplementation { "CPython" => Ok(PythonImplementation::CPython), "PyPy" => Ok(PythonImplementation::PyPy), "GraalVM" => Ok(PythonImplementation::GraalPy), + "RustPython" => Ok(PythonImplementation::RustPython), _ => bail!("unknown interpreter: {}", s), } } @@ -1768,6 +1772,7 @@ fn default_lib_name_unix( }, PythonImplementation::GraalPy => Ok("python-native".to_string()), + PythonImplementation::RustPython => Ok("rustpython-capi".to_string()), } } diff --git a/pyo3-build-config/src/lib.rs b/pyo3-build-config/src/lib.rs index 65d7f1bade4..9bc9a9c8cc9 100644 --- a/pyo3-build-config/src/lib.rs +++ b/pyo3-build-config/src/lib.rs @@ -261,6 +261,7 @@ pub fn print_expected_cfgs() { println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)"); println!("cargo:rustc-check-cfg=cfg(PyPy)"); println!("cargo:rustc-check-cfg=cfg(GraalPy)"); + println!("cargo:rustc-check-cfg=cfg(RustPython)"); println!("cargo:rustc-check-cfg=cfg(py_sys_config, values(\"Py_DEBUG\", \"Py_REF_DEBUG\", \"Py_TRACE_REFS\", \"COUNT_ALLOCS\"))"); println!("cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)"); println!("cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)"); @@ -393,6 +394,7 @@ pub mod pyo3_build_script_impl { PythonImplementation::CPython => "Python", PythonImplementation::PyPy => "PyPy", PythonImplementation::GraalPy => "GraalPy", + PythonImplementation::RustPython => "RustPython", }; let version = &interpreter_config.version; let message = format!( diff --git a/pyo3-ffi/build.rs b/pyo3-ffi/build.rs index 127874ffa84..7c9be0e4cb0 100644 --- a/pyo3-ffi/build.rs +++ b/pyo3-ffi/build.rs @@ -122,6 +122,7 @@ fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> { return Err(error.finish().into()); } } + PythonImplementation::RustPython => {} } if interpreter_config.abi3 { @@ -140,6 +141,7 @@ fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> { PythonImplementation::GraalPy => warn!( "GraalPy does not support abi3 so the build artifacts will be version-specific." ), + PythonImplementation::RustPython => {} } }