diff --git a/Changelog.md b/Changelog.md index fcb93a5c4..2a3ba6bb2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * **Breaking Change**: Remove deprecated `python-source` option in `Cargo.toml` in [#1335](https://github.com/PyO3/maturin/pull/1335) * **Breaking Change**: Turn `patchelf` version warning into a hard error in [#1335](https://github.com/PyO3/maturin/pull/1335) * **Breaking Change**: [`uniffi_bindgen` CLI](https://mozilla.github.io/uniffi-rs/tutorial/Prerequisites.html#the-uniffi-bindgen-cli-tool) is required for building `uniffi` bindings wheels in [#1352](https://github.com/PyO3/maturin/pull/1352) +* Add workspace lock file to sdist as a fallback in [#1362](https://github.com/PyO3/maturin/pull/1362) ## [0.14.6] - 2022-12-13 diff --git a/src/source_distribution.rs b/src/source_distribution.rs index ab460bc33..36f6a59ac 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -590,16 +590,27 @@ pub fn source_distribution( let abs_manifest_path = manifest_path.normalize()?.into_path_buf(); let abs_manifest_dir = abs_manifest_path.parent().unwrap(); let cargo_lock_path = abs_manifest_dir.join("Cargo.lock"); + let cargo_lock_exists = cargo_lock_path.exists(); + let workspace_cargo_lock = build_context + .cargo_metadata + .workspace_root + .join("Cargo.lock"); + let workspace_cargo_lock_exists = workspace_cargo_lock.exists(); let cargo_lock_required = build_context.cargo_options.locked || build_context.cargo_options.frozen; - if cargo_lock_required || cargo_lock_path.exists() { + if cargo_lock_required || cargo_lock_exists || workspace_cargo_lock_exists { let project_root = pyproject_toml_path.parent().unwrap(); let relative_cargo_lock = if cargo_lock_path.starts_with(project_root) { cargo_lock_path.strip_prefix(project_root).unwrap() } else { cargo_lock_path.strip_prefix(abs_manifest_dir).unwrap() }; - writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?; + if cargo_lock_exists { + writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?; + } else { + // Fallback to workspace Cargo lock file + writer.add_file(root_dir.join(relative_cargo_lock), workspace_cargo_lock)?; + } } else { eprintln!( "⚠️ Warning: Cargo.lock is not found, it is recommended \ diff --git a/tests/run.rs b/tests/run.rs index 390e056fe..5a5d178d2 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -546,6 +546,22 @@ fn pyo3_mixed_include_exclude_wheel_files() { )) } +#[test] +fn workspace_sdist() { + handle_result(other::test_source_distribution( + "test-crates/workspace/py", + vec![ + "py-0.1.0/Cargo.lock", + "py-0.1.0/Cargo.toml", + "py-0.1.0/PKG-INFO", + "py-0.1.0/pyproject.toml", + "py-0.1.0/src/main.rs", + ], + None, + "sdist-workspace", + )) +} + #[test] fn workspace_with_path_dep_sdist() { handle_result(other::test_source_distribution( @@ -555,6 +571,7 @@ fn workspace_with_path_dep_sdist() { "workspace_with_path_dep-0.1.0/local_dependencies/generic_lib/src/lib.rs", "workspace_with_path_dep-0.1.0/local_dependencies/transitive_lib/Cargo.toml", "workspace_with_path_dep-0.1.0/local_dependencies/transitive_lib/src/lib.rs", + "workspace_with_path_dep-0.1.0/Cargo.lock", "workspace_with_path_dep-0.1.0/Cargo.toml", "workspace_with_path_dep-0.1.0/pyproject.toml", "workspace_with_path_dep-0.1.0/src/lib.rs", @@ -573,6 +590,7 @@ fn workspace_inheritance_sdist() { vec![ "workspace_inheritance-0.1.0/local_dependencies/generic_lib/Cargo.toml", "workspace_inheritance-0.1.0/local_dependencies/generic_lib/src/lib.rs", + "workspace_inheritance-0.1.0/Cargo.lock", "workspace_inheritance-0.1.0/Cargo.toml", "workspace_inheritance-0.1.0/pyproject.toml", "workspace_inheritance-0.1.0/src/lib.rs",