Skip to content

Commit

Permalink
Add support for linking with pyo3 in abi3 debug mode on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Feb 15, 2023
1 parent 4291042 commit 0841694
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 138 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
* Bump MSRV to 1.63.0 in [#1407](https://github.com/PyO3/maturin/pull/1407)
* Add support for uniffi 0.23 in [#1481](https://github.com/PyO3/maturin/pull/1481)
* Add support for Emscripten in `generate-ci` command in [#1484](https://github.com/PyO3/maturin/pull/1484)
* Add support for linking with pyo3 in abi3 debug mode on Windows in [#1487](https://github.com/PyO3/maturin/pull/1487)

## [0.14.13] - 2023-02-12

Expand Down
4 changes: 3 additions & 1 deletion src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ impl BuildContext {
&self.project_layout,
&self.module_name,
&artifact.path,
None,
self.interpreter.first(),
true,
&self.target,
self.editable,
self.pyproject_toml.as_ref(),
Expand Down Expand Up @@ -612,6 +613,7 @@ impl BuildContext {
&self.module_name,
&artifact.path,
Some(python_interpreter),
false,
&self.target,
self.editable,
self.pyproject_toml.as_ref(),
Expand Down
5 changes: 5 additions & 0 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ impl BuildOptions {
implmentation_name: "cpython".to_string(),
soabi: None,
}])
} else if let Some(config_file) = env::var_os("PYO3_CONFIG_FILE") {
let interpreter_config =
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
.context("Invalid PYO3_CONFIG_FILE")?;
Ok(vec![PythonInterpreter::from_config(interpreter_config)])
} else if let Some(interp) = interpreters.get(0) {
println!("🐍 Using {interp} to generate to link bindings (With abi3, an interpreter is only required on windows)");
Ok(interpreters)
Expand Down
22 changes: 14 additions & 8 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,22 +712,28 @@ pub fn write_bindings_module(
module_name: &str,
artifact: &Path,
python_interpreter: Option<&PythonInterpreter>,
is_abi3: bool,
target: &Target,
editable: bool,
pyproject_toml: Option<&PyProjectToml>,
) -> Result<()> {
let ext_name = &project_layout.extension_name;
let so_filename = match python_interpreter {
Some(python_interpreter) => python_interpreter.get_library_name(ext_name),
// abi3
None => {
if target.is_unix() {
format!("{ext_name}.abi3.so")
} else {
let so_filename = if is_abi3 {
if target.is_unix() {
format!("{ext_name}.abi3.so")
} else {
match python_interpreter {
Some(python_interpreter) if python_interpreter.is_windows_debug() => {
format!("{ext_name}_d.pyd")
}
// Apparently there is no tag for abi3 on windows
format!("{ext_name}.pyd")
_ => format!("{ext_name}.pyd"),
}
}
} else {
let python_interpreter =
python_interpreter.expect("A python interpreter is required for non-abi3 build");
python_interpreter.get_library_name(ext_name)
};

if !editable {
Expand Down
5 changes: 5 additions & 0 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ impl PythonInterpreter {
)
}

/// Is this a debug build of Python for Windows?
pub fn is_windows_debug(&self) -> bool {
self.ext_suffix.starts_with("_d.") && self.ext_suffix.ends_with(".pyd")
}

/// Checks whether the given command is a python interpreter and returns a
/// [PythonInterpreter] if that is the case
pub fn check_executable(
Expand Down
20 changes: 10 additions & 10 deletions test-crates/pyo3-abi3-without-version/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions test-crates/pyo3-bin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions test-crates/pyo3-feature/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test-crates/pyo3-ffi-pure/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test-crates/pyo3-ffi-pure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "1.0.0"
edition = "2021"

[dependencies]
pyo3-ffi = { version = "0.17.3", features = ["abi3-py37", "extension-module"] }
pyo3-ffi = { version = "0.18.1", features = ["abi3-py37", "extension-module"] }

[lib]
name = "pyo3_ffi_pure"
Expand Down
20 changes: 10 additions & 10 deletions test-crates/pyo3-mixed-include-exclude/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0841694

Please sign in to comment.