Skip to content

Commit

Permalink
Merge #1362
Browse files Browse the repository at this point in the history
1362: Add workspace lock file to sdist as a fallback r=messense a=messense

See sourmash-bio/sourmash#2393 (comment)

> Figure out how to pull `Cargo.lock` from workspace root.

cc `@luizirber`

Co-authored-by: messense <messense@icloud.com>
  • Loading branch information
bors[bot] and messense committed Dec 19, 2022
2 parents d665558 + 43998a2 commit 3c83f8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
18 changes: 18 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 3c83f8f

Please sign in to comment.