Skip to content

Commit 83e6b70

Browse files
bors[bot]messense
andauthored
Merge #1487
1487: Add support for linking with pyo3 in abi3 debug mode on Windows r=messense a=messense Closes #1465 Co-authored-by: messense <[email protected]>
2 parents 6e59dad + a4fe0ed commit 83e6b70

File tree

21 files changed

+159
-140
lines changed

21 files changed

+159
-140
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
# Just for test, come back to upstream after released
128128
uses: Xuanwo/sccache-action@c94e27bef21ab3fb4a5152c8a878c53262b4abb0
129129
with:
130-
version: "v0.4.0-pre.6"
130+
version: "v0.4.0-pre.7"
131131
- uses: actions/checkout@v3
132132
- uses: conda-incubator/setup-miniconda@v2
133133
with:
@@ -443,7 +443,7 @@ jobs:
443443
if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
444444
uses: Xuanwo/sccache-action@c94e27bef21ab3fb4a5152c8a878c53262b4abb0
445445
with:
446-
version: "v0.4.0-pre.6"
446+
version: "v0.4.0-pre.7"
447447
- uses: actions/setup-python@v4
448448
if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
449449
with:

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* Bump MSRV to 1.63.0 in [#1407](https://github.com/PyO3/maturin/pull/1407)
1818
* Add support for uniffi 0.23 in [#1481](https://github.com/PyO3/maturin/pull/1481)
1919
* Add support for Emscripten in `generate-ci` command in [#1484](https://github.com/PyO3/maturin/pull/1484)
20+
* Add support for linking with pyo3 in abi3 debug mode on Windows in [#1487](https://github.com/PyO3/maturin/pull/1487)
2021

2122
## [0.14.13] - 2023-02-12
2223

src/build_context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ impl BuildContext {
533533
&self.project_layout,
534534
&self.module_name,
535535
&artifact.path,
536-
None,
536+
self.interpreter.first(),
537+
true,
537538
&self.target,
538539
self.editable,
539540
self.pyproject_toml.as_ref(),
@@ -612,6 +613,7 @@ impl BuildContext {
612613
&self.module_name,
613614
&artifact.path,
614615
Some(python_interpreter),
616+
false,
615617
&self.target,
616618
self.editable,
617619
self.pyproject_toml.as_ref(),

src/build_options.rs

+5
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ impl BuildOptions {
371371
implmentation_name: "cpython".to_string(),
372372
soabi: None,
373373
}])
374+
} else if let Some(config_file) = env::var_os("PYO3_CONFIG_FILE") {
375+
let interpreter_config =
376+
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
377+
.context("Invalid PYO3_CONFIG_FILE")?;
378+
Ok(vec![PythonInterpreter::from_config(interpreter_config)])
374379
} else if let Some(interp) = interpreters.get(0) {
375380
println!("🐍 Using {interp} to generate to link bindings (With abi3, an interpreter is only required on windows)");
376381
Ok(interpreters)

src/module_writer.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -712,22 +712,28 @@ pub fn write_bindings_module(
712712
module_name: &str,
713713
artifact: &Path,
714714
python_interpreter: Option<&PythonInterpreter>,
715+
is_abi3: bool,
715716
target: &Target,
716717
editable: bool,
717718
pyproject_toml: Option<&PyProjectToml>,
718719
) -> Result<()> {
719720
let ext_name = &project_layout.extension_name;
720-
let so_filename = match python_interpreter {
721-
Some(python_interpreter) => python_interpreter.get_library_name(ext_name),
722-
// abi3
723-
None => {
724-
if target.is_unix() {
725-
format!("{ext_name}.abi3.so")
726-
} else {
721+
let so_filename = if is_abi3 {
722+
if target.is_unix() {
723+
format!("{ext_name}.abi3.so")
724+
} else {
725+
match python_interpreter {
726+
Some(python_interpreter) if python_interpreter.is_windows_debug() => {
727+
format!("{ext_name}_d.pyd")
728+
}
727729
// Apparently there is no tag for abi3 on windows
728-
format!("{ext_name}.pyd")
730+
_ => format!("{ext_name}.pyd"),
729731
}
730732
}
733+
} else {
734+
let python_interpreter =
735+
python_interpreter.expect("A python interpreter is required for non-abi3 build");
736+
python_interpreter.get_library_name(ext_name)
731737
};
732738

733739
if !editable {

src/python_interpreter/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ impl PythonInterpreter {
539539
)
540540
}
541541

542+
/// Is this a debug build of Python for Windows?
543+
pub fn is_windows_debug(&self) -> bool {
544+
self.ext_suffix.starts_with("_d.") && self.ext_suffix.ends_with(".pyd")
545+
}
546+
542547
/// Checks whether the given command is a python interpreter and returns a
543548
/// [PythonInterpreter] if that is the case
544549
pub fn check_executable(

test-crates/pyo3-abi3-without-version/Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-crates/pyo3-bin/Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-crates/pyo3-feature/Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-crates/pyo3-ffi-pure/Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-crates/pyo3-ffi-pure/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "1.0.0"
44
edition = "2021"
55

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

99
[lib]
1010
name = "pyo3_ffi_pure"

test-crates/pyo3-mixed-include-exclude/Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)