Compute the shasum2 of a crate's source

Suppose we have the following crates:

  • crate msg: defines some structs / enums

  • crate server: depends on crate msg

  • crate client: depends on crate msg

now, I want a way to ensure that crate server & crate client can check that they used the same version of crate msg. Is there for crate server/client to get a shasum2 of the src of the crate mst they used? (This way, if after a change, only one of the two crates is recompiled, we can easily detect a version mismatch.)

EDIT: I want something auto generated, not something programmer has to manually update, as I may forget to update after a change.

I do not know if it covers your use case, but something to look into is SVH (strict version hash) and related issues.

1 Like

It is not obvious to me how to use any of the 3 techniques to solve the problem at hand, but I do agree with you they are in the right ballpark of "checksum-ing crate"

If you can compare the common msg crate by version number instead of source hash, then the cargo-lock crate may work. In a build script on each dependent crate, you can call Lockfile::load("Cargo.lock"), find the Package by name corresponding to msg, then store the Version of that package in a common location. (Note that Package also has a checksum field, but it only contains a value when the package is downloaded from a registry like crates.io.)

This requires manually updating the version number right? The problem here is I'm using IntelliJ, which jumps me between crates on "goto def"; so there are times where I am modifying crate msg in the flow of IntelliJ editing, and not even consciously aware of "oh, I'm in the crate msg now".

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.