Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use std::{env, fs, path::Path};

fn main() {
pyo3_build_config::use_pyo3_cfgs();
let config = pyo3_build_config::get();
if matches!(
pyo3_build_config::get().implementation(),
config.implementation(),
pyo3_build_config::PythonImplementation::CPython
) {
println!("cargo:rustc-cfg=CPython");
}
println!("cargo:rustc-check-cfg=cfg(CPython)");

let link = match env::var("CARGO_CFG_TARGET_OS").as_deref() {
Ok("windows") => format!(
r#"#[link(name = "{}", kind = "raw-dylib")]"#,
config.lib_name().unwrap()
),
_ => String::new(),
};
let out = Path::new(&env::var("OUT_DIR").unwrap()).join("extern_libpython.rs");
let src = format!(
"macro_rules! extern_libpython {{ ($($t:tt)*) => {{ {link} extern \"C\" {{ $($t)* }} }} }}"
);
fs::write(out, src).unwrap();
}
6 changes: 5 additions & 1 deletion src/ffi/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use pyo3::ffi;

extern "C" {
include!(concat!(env!("OUT_DIR"), "/extern_libpython.rs"));

extern_libpython! {
// x86 Windows import names drop one leading `_`.
#[cfg_attr(all(windows, target_arch = "x86"), link_name = "__PyDict_NewPresized")]
pub(crate) fn _PyDict_NewPresized(minused: ffi::Py_ssize_t) -> *mut ffi::PyObject;
}
Loading