Skip to main content

extern_libpython

Macro extern_libpython 

Source
macro_rules! extern_libpython {
    ($abi:literal { $($body:tt)* }) => { ... };
    (@impl $abi:literal { $($body:tt)* } $($dll:literal),* $(,)?) => { ... };
    ($($body:tt)*) => { ... };
}
Expand description

Helper macro to declare extern blocks that link against libpython on Windows using raw-dylib, eliminating the need for import libraries.

The build script sets a pyo3_dll cfg value to the target DLL name (e.g. python312), and this macro expands to the appropriate #[link(name = "...", kind = "raw-dylib")] attribute for that DLL.

§Usage

// Default ABI "C" (most common):
extern_libpython! {
    pub fn PyObject_Call(
        callable: *mut PyObject,
        args: *mut PyObject,
        kwargs: *mut PyObject,
    ) -> *mut PyObject;
}

// Explicit ABI:
extern_libpython! { "C-unwind" {
    pub fn PyGILState_Ensure() -> PyGILState_STATE;
}}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here