我依赖于crate a
和b
,其中我将b
补丁为一个git
依赖项,其引用的版本为foo
:
# Cargo.toml of my crate
[dependencies]
a = "1.0.0"
b = "1.0.0"
[patch.crates-io]
b = { git = "https://github.com/user/example", rev = "foo" }
a
也作为 git 依赖项依赖于 b
,但没有特定的 ref
:
# Cargo.toml of a
[dependencies]
b = { git = "https://github.com/user/example" }
我想要强制使用b
和我的代码相同的ref
,我尝试了以下方法:
# The ideal Cargo.toml of my crate
[dependencies]
a = "1.0.0"
b = "1.0.0"
# patch local dependency
[patch.crates-io]
b = { git = "https://github.com/user/example", rev = "foo" }
# patch transient dependency
[patch.'https://github.com/user/example']
b = { git = "https://github.com/user/example", rev = "foo" }
但是这种方法行不通,因为我正在打补丁的源代码仍然指向相同的源代码,只是在不同的 rev
中:
error: failed to resolve patches for `https://github.com/user/example`
Caused by:
patch for `b` in `https://github.com/user/example` points to the same source, but patches must point to different sources
[Finished running. Exit status: 101]
到目前为止,我的解决方法是 fork b
然后进行以下修补:
# Cargo.toml of my crate using a work around
[dependencies]
a = "1.0.0"
b = "1.0.0"
[patch.crates-io]
b = { git = "https://github.com/me/example", rev = "foo" } # Using my fork
[patch.'https://github.com/user/example']
b = { git = "https://github.com/me/example", rev = "foo" } # Using my fork
这个方法可以工作,但是fork实际上没有用处。有没有更好的方法?
我尝试了这种方法,但是它也不起作用,因为它忽略了rev
。整个GitHub问题让人觉得目前并不支持我的尝试,但很难确定,因为它并不完全是同一个功能。
cargo fetch --locked && cargo build --frozen
。 - lnl