Skip to content

Heuristics to include Cargo.lock or not in a package are suboptimal #13447

Closed
@sdroege

Description

@sdroege

Problem

Context is: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/499

The setup here is a workspace with multiple cdylib/staticlib/rlib crates. When publishing them, the ones with an example or binary will have their Cargo.lock included in the package, the others not:

    /// Returns if package should include `Cargo.lock`.
    pub fn include_lockfile(&self) -> bool {
        self.targets().iter().any(|t| t.is_example() || t.is_bin())
    }

This seems a bit arbitrary in this situation. Some of the crates have examples, some not 🤷

In practice this causes problems if people get the crates from crates.io and try to build the cdylib/staticlib, e.g. via cargo-c, and use --frozen to ensure that the same Cargo.lock is used as during publishing.

Steps

  1. Create a cdylib crate
  2. cargo publish --dry-run and check whether the Cargo.lock is included in target/package` (it is not)
  3. Add an example to the crate
  4. cargo publish --dry-run and check whether the Cargo.lock is included in target/package` (it is included now)

Possible Solution(s)

I would suggest to update the heuristic above to either include cdylib/staticlib crates, and/or to provide some kind of configuration in Cargo.toml whether the Cargo.lock should be included or not.

If something is decided, I'd be happy to implement this.

Notes

No response

Version

cargo 1.76.0 (c84b36747 2024-01-18)
release: 1.76.0
commit-hash: c84b367471a2db61d2c2c6aab605b14130b8a31b
commit-date: 2024-01-18
host: x86_64-unknown-linux-gnu
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Fedora 39.0.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-packageCommand-publishS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions