You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In examples/pyo3-pytests we need to detect the Python version and PyPy so that some tests can be conditionally compiled. We do this by invoking the Python interpreter:
let output = String::from_utf8_lossy(&out.stdout);
letmut lines = output.trim().lines();
println!("{}", output);
let version:u8 = lines
.next()
.unwrap()
.parse()
.expect("python version was not parsed");
let implementation = lines.next().unwrap();
for each in6..version {
println!("cargo:rustc-cfg=Py_3_{}", each);
}
if implementation == "PyPy"{
println!("cargo:rustc-cfg=PyPy");
}
}
This has some downsides that we should try to fix:
It's using different logic to detect Python compared to PyO3's main build.rs, which could lead to misconfiguration in certain situations. (e.g. it doesn't check PYO3_PYTHON, nor will it work when cross-compiling.)
Users have to copy this pattern by hand into every crate which needs to support multiple Python versions.
I think we can solve this by splitting out a lot of PyO3's build.rs into a new crate pyo3-build-config which we would use in [build-dependencies]. Downstream crates like pyo3-pytests and orjson could then use this crate also in [build-dependencies] to access the exact same configuration which PyO3 has loaded in their own build.rs files.
I've started playing around with something of this form; this issue is a reminder for me to finish it off.
The text was updated successfully, but these errors were encountered:
cc @m-ou-se I wonder if this would "resolve" m-ou-se/inline-python#27 by making it easier for inline-python to request linking to libpython in its build script. (I'm thinking with this change, inline-python's build script could access the pyo3 build config.)
In
examples/pyo3-pytests
we need to detect the Python version and PyPy so that some tests can be conditionally compiled. We do this by invoking the Python interpreter:pyo3/examples/pyo3-pytests/build.rs
Lines 1 to 28 in 990bbb5
This has some downsides that we should try to fix:
build.rs
, which could lead to misconfiguration in certain situations. (e.g. it doesn't check PYO3_PYTHON, nor will it work when cross-compiling.)e.g. I've seen a similar trick in the wild in
orjson
(which is where I borrowed this from) https://github.com/ijl/orjson/blob/master/build.rsI think we can solve this by splitting out a lot of PyO3's
build.rs
into a new cratepyo3-build-config
which we would use in[build-dependencies]
. Downstream crates likepyo3-pytests
andorjson
could then use this crate also in[build-dependencies]
to access the exact same configuration which PyO3 has loaded in their ownbuild.rs
files.I've started playing around with something of this form; this issue is a reminder for me to finish it off.
The text was updated successfully, but these errors were encountered: