diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 581004c4a90..2e93c812832 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -674,14 +674,14 @@ pub fn is_extension_module() -> bool { /// Checks if we need to link to `libpython` for the current build target. /// -/// Must be called from a crate PyO3 build script. +/// Must be called from a PyO3 crate build script. pub fn is_linking_libpython() -> bool { is_linking_libpython_for_target(&target_triple_from_env()) } /// Checks if we need to link to `libpython` for the target. /// -/// Must be called from a crate PyO3 build script. +/// Must be called from a PyO3 crate build script. fn is_linking_libpython_for_target(target: &Triple) -> bool { target.operating_system == OperatingSystem::Windows || target.environment == Environment::Android @@ -1651,14 +1651,19 @@ pub fn make_cross_compile_config() -> Result> { /// Only used by `pyo3-build-config` build script. #[allow(dead_code)] pub fn make_interpreter_config() -> Result { + let host = Triple::host(); let abi3_version = get_abi3_version(); - if have_python_interpreter() { + // See if we can skip the Python interpreter configuration detection. + // Unix "abi3" extension modules can be built without any interpreter, + // so do this by default just like maturin does. + let require_interpreter = abi3_version.is_none() || is_linking_libpython_for_target(&host); + + if have_python_interpreter() && require_interpreter { let mut interpreter_config = InterpreterConfig::from_interpreter(find_interpreter()?)?; interpreter_config.fixup_for_abi3_version(abi3_version)?; Ok(interpreter_config) } else if let Some(version) = abi3_version { - let host = Triple::host(); Ok(default_abi3_config(&host, version)) } else { bail!("An abi3-py3* feature must be specified when compiling without a Python interpreter.")