Skip to content

Commit a41bc86

Browse files
authored
If an interpreter is available, use it, even when building ABI3. (#2829)
At present, when targeting an `abi3` build, Maturin will use a dummy interpreter to provide build configuration details, unless the user specifies an interpreter with `--interpreter`, or the target is cross-compiling, or Windows is being targeted. The use of a dummy interpreter when a real interpreter is available can lead to the interpreter details that are available and defined in `sysconfigdata` not being used as part of the build process. This was discovered in the process of working on iOS support (see #2827 and #2828); although the iOS build environment *does* provide build configuration details, those details were not being passed down to the PyO3 build configuration. With those two patches (and some patches to PyO3 - see PyO3/pyo3#5605 and PyO3/pyo3#5606), it was possible to build a non-abi3 wheel; but this patch was needed to build an abi3 wheel.
1 parent e753052 commit a41bc86

File tree

2 files changed

+57
-52
lines changed

2 files changed

+57
-52
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* When building `abi3` wheels on non-Windows platforms that aren't cross-compiling, the `sysconfigdata` of the interpreter used to run maturin will now be used, rather than a dummy interpreter.
56
* Allow iOS cross-platform virtual environments, such as those used by cibuildwheel, to imply an iOS target.
67
* Fix iOS wheel naming to be compliant with PEP 730.
78
* Fix generated WHEEL Tag metadata to be spec compliant.

src/build_options.rs

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -473,60 +473,64 @@ impl BuildOptions {
473473
}
474474
Ok(found_interpreters)
475475
}
476-
} else {
477-
eprintln!("🐍 Not using a specific python interpreter");
478-
if self.interpreter.is_empty() {
479-
// Fake one to make `BuildContext::build_wheels` happy for abi3 when no cpython/pypy found on host
480-
// The python interpreter config doesn't matter, as it's not used for anything
481-
Ok(vec![PythonInterpreter {
482-
config: InterpreterConfig {
483-
major: *major as usize,
484-
minor: *minor as usize,
485-
interpreter_kind: InterpreterKind::CPython,
486-
abiflags: "".to_string(),
487-
ext_suffix: "".to_string(),
488-
pointer_width: None,
489-
gil_disabled: false,
490-
},
491-
executable: PathBuf::new(),
492-
platform: None,
493-
runnable: false,
494-
implementation_name: "cpython".to_string(),
495-
soabi: None,
496-
}])
497-
} else if target.cross_compiling() {
498-
let mut interps = Vec::with_capacity(found_interpreters.len());
499-
let mut pypys = Vec::new();
500-
for interp in found_interpreters {
501-
if interp.interpreter_kind.is_pypy() {
502-
pypys.push(PathBuf::from(format!(
503-
"pypy{}.{}",
504-
interp.major, interp.minor
505-
)));
506-
} else {
507-
interps.push(interp);
508-
}
509-
}
510-
// cross compiling to PyPy with abi3 feature enabled,
511-
// we cannot use host pypy so switch to bundled sysconfig instead
512-
if !pypys.is_empty() {
513-
interps.extend(find_interpreter_in_sysconfig(
514-
bridge,
515-
&pypys,
516-
target,
517-
requires_python,
518-
)?)
519-
}
520-
if interps.is_empty() {
521-
bail!("Failed to find any python interpreter");
522-
}
523-
Ok(interps)
524-
} else {
525-
if found_interpreters.is_empty() {
526-
bail!("Failed to find any python interpreter");
476+
} else if target.cross_compiling() {
477+
let mut interps = Vec::with_capacity(found_interpreters.len());
478+
let mut pypys = Vec::new();
479+
for interp in found_interpreters {
480+
if interp.interpreter_kind.is_pypy() {
481+
pypys.push(PathBuf::from(format!(
482+
"pypy{}.{}",
483+
interp.major, interp.minor
484+
)));
485+
} else {
486+
interps.push(interp);
527487
}
528-
Ok(found_interpreters)
529488
}
489+
// cross compiling to PyPy with abi3 feature enabled,
490+
// we cannot use host pypy so switch to bundled sysconfig instead
491+
if !pypys.is_empty() {
492+
interps.extend(find_interpreter_in_sysconfig(
493+
bridge,
494+
&pypys,
495+
target,
496+
requires_python,
497+
)?)
498+
}
499+
if interps.is_empty() {
500+
bail!("Failed to find any python interpreter");
501+
}
502+
Ok(interps)
503+
} else if !found_interpreters.is_empty() {
504+
let interpreters_str = found_interpreters
505+
.iter()
506+
.map(ToString::to_string)
507+
.collect::<Vec<String>>()
508+
.join(", ");
509+
eprintln!("🐍 Found {interpreters_str}");
510+
511+
Ok(found_interpreters)
512+
} else if self.interpreter.is_empty() {
513+
eprintln!("🐍 Not using a specific python interpreter");
514+
// Fake one to make `BuildContext::build_wheels` happy for abi3 when no cpython/pypy found on host
515+
// The python interpreter config doesn't matter, as it's not used for anything
516+
Ok(vec![PythonInterpreter {
517+
config: InterpreterConfig {
518+
major: *major as usize,
519+
minor: *minor as usize,
520+
interpreter_kind: InterpreterKind::CPython,
521+
abiflags: "".to_string(),
522+
ext_suffix: "".to_string(),
523+
pointer_width: None,
524+
gil_disabled: false,
525+
},
526+
executable: PathBuf::new(),
527+
platform: None,
528+
runnable: false,
529+
implementation_name: "cpython".to_string(),
530+
soabi: None,
531+
}])
532+
} else {
533+
bail!("Failed to find any python interpreter");
530534
}
531535
}
532536
}

0 commit comments

Comments
 (0)