Cargo testing local forks of packages

There's a crate, X, I'm working on a PR for and it used by another crate Y, which is used by program P.

So right now, P depends on Y-1.0.1 and that depends on X-2.5.3.

I am making a change to X so it will be X-2.5.4.

I want to test my change to X on Y & P before I submit it. I think to do this, I will have my X PR update the version to X-2.5.4 and I'll have to make a Y PR to change it to Y-1.0.2 (with a new X-2.5.4 dependency), then I can make P depend on Y-1.0.2.

Given that I don't control either X or Y on crates.io, how can get my local instance of Cargo to notice these changes? I want to do something like

cd x
cargo build
cargo tell-my-machine-about-it
cd ../y
cargo build # gets the new version of x
cargo tell-my-machine-about-it
cd ../p
cargo build # gets the new version of y (which has the new version of x)

But I don't think that cargo tell-my-machine-about-it exists... and clearly I don't know what I should be searching for in Introduction - The Cargo Book

I tried to think through if I should be following the instructions here --- Overriding Dependencies - The Cargo Book --- but it seems weird that I'm modifying the Cargo.toml file with paths in my local system... I don't want to include those in the PR, but I am making some changes to it in the PR, so I'll have to maintain un-committed revisions to the file. I think of what I'm doing as "faking results from crates.io" and so it seems like it should be part of the ambient environment.

Thank you for your help!

You can try using a local registry, like GitHub - moriturus/ktra: Your Little Cargo Registry.

[patch] is the correct way to do this, and yes, it means modifying Cargo.toml. But those should only be needed for testing your change. In particular:

I'll have to make a Y PR to change it to Y-1.0.2 (with a new X-2.5.4 dependency), then I can make P depend on Y-1.0.2.

1.0.2 is a compatible version to 1.0.1, so you do not need to do anything to Y. The only thing that determines whether 1.0.1 or 1.0.2 is used is P's Cargo.lock file.

So, you do not need to PR to Y at all — only to P, and only if P has a committed lock file.

Steps:

  1. Make edits to X.
  2. In your local copy of P, add a [patch] to change the version of X used to be your local copy of X.
  3. Run P's tests to confirm it works.
  4. Send PR to X.
  5. When PR to X is accepted, send PR to P (if applicable).
2 Likes

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.