Skip to content

Commit

Permalink
Add support for using bundled python sysconfigs for PyPy when abi3
Browse files Browse the repository at this point in the history
feature is enabled
  • Loading branch information
messense committed Jun 8, 2022
1 parent 9042c79 commit eed6c12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Don't require `pip` error messages to be utf-8 encoding in [#953](https://github.com/PyO3/maturin/pull/953)
* Compare minimum python version requirement between `requires-python` and bindings crate in [#954](https://github.com/PyO3/maturin/pull/954)
* Add a `--target` option to `maturin list-python` command in [#957](https://github.com/PyO3/maturin/pull/957)
* Add support for using bundled python sysconfigs for PyPy when abi3 feature is enabled in [#958](https://github.com/PyO3/maturin/pull/958)

## [0.12.19] - 2022-06-05

Expand Down
23 changes: 15 additions & 8 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,19 @@ pub fn find_interpreter(
}
BridgeModel::Bin(None) => Ok(vec![]),
BridgeModel::BindingsAbi3(major, minor) => {
let interpreter = if !interpreter.is_empty() {
PythonInterpreter::check_executables(interpreter, target, bridge)
.unwrap_or_default()
let interpreters = if !interpreter.is_empty() {
match find_interpreter_in_host(bridge, interpreter, target, Some(*minor as usize)) {
Ok(host_interps) => host_interps,
Err(err) => {
if !interpreter.is_empty() {
find_interpreter_in_sysconfig(interpreter, target).map_err(|_| err)?
} else {
return Err(err);
}
}
}
} else {
PythonInterpreter::find_all(target, bridge, Some(*minor as usize))
.unwrap_or_default()
find_interpreter_in_host(bridge, interpreter, target, Some(*minor as usize))?
};
// Ideally, we wouldn't want to use any python interpreter without abi3 at all.
// Unfortunately, on windows we need one to figure out base_prefix for a linker
Expand All @@ -937,9 +944,9 @@ pub fn find_interpreter(
platform: None,
runnable: false,
}])
} else if let Some(interp) = interpreter.get(0) {
} else if let Some(interp) = interpreters.get(0) {
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interp);
Ok(interpreter)
Ok(interpreters)
} else if generate_import_lib {
println!("🐍 Not using a specific python interpreter (Automatically generating windows import library)");
// fake a python interpreter
Expand Down Expand Up @@ -980,7 +987,7 @@ pub fn find_interpreter(
runnable: false,
}])
} else {
Ok(interpreter)
Ok(interpreters)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ fn compile_target(

// rust-cpython, and legacy pyo3 versions
build_command.env("PYTHON_SYS_EXECUTABLE", &interpreter.executable);
} else if (bindings_crate.is_bindings("pyo3") || bindings_crate.is_bindings("pyo3-ffi"))
} else if (bindings_crate.is_bindings("pyo3")
|| bindings_crate.is_bindings("pyo3-ffi")
|| (matches!(bindings_crate, BridgeModel::BindingsAbi3(_, _))
&& matches!(interpreter.interpreter_kind, InterpreterKind::PyPy)))
&& env::var_os("PYO3_CONFIG_FILE").is_none()
{
let pyo3_config = interpreter.pyo3_config_file();
Expand Down

0 comments on commit eed6c12

Please sign in to comment.