Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for linking with pyo3 in abi3 debug mode on Windows #1487

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
# Just for test, come back to upstream after released
uses: Xuanwo/sccache-action@c94e27bef21ab3fb4a5152c8a878c53262b4abb0
with:
version: "v0.4.0-pre.6"
version: "v0.4.0-pre.7"
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
with:
Expand Down Expand Up @@ -446,7 +446,7 @@ jobs:
if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
uses: Xuanwo/sccache-action@c94e27bef21ab3fb4a5152c8a878c53262b4abb0
with:
version: "v0.4.0-pre.6"
version: "v0.4.0-pre.7"
- uses: actions/setup-python@v4
if: ${{ steps.changes.outputs.changed == 'true' || contains(github.event.pull_request.labels.*.name, 'release') }}
with:
Expand Down
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