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

cargo cannot merge crates with the same lockfile commit and rev commit hash #15252

Open
Redhawk18 opened this issue Mar 1, 2025 · 9 comments
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@Redhawk18
Copy link

Problem

Compiling iced_core v0.14.0-dev (https://github.com/iced-rs/iced.git?rev=beddf49c#beddf49c)
Compiling iced_core v0.14.0-dev (https://github.com/iced-rs/iced.git?rev=beddf49c76f3b43e7b33452831e1293cad28fd89#beddf49c)

There should only be one version of this crate

Steps

  1. have two libraries that have different way of versioning git crates. (ie lockfile + rev, rev only, or lockfile only)
  2. cargo will compile the two versions of the same crate

Possible Solution(s)

I did fix this, I just wanted to ask if this is a bug or not with cargo because if it's not it's still silly and needs to be fixed either way.

What I had to do is remove all rev attributes and rely on the Cargo.lock file instead, this is my collection of my application first and then the libraries.
https://github.com/Redhawk18/kuiper/blob/08ebe8d0102ee21a0e23ba611ef97813129c9ca0/Cargo.toml#L48
https://github.com/Redhawk18/iced_aw/blob/4a77e45464b03bb8bd93f92e8c13f1d58670ae3f/Cargo.toml#L70
https://github.com/Redhawk18/iced_fonts/blob/df5e170b74dae255107f3966f1e34dce8b96365a/Cargo.toml#L21

Notes

No response

Version

cargo 1.85.0 (d73d2caf9 2024-12-31)
release: 1.85.0
commit-hash: d73d2caf9e41a39daf2a8d6ce60ec80bf354d2a7
commit-date: 2024-12-31
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.12.1 (sys:0.4.74+curl-8.9.0 system ssl:OpenSSL/3.4.1)
os: NixOS 24.11.0 [64-bit]
@Redhawk18 Redhawk18 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 1, 2025
@weihanglo
Copy link
Member

Thanks for the bug report. By just skimming at the two “Compiling” statuses, I think this is a duplicate of this issue:

Cargo as of now considers different git URLs as different sources.
If you want to consolidate them, consider using full hash in rev.

Going to close as a dup of #7497, if you don't mind.

@Redhawk18
Copy link
Author

Thanks for the bug report. By just skimming at the two “Compiling” statuses, I think this is a duplicate of this issue:

* [Cargo should reference git dependencies by commit hash instead of url #7497](https://github.com/rust-lang/cargo/issues/7497)

Cargo as of now considers different git URLs as different sources. If you want to consolidate them, consider using full hash in rev.

Going to close as a dup of #7497, if you don't mind.

I'm saying the rev attitude causes this problem, this is a bug with that.

@weihanglo
Copy link
Member

weihanglo commented Mar 1, 2025

I'm saying the rev attitude causes this problem, this is a bug with that.

Sorry not being clearer. That was exactly what I was talking about. If you have two git dependency of the same package on the same revision, but the rev fields are specified with different length of the hash (e.g. one only have 7-char length, and the other has 40), Cargo considers them from different source so compile twice.

@weihanglo
Copy link
Member

If this is not the issue you are talking about, please give a minimal reproducible example so we can investigate.

@Redhawk18
Copy link
Author

I'm saying the rev attitude causes this problem, this is a bug with that.

Sorry not being clearer. That was exactly what I was talking about. If you have two git dependency of the same package on the same revision, but the rev fields are specified with different length of the hash (e.g. one only have 7-char length, and the other has 40), Cargo considers them from different source so compile twice.

When I was testing this, the length did not make a difference.

@Redhawk18
Copy link
Author

If this is not the issue you are talking about, please give a minimal reproducible example so we can investigate.

the three rust projects above are versioned at the correct commits to test and play around with to see what I was describing, I could never get rev to work.

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. labels Mar 1, 2025
@weihanglo
Copy link
Member

I'll give it a shot when I am available. If you could show a reproduction of how you specify the full hash but still not working, it would be great.

@weihanglo weihanglo reopened this Mar 1, 2025
@Redhawk18
Copy link
Author

I made these changes to those projects

iced aw

diff --git a/Cargo.toml b/Cargo.toml
index 11abb3d..997130c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -70,14 +70,15 @@ web-time = "1.1.0"
 [dependencies.iced]
 version = "0.14.0-dev"
 git = "https://github.com/iced-rs/iced.git"
-# rev = "beddf49c"
+rev = "beddf49c76f3b43e7b33452831e1293cad28fd89"
 default-features = false
 features = ["advanced", "wgpu"]
 
 [dependencies.iced_fonts]
 version = "0.2.0"
-git = "https://github.com/redhawk18/iced_fonts.git"
-branch = "next"
+# git = "https://github.com/redhawk18/iced_fonts.git"
+# branch = "next"
+path = "../iced_fonts/"
 
 # [profile.dev.package."*"]
 # opt-level = 2

iced fonts

diff --git a/Cargo.toml b/Cargo.toml
index 7500cda..73ce729 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,8 +23,8 @@ iced_core = "0.14.0-dev"
 iced_widget = "0.14.0-dev"
 
 [patch.crates-io]
-iced_core = { git = "https://github.com/iced-rs/iced.git" }
-iced_widget = { git = "https://github.com/iced-rs/iced.git" }
+iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }
+iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }
 
 [package.metadata.docs.rs]
 features = ["required", "full"]

kuiper

diff --git a/Cargo.toml b/Cargo.toml
index a1b4a83..d7d73cb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -50,5 +50,7 @@ iced = { git = 'https://github.com/iced-rs/iced.git' }
 iced_core = { git = 'https://github.com/iced-rs/iced.git' }
 iced_runtime = { git = 'https://github.com/iced-rs/iced.git' }
 iced_widget = { git = 'https://github.com/iced-rs/iced.git' }
-iced_aw = { git = 'https://github.com/redhawk18/iced_aw.git' }
-iced_fonts = { git = 'https://github.com/redhawk18/iced_fonts.git', branch = "next" }
+# iced_aw = { git = 'https://github.com/redhawk18/iced_aw.git' }
+iced_aw = { path = "../iced_aw/" }
+# iced_fonts = { git = 'https://github.com/redhawk18/iced_fonts.git', branch = "next" }
+iced_fonts = { path = "../iced_fonts/" }

Also please notice that kuiper compiles before you apply these patch files, so the double crates causes compiler errors.

@weihanglo
Copy link
Member

Ahh! saw some common mistakes in your previous attempt.

First, run cargo tree -i iced_core and you'll see:

$ cargo tree -i iced_core
error: There are multiple `iced_core` packages in your project, and the specification `iced_core` is ambiguous.
Please re-run this command with one of the following specifications:
  git+https://github.com/iced-rs/iced.git?rev=beddf49c76f3b43e7b33452831e1293cad28fd89#iced_core@0.14.0-dev
  git+https://github.com/iced-rs/iced.git#iced_core@0.14.0-dev

And then disambiguate it

$ cargo tree -i git+https://github.com/iced-rs/iced.git#iced_core@0.14.0-dev
iced_core v0.14.0-dev (https://github.com/iced-rs/iced.git#beddf49c)
|-- iced v0.14.0-dev (https://github.com/iced-rs/iced.git#beddf49c)
|   `-- kuiper_gui v0.1.0 (/workspace/kuiper/gui)
|       `-- kuiper v0.1.0 (/workspace/kuiper)
|-- iced_fonts v0.2.0 (/workspace/iced_fonts)
|   |-- iced_aw v0.12.1 (/workspace/iced_aw)
|   |   `-- kuiper_gui v0.1.0 (/workspace/kuiper/gui) (*)
|   `-- kuiper_gui v0.1.0 (/workspace/kuiper/gui) (*)
|-- iced_futures v0.14.0-dev (https://github.com/iced-rs/iced.git#beddf49c)
|   |-- iced v0.14.0-dev (https://github.com/iced-rs/iced.git#beddf49c) (*)
...

So it is clearly that iced_core from this kuiper -> kuiper_gui -> iced dependency chain didn't really get patched. It was still the git dependency without any revision to disambiguate. That was because in the [patch.crates-io] section in kuiper/Cargo.toml, iced was only specified with git repo but not rev field. However, in iced_aw it was specified with an exact rev as a real git dependency, hence two iced_core are different based on my previous explanation and #7497. In addition, the [patch.crates-io] section in iced_fonts/Cargo.toml did nothing because it was not the root workspace (assumed you ran cargo build from kuiper) so ignored. See the last sentence of the doc about it.

Since iced is a Cargo workspace having a handful of packages, which depend on each other intertwinedly. If you add full commit hash to patch only one package like iced_widget, it won't work because iced_core from kuiper->iced won't get patched. As a result, Cargo will consider them different.

The solution should be simple: updating kuiper/Cargo.toml like this:

 [patch.crates-io]
-iced = { git = 'https://github.com/iced-rs/iced.git' }
-iced_core = { git = 'https://github.com/iced-rs/iced.git' }
-iced_runtime = { git = 'https://github.com/iced-rs/iced.git' }
-iced_widget = { git = 'https://github.com/iced-rs/iced.git' }
+iced = { git = 'https://github.com/iced-rs/iced.git', rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }
+iced_core = { git = 'https://github.com/iced-rs/iced.git', rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }
+iced_runtime = { git = 'https://github.com/iced-rs/iced.git', rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }
+iced_widget = { git = 'https://github.com/iced-rs/iced.git', rev = "beddf49c76f3b43e7b33452831e1293cad28fd89" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants