Skip to content

Commit

Permalink
Merge pull request #918 from messense/generate-import-lib
Browse files Browse the repository at this point in the history
Add support for `generate-import-lib` feature of pyo3
  • Loading branch information
messense authored May 14, 2022
2 parents 9ab1713 + 8326ab0 commit cef46c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Allow stubs-only mixed project layout in [#914](https://github.com/PyO3/maturin/pull/914)
* Allow setting the publish user name via `MATURIN_USERNAME` in [#915](https://github.com/PyO3/maturin/pull/915)
* Add Windows python sysconfig in [#917](https://github.com/PyO3/maturin/pull/917)
* Add support for `generate-import-lib` feature of pyo3 in [#918](https://github.com/PyO3/maturin/pull/918)

## [0.12.15] - 2022-05-07

Expand Down
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 cef46c3

Please sign in to comment.