Skip to content

Commit

Permalink
Fix python version cfg (#25)
Browse files Browse the repository at this point in the history
* Fix python version cfg

* Fix build.rs and add pyo3-build-config
* change minimum for fastcall to py3.8

Co-authored-by: Łuczak, Piotr <[email protected]>
Co-authored-by: Aviram Hassan <[email protected]>
  • Loading branch information
3 people authored Jul 23, 2021
1 parent 71e6926 commit b689f0b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ rmp-serde = {version = "^0.15.4"}
[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "i686", target_arch = "armv7"))'.dependencies]
encoding_rs = { version = "0.8", default_features = false, features = ["simd-accel"] }

[build-dependencies]
pyo3-build-config = { version = "^0.14.1" }

[profile.release]
codegen-units = 1
debug = false
Expand Down
14 changes: 1 addition & 13 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
use std::process::Command;

fn main() {
let out = Command::new("python")
.args(&["-c", "import sys; print(sys.version_info[1])"])
.output()
.expect("python version did not print");
let version = String::from_utf8_lossy(&out.stdout)
.trim()
.parse::<u8>()
.expect("python version was not parsed");
for each in 6..version {
println!("cargo:rustc-cfg=python3{}", each);
}
pyo3_build_config::use_pyo3_cfgs();
}
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub unsafe extern "C" fn PyInit_ormsgpack() -> *mut PyObject {
let wrapped_packb: PyMethodDef;
let wrapped_unpackb: PyMethodDef;

#[cfg(python37)]
#[cfg(Py_3_8)]
{
wrapped_packb = PyMethodDef {
ml_name: "packb\0".as_ptr() as *const c_char,
Expand All @@ -96,7 +96,7 @@ pub unsafe extern "C" fn PyInit_ormsgpack() -> *mut PyObject {
};
}

#[cfg(not(python37))]
#[cfg(not(Py_3_8))]
{
wrapped_packb = PyMethodDef {
ml_name: "packb\0".as_ptr() as *const c_char,
Expand All @@ -118,7 +118,7 @@ pub unsafe extern "C" fn PyInit_ormsgpack() -> *mut PyObject {
)
);

#[cfg(python37)]
#[cfg(Py_3_8)]
{
wrapped_unpackb = PyMethodDef {
ml_name: "unpackb\0".as_ptr() as *const c_char,
Expand All @@ -130,7 +130,7 @@ pub unsafe extern "C" fn PyInit_ormsgpack() -> *mut PyObject {
};
}

#[cfg(not(python37))]
#[cfg(not(Py_3_8))]
{
wrapped_unpackb = PyMethodDef {
ml_name: "unpackb\0".as_ptr() as *const c_char,
Expand Down Expand Up @@ -250,7 +250,7 @@ fn raise_packb_exception(msg: Cow<str>) -> *mut PyObject {
std::ptr::null_mut()
}

#[cfg(python37)]
#[cfg(Py_3_8)]
#[no_mangle]
pub unsafe extern "C" fn unpackb(
_self: *mut PyObject,
Expand Down Expand Up @@ -307,7 +307,7 @@ pub unsafe extern "C" fn unpackb(
}
}

#[cfg(not(python37))]
#[cfg(not(Py_3_8))]
#[no_mangle]
pub unsafe extern "C" fn unpackb(
_self: *mut PyObject,
Expand Down Expand Up @@ -369,7 +369,7 @@ pub unsafe extern "C" fn unpackb(
}
}

#[cfg(python37)]
#[cfg(Py_3_8)]
#[no_mangle]
pub unsafe extern "C" fn packb(
_self: *mut PyObject,
Expand Down Expand Up @@ -437,7 +437,7 @@ pub unsafe extern "C" fn packb(
}
}

#[cfg(not(python37))]
#[cfg(not(Py_3_8))]
#[no_mangle]
pub unsafe extern "C" fn packb(
_self: *mut PyObject,
Expand Down

0 comments on commit b689f0b

Please sign in to comment.