Open
Description
Problem
A minimal example:
fn main() -> anyhow::Result<()> {
use cargo::{
core::{manifest::EitherManifest, SourceId},
util::toml::read_manifest,
Config,
};
let config = Config::default()?;
let source_id = match config.get::<Option<String>>("source.crates-io.replace-with") {
Ok(Some(replacement)) => config
.get::<Option<String>>(&format!("source.{replacement}.registry"))
.ok()
.flatten(),
_ => None,
}
.map(|registry| SourceId::from_url(®istry))
.unwrap_or_else(|| SourceId::crates_io_maybe_sparse_http(&config))?;
let (EitherManifest::Real(manifest), _) = read_manifest(
&std::path::PathBuf::from("Cargo.toml").canonicalize()?,
source_id,
&config,
)?
else {
panic!("virtual manifest");
};
dbg!(
manifest.summary().source_id().url().as_str(),
manifest.dependencies()[0].source_id().url().as_str()
);
Ok(())
}
Then, with source replacement in place:
$ cargo run
[src/main.rs:26] manifest.summary().source_id().url().as_str() = "sparse+https://mirrors.sjtug.sjtu.edu.cn/crates.io-index/"
[src/main.rs:26] manifest.dependencies()[0].source_id().url().as_str() = "https://github.com/rust-lang/crates.io-index"
Steps
No response
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.75.0 (1d8b05cdd 2023-11-20)
release: 1.75.0
commit-hash: 1d8b05cdd1287c64467306cf3ca2c8ac60c11eb0
commit-date: 2023-11-20
host: aarch64-apple-darwin
os: Mac OS 14.2.1 [64-bit]