Skip to content

Commit

Permalink
Cargo vendor: add source rewriting for private registries included in…
Browse files Browse the repository at this point in the history
… deps

In the case where the exact same dependency is supplied by two different registries, Cargo.lock keeps only one. However, in that case, the output of `cargo vendor` contains only the registry from Cargo.lock, which isn't enough to compile with `--offline`.

This commit adds the dependencies' registries of all vendored packages to the output of `cargo vendor`.
  • Loading branch information
P-E-Meunier committed Oct 22, 2024
1 parent edd36eb commit 2cd324b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::core::shell::Verbosity;
use crate::core::{GitReference, Package, Workspace};
use crate::core::{EitherManifest, GitReference, Package, Workspace};
use crate::ops;
use crate::sources::path::PathSource;
use crate::sources::CRATES_IO_REGISTRY;
use crate::util::cache_lock::CacheLockMode;
use crate::util::toml::read_manifest;
use crate::util::{try_canonicalize, CargoResult, GlobalContext};
use anyhow::{bail, Context as _};
use cargo_util::{paths, Sha256};
Expand Down Expand Up @@ -203,6 +204,13 @@ fn sync(
id.name().to_string()
};

let t = read_manifest(&src.join("Cargo.toml"), id.source_id(), gctx)?;
if let EitherManifest::Real(m) = t {
for d in m.dependencies() {
sources.insert(d.source_id());
}
}

sources.insert(id.source_id());
let dst = canonical_destination.join(&dst_name);
to_remove.remove(&dst);
Expand Down

0 comments on commit 2cd324b

Please sign in to comment.