From 3be077a6112d8b9d1f2bbce66dd8b70f56231477 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 8 Jun 2022 22:37:03 +0800 Subject: [PATCH] Add support for using bundled python sysconfigs for PyPy when abi3 feature is enabled --- Changelog.md | 1 + src/build_options.rs | 22 +++++++++++++++------- src/compile.rs | 5 ++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index d17efe700..c3312e5d4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/build_options.rs b/src/build_options.rs index df44cad31..3ab2a6c50 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -908,11 +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 { + Vec::new() + } + } + } } else { - PythonInterpreter::find_all(target, bridge, Some(*minor as usize)) + find_interpreter_in_host(bridge, interpreter, target, Some(*minor as usize)) .unwrap_or_default() }; // Ideally, we wouldn't want to use any python interpreter without abi3 at all. @@ -937,9 +945,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 @@ -980,7 +988,7 @@ pub fn find_interpreter( runnable: false, }]) } else { - Ok(interpreter) + Ok(interpreters) } } } diff --git a/src/compile.rs b/src/compile.rs index 77aac5c3c..23cf567ca 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -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();