# Is There An Elegant Way to Support Latest Git and Latest Release Dependencies?

**URL:** <https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688>\
**Category:** help\
**Created:** [January 26, 2021, 7:43pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688 "2021-01-26T19:43:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zicklag](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicklag/32/11369_2.png) [@zicklag](https://users.rust-lang.org/u/zicklag)\
**Post date:** [January 26, 2021, 7:43pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/1 "2021-01-26T19:43:58Z")

</div>

I've got an issue where I want to publish a crate, but I want it to be usable for both the latest release of Bevy, which right now is 0.4 and the latest git version of Bevy ( 0.5, but unreleased ) I tried something like this in my Cargo.toml, but it doesn't like the Git repo dep:

```nohighlight
[features]
default = ["bevy-0-4"]
bevy-0-4 = ["bevy_0_4"]
bevy-0-5 = ["bevy_0_5"]

[dependencies]
bevy_0_4 = { package = "bevy", version = "0.4", optional = true }
bevy_0_5 = { package = "bevy", version = "0.5", git = "https://github.com/bevyengine/bevy.git", optional = true }

```

From what I've seen this is impossible because [crates.io](http://crates.io) doesn't tolerate the Git dependency, but I wanted to post here just to make sure nobody has ever managed this first.

---

<div class="post-metadata">

**Author:** ![alice](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alice/32/9777_2.png) [@alice](https://users.rust-lang.org/u/alice)\
**Post date:** [January 26, 2021, 7:48pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/2 "2021-01-26T19:48:40Z")

</div>

Write the dependency normally without the `git` marker. The users of your crate can then use a [`[patch.crates-io]`](https://doc.rust-lang.org/edition-guide/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html) section in their `Cargo.toml` to override _your_ dependency to the git one.

---

<div class="post-metadata">

**Author:** ![zicklag](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicklag/32/11369_2.png) [@zicklag](https://users.rust-lang.org/u/zicklag)\
**Post date:** [January 26, 2021, 7:52pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/3 "2021-01-26T19:52:26Z")

</div>

Ah, that's actually pretty nice. Thanks!

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [January 27, 2021, 1:46pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/4 "2021-01-27T13:46:15Z")

</div>

`[patch]` only works when the version in the `Cargo.toml` of the override is the same as the original version.

---

<div class="post-metadata">

**Author:** ![dekellum](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/dekellum/32/8063_2.png) [@dekellum](https://users.rust-lang.org/u/dekellum)\
**Post date:** [January 27, 2021, 2:25pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/5 "2021-01-27T14:25:19Z")

</div>

No offense intended, but…

#### Is there some chance that this might be an _XY Problem_?

You say you want your published crate...

> to be usable **for** both [versions of bevy]

(my emphasis) Does that imply that bevy will be calling your published crate? In that case is bevy in the Cargo.toml you show above, really more of a dev-dependency? Or is there some other way that you can break the seemingly circular dependency?

---

<div class="post-metadata">

**Author:** ![zicklag](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicklag/32/11369_2.png) [@zicklag](https://users.rust-lang.org/u/zicklag)\
**Post date:** [January 27, 2021, 5:04pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/6 "2021-01-27T17:04:59Z")

</div>

@dekellum my crate is a Bevy plugin, so Bevy will be using it, and it will be using Bevy. The user using my crate will have something like this in the Cargo TOML, in the case that they want to use master version of Bevy:

```nohighlight
[dependencies]
bevy = "0.4.0"
bevy_ldtk = { path = "../bevy_ldtk", features = ["bevy-unstable"] }

[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy.git "}

```

---

<div class="post-metadata">

**Author:** ![dekellum](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/dekellum/32/8063_2.png) [@dekellum](https://users.rust-lang.org/u/dekellum)\
**Post date:** [January 27, 2021, 5:06pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/7 "2021-01-27T17:06:26Z")

</div>

So I don't know anything about Bevy, but are your sure you can't make your Bevy dependency a dev-dependency or a build-depedency only?

Or maybe Bevy should ideally have a split out second crate, e.g. bevy-plugin-interface that you could have as a dependency?

---

<div class="post-metadata">

**Author:** ![zicklag](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicklag/32/11369_2.png) [@zicklag](https://users.rust-lang.org/u/zicklag)\
**Post date:** [January 27, 2021, 5:08pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/8 "2021-01-27T17:08:12Z")

</div>

Yes, because I need to `use` bevy's types and such in the Plugin, for instance I need to implement the `BevyPlugin` trait.

Maybe it could be split out to an interface, but technically that'd have the same issue, because the interface could still have breaking changes just like the crate itself.

It's fine that they have to do a weird patch thing anyway, I think, because if they are using Bevy from master, they're already going off the beaten road a bit.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [April 27, 2021, 5:08pm UTC](https://users.rust-lang.org/t/is-there-an-elegant-way-to-support-latest-git-and-latest-release-dependencies/54688/9 "2021-04-27T17:08:43Z")

</div>

Closed on April 27, 2021, 5:08pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
