Why did cargo vendor fail to write the checksum for a crate in a Git repository?

Viewed 593

I have a Rust project where I vendor my dependencies. This is what my .cargo/config.toml looks like:

# Vendor dependencies from crates.io (but do not check them into Git.)
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"

After some time, I added a Rust crate in a GitHub repository (not crates.io) to my Cargo.toml, which now has a section that looks like:

[dependencies.symphonia]
git = "https://github.com/neocrym-forks/Symphonia"
rev = "2cafae82b664ceb14dd5d058f534574399764165"

But now when I run the command cargo vendor --versioned-dirs --quiet, I get the following error message:

error: failed to sync

Caused by:
  failed to write `vendor/symphonia-0.3.0/.cargo-checksum.json`

What went wrong?

1 Answers

tl;dr: Set your $CARGO_HOME to a directory that you can write to.

The failed to write error is happening because Cargo cannot find where it "git cloned" the repository from GitHub. Normally, those repositories are cloned to $CARGO_HOME/git/checkouts and then are copied to the vendor directory.

In my case, I was using a CI image that was confused about the correct value of $CARGO_HOME because Rust was installed by the root user in a location not writeable by the non-root CI user.

I reset my $CARGO_HOME to a directory that my non-root user can write to, and it worked.

Related