From 8e9e0ce627383fe660f218fe35ade47bba09b753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Meunier?= Date: Tue, 22 Oct 2024 19:40:58 +0200 Subject: [PATCH] Cargo vendor: add source rewriting for private registries included in 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`. --- src/cargo/ops/vendor.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index 35d0e0c9417..dcc6be177d5 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -1,9 +1,10 @@ use crate::core::shell::Verbosity; -use crate::core::{GitReference, Package, Workspace}; +use crate::core::{GitReference, Package, Workspace, EitherManifest}; 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}; @@ -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);