Introduce PYO3_NO_INTERPRETER variable for build script
This commit is contained in:
parent
eae0d8682b
commit
1b838504b7
18
build.rs
18
build.rs
|
@ -836,7 +836,25 @@ fn check_target_architecture(interpreter_config: &InterpreterConfig) -> Result<(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn abi3_without_interpreter() -> Result<()> {
|
||||
println!("cargo:rustc-cfg=Py_LIMITED_API");
|
||||
let mut flags = "FLAG_WITH_THREAD=1".to_string();
|
||||
for minor in PY3_MIN_MINOR..=ABI3_MAX_MINOR {
|
||||
println!("cargo:rustc-cfg=Py_3_{}", minor);
|
||||
flags += &format!(",CFG_Py_3_{}", minor);
|
||||
}
|
||||
println!("cargo:rustc-cfg=py_sys_config=\"WITH_THREAD\"");
|
||||
println!("cargo:python_flags={}", flags);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// If PYO3_NO_INTEPRETER is set with abi3, we can build PyO3 without calling Python (UNIX only).
|
||||
if env::var_os("PYO3_NO_INTERPRETER").is_some()
|
||||
&& env::var_os(format!("CARGO_FEATURE_ABI3_PY3{}", ABI3_MAX_MINOR)).is_some()
|
||||
{
|
||||
return abi3_without_interpreter();
|
||||
}
|
||||
// 1. Setup cfg variables so we can do conditional compilation in this library based on the
|
||||
// python interpeter's compilation flags. This is necessary for e.g. matching the right unicode
|
||||
// and threading interfaces. First check if we're cross compiling, if so, we cannot run the
|
||||
|
|
|
@ -66,6 +66,9 @@ E.g., if you set `abi3-py36` feature, you can build `cp36-abi3-manylinux2020_x86
|
|||
To ensure ABI compatibility, we don't allow setting a minimum version higher than the system Python version.
|
||||
E.g., if you set `abi3-py38` and try to compile the crate with Python 3.6, it just fails.
|
||||
|
||||
As an advanced feature, you can build PyO3 wheel without calling Python interpreter with
|
||||
the environment variable `PYO3_NO_INTERPRETER` set, but this only works on *NIX.
|
||||
|
||||
## Cross Compiling
|
||||
|
||||
Cross compiling PyO3 modules is relatively straightforward and requires a few pieces of software:
|
||||
|
|
Loading…
Reference in New Issue