Skip to content

Commit 9177092

Browse files
committed
Try supporting cross compilation with abi3 to windows
1 parent 036fff7 commit 9177092

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/build_options.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::build_context::{BridgeModel, ProjectLayout};
2+
use crate::python_interpreter::InterpreterKind;
23
use crate::BuildContext;
34
use crate::CargoToml;
45
use crate::Manylinux;
@@ -384,15 +385,36 @@ pub fn find_interpreter(
384385
Ok(vec![interpreter])
385386
}
386387
BridgeModel::Bin => Ok(vec![]),
387-
BridgeModel::BindingsAbi3(_, _) => {
388+
BridgeModel::BindingsAbi3(major, minor) => {
388389
// Ideally, we wouldn't want to use any python interpreter without abi3 at all.
389390
// Unfortunately, on windows we need one to figure out base_prefix for a linker
390391
// argument.
391392
if target.is_windows() {
392-
let interpreter =
393-
find_single_python_interpreter(bridge, interpreter, target, "abi3 on windows")?;
394-
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interpreter);
395-
Ok(vec![interpreter])
393+
if let Some(manual_base_prefix) = std::env::var_os("PYO3_CROSS_LIB_DIR") {
394+
// PYO3_CROSS_LIB_DIR equals base_prefix when cross compiling,
395+
// so we fake a python interpreter matching it
396+
println!("⚠ Cross-compiling is poorly supported");
397+
Ok(vec![PythonInterpreter {
398+
major: *major as usize,
399+
minor: *minor as usize,
400+
abiflags: "".to_string(),
401+
target: target.clone(),
402+
executable: PathBuf::new(),
403+
ext_suffix: Some(".pyd".to_string()),
404+
interpreter_kind: InterpreterKind::CPython,
405+
abi_tag: None,
406+
base_prefix: PathBuf::from(manual_base_prefix),
407+
}])
408+
} else {
409+
let interpreter = find_single_python_interpreter(
410+
bridge,
411+
interpreter,
412+
target,
413+
"abi3 on windows",
414+
)?;
415+
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interpreter);
416+
Ok(vec![interpreter])
417+
}
396418
} else {
397419
println!("🐍 Not using a specific python interpreter (With abi3, an interpreter is only required on windows)");
398420
Ok(vec![])

0 commit comments

Comments
 (0)