Skip to content

Commit

Permalink
Add support for generate-import-lib feature of pyo3
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 14, 2022
1 parent 9ab1713 commit 6695343
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ impl BuildOptions {
None => PathBuf::from(&cargo_metadata.target_directory).join("wheels"),
};

let generate_abi3_import_lib = is_generating_abi3_import_lib(&cargo_metadata)?;
let generate_import_lib = is_generating_import_lib(&cargo_metadata)?;
let interpreter = if self.interpreter.is_empty() {
// Auto-detect interpreters
find_interpreter(
&bridge,
&[],
&target,
get_min_python_minor(&metadata21),
generate_abi3_import_lib,
generate_import_lib,
)?
} else {
// User given list of interpreters
Expand All @@ -293,7 +293,7 @@ impl BuildOptions {
&self.interpreter,
&target,
None,
generate_abi3_import_lib,
generate_import_lib,
)?
};

Expand Down Expand Up @@ -468,8 +468,8 @@ fn has_abi3(cargo_metadata: &Metadata) -> Result<Option<(u8, u8)>> {
}

/// pyo3 0.16.4+ supports building abi3 wheels without a working Python interpreter for Windows
/// when `generate-abi3-import-lib` feature is enabled
fn is_generating_abi3_import_lib(cargo_metadata: &Metadata) -> Result<bool> {
/// when `generate-import-lib` feature is enabled
fn is_generating_import_lib(cargo_metadata: &Metadata) -> Result<bool> {
let resolve = cargo_metadata
.resolve
.as_ref()
Expand All @@ -485,7 +485,7 @@ fn is_generating_abi3_import_lib(cargo_metadata: &Metadata) -> Result<bool> {
let generate_import_lib = pyo3_crate
.features
.iter()
.any(|x| x == "generate-abi3-import-lib");
.any(|x| x == "generate-import-lib" || x == "generate-abi3-import-lib");
return Ok(generate_import_lib);
}
_ => continue,
Expand Down Expand Up @@ -701,7 +701,7 @@ pub fn find_interpreter(
interpreter: &[PathBuf],
target: &Target,
min_python_minor: Option<usize>,
generate_abi3_import_lib: bool,
generate_import_lib: bool,
) -> Result<Vec<PythonInterpreter>> {
match bridge {
BridgeModel::Bindings(binding_name, _) => {
Expand All @@ -715,10 +715,7 @@ pub fn find_interpreter(
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
.context("Invalid PYO3_CONFIG_FILE")?;
interpreters.push(PythonInterpreter::from_config(interpreter_config));
} else if binding_name.starts_with("pyo3")
&& target.is_unix()
&& target.cross_compiling()
{
} else if binding_name.starts_with("pyo3") && target.cross_compiling() {
if let Some(cross_lib_dir) = std::env::var_os("PYO3_CROSS_LIB_DIR") {
let host_interpreters =
find_interpreter_in_host(bridge, interpreter, target, min_python_minor)?;
Expand Down Expand Up @@ -863,7 +860,7 @@ pub fn find_interpreter(
} else if let Some(interp) = interpreter.get(0) {
println!("🐍 Using {} to generate to link bindings (With abi3, an interpreter is only required on windows)", interp);
Ok(interpreter)
} else if generate_abi3_import_lib {
} else if generate_import_lib {
println!("🐍 Not using a specific python interpreter (Automatically generating windows import library)");
// fake a python interpreter
Ok(vec![PythonInterpreter {
Expand Down

0 comments on commit 6695343

Please sign in to comment.