From cc5fc3be39ba0b1e432d5f2fde312876f36bdcc5 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 15 Jun 2022 17:14:33 +0800 Subject: [PATCH] Fix auditwheel bundled shared libs directory name Previous the `pyo3-mixed-py-subdir` crate would produce `_pyo3_mixed.libs`, now it produces `pyo3_mixed_py_subdir.libs`. --- src/build_context.rs | 11 +++++++++-- test-crates/pyo3-mixed-py-subdir/Cargo.toml | 1 + .../python/pyo3_mixed_py_subdir/__init__.py | 2 +- test-crates/pyo3-mixed-py-subdir/src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/build_context.rs b/src/build_context.rs index e5b41a536..1584369e0 100644 --- a/src/build_context.rs +++ b/src/build_context.rs @@ -101,7 +101,7 @@ impl ProjectLayout { Cow::Owned(project_root.join(py_src)) }); let (python_module, rust_module, extension_name) = if parts.len() > 1 { - let mut rust_module = project_root.to_path_buf(); + let mut rust_module = python_root.to_path_buf(); rust_module.extend(&parts[0..parts.len() - 1]); ( python_root.join(parts[0]), @@ -337,7 +337,14 @@ impl BuildContext { } // Put external libs to ${module_name}.libs directory // See https://github.com/pypa/auditwheel/issues/89 - let libs_dir = PathBuf::from(format!("{}.libs", self.module_name)); + let mut libs_dir = self + .project_layout + .python_module + .as_ref() + .and_then(|py| py.file_name().map(|s| s.to_os_string())) + .unwrap_or(self.project_layout.extension_name.clone().into()); + libs_dir.push(".libs"); + let libs_dir = PathBuf::from(libs_dir); writer.add_directory(&libs_dir)?; let temp_dir = tempfile::tempdir()?; diff --git a/test-crates/pyo3-mixed-py-subdir/Cargo.toml b/test-crates/pyo3-mixed-py-subdir/Cargo.toml index 9a4d64532..ad749d416 100644 --- a/test-crates/pyo3-mixed-py-subdir/Cargo.toml +++ b/test-crates/pyo3-mixed-py-subdir/Cargo.toml @@ -15,3 +15,4 @@ crate-type = ["cdylib"] [package.metadata.maturin] python-source = "python" +name = "pyo3_mixed_py_subdir._pyo3_mixed" diff --git a/test-crates/pyo3-mixed-py-subdir/python/pyo3_mixed_py_subdir/__init__.py b/test-crates/pyo3-mixed-py-subdir/python/pyo3_mixed_py_subdir/__init__.py index fd165e408..76661a975 100644 --- a/test-crates/pyo3-mixed-py-subdir/python/pyo3_mixed_py_subdir/__init__.py +++ b/test-crates/pyo3-mixed-py-subdir/python/pyo3_mixed_py_subdir/__init__.py @@ -1,5 +1,5 @@ from .python_module.double import double -from .pyo3_mixed_py_subdir import get_21 +from ._pyo3_mixed import get_21 def get_42() -> int: diff --git a/test-crates/pyo3-mixed-py-subdir/src/lib.rs b/test-crates/pyo3-mixed-py-subdir/src/lib.rs index e52a7d921..b5f56a239 100644 --- a/test-crates/pyo3-mixed-py-subdir/src/lib.rs +++ b/test-crates/pyo3-mixed-py-subdir/src/lib.rs @@ -6,7 +6,7 @@ fn get_21() -> usize { } #[pymodule] -fn pyo3_mixed_py_subdir(_py: Python, m: &PyModule) -> PyResult<()> { +fn _pyo3_mixed(_py: Python, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(get_21))?; Ok(())