Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a certain commit in dependencies in Cargo.toml?

I am trying to configure my Rust project with an external dependency in GitHub. Unfortunately, some last commits made some changes in interfaces so I am unable to use the latest version. The developers also do not care of tags and separate branches for different versions, so I think the only correct way is to specify a certain commit somehow where the interface fits what I worked with.

What I have now in Cargo.toml is:

[dependencies] ... thelib = { git = 'https://github.com/someguys/thelib' } 

I saw it is possible to specify a branch like this:

thelib = { git = 'https://github.com/someguys/thelib', branch = 'branch1' } 

But I have not seen a working example with a commit. Could anybody provide one here?

like image 590
Fomalhaut Avatar asked Jan 15 '19 10:01

Fomalhaut


1 Answers

As hinted in the Cargo.toml vs Cargo.lock section of the Cargo guide, you can use the rev property to specify a commit hash:

[...] If you build this package today, and then you send a copy to me, and I build this package tomorrow, something bad could happen. There could be more commits to rand in the meantime, and my build would include new commits while yours would not. Therefore, we would get different builds. This would be bad because we want reproducible builds.

We could fix this problem by putting a rev line in our Cargo.toml:

[dependencies] rand = { git = "https://github.com/rust-lang-nursery/rand.git", rev = "9f35b8e" } 

It is also mentioned in Specifying dependencies, although no example is given (emphasis mine):

Since we haven’t specified any other information, Cargo assumes that we intend to use the latest commit on the master branch to build our package. You can combine the git key with the rev, tag, or branch keys to specify something else. [...]

like image 100
E_net4 stands with Ukraine Avatar answered Sep 23 '22 21:09

E_net4 stands with Ukraine