Hi,
In our rust project, we came up with the need of modifying external crates.
Our project is a workspace with a library mylib
and the following Cargo.toml:
[package]
name = "mylib"
[dev-dependencies]
rstest = 0.12.0
As we need to modfiy the source-code of rstest
a bit, we use git subtree
to clone
the source-code of rstest into external/rstest
.
We do our modifications as expected, need to find a way to make mylib
use our patched version of the rstest
crate.
Solution 1: Set the path
We can modify our library Cargo.toml to point directly to the package we need by using the path:
[package]
name = "mylib"
[dev-dependencies]
rstest = { path = "external/rstest" }
And this exactly what we want but unfortunately there is one drawback.
The subtree in external/rstest
is also a Cargo workspace. Therefore, we finally end up with a workspace in a workspace. This is currently not supported by Cargo.
Solution 2: Patch the crate
We modify our workspace by patching crates.io to use our version of rstest
instead.
In our workspace Cargo.toml we write
[patch.crates-io]
rstest = { path = "external/rstest" }
This solution works fine until rstest gets a new version on crates.io. Then the patched version which is 0.12.0
will not be used anymore, but the newer version from crates.io is consumed.
Also, developers might oversee the need of using the patched crate and simply update the version dependency of rstest
to a newer version.
Possible Solution 3: Use an own registry
It would be nice to handle our external
patched crates in a kind of own registry. As of now, it's possible to define a registry in config.toml
with
[source.my-vendor-source]
directory = "external"
and corresponding library Cargo.toml
rstest = { version = "0.12.0", registry = "my-vendor-source" }
But I was not able to make it work, as the registry will need an index first.
And I am also not sure if it makes sense to simulate a local registry for this use case.
So my question to the community :
How do you solve this ?
Thanks,
Peter