diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index affb130cdaa9..653685b8beca 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -1,4 +1,5 @@ use crate::core::PackageId; +use crate::sources::registry::CRATES_IO_HTTP_INDEX; use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY}; use crate::sources::{GitSource, PathSource, RegistrySource}; use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl}; @@ -206,6 +207,18 @@ impl SourceId { }) } + /// Returns the `SourceId` corresponding to the main repository, using the + /// http index if allowed. + pub fn crates_io_maybe_http(config: &Config) -> CargoResult { + if config.cli_unstable().http_registry { + config.check_registry_index_not_set()?; + let url = CRATES_IO_HTTP_INDEX.into_url().unwrap(); + SourceId::new(SourceKind::Registry, url, Some(CRATES_IO_REGISTRY)) + } else { + Self::crates_io(config) + } + } + /// Gets the `SourceId` associated with given name of the remote registry. pub fn alt_registry(config: &Config, key: &str) -> CargoResult { let url = config.get_registry_index(key)?; @@ -356,7 +369,8 @@ impl SourceId { SourceKind::Registry => {} _ => return false, } - self.inner.url.as_str() == CRATES_IO_INDEX + let url = self.inner.url.as_str(); + url == CRATES_IO_INDEX || url == CRATES_IO_HTTP_INDEX } /// Hashes `self`. diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 5bd8decb1b82..0a3928e33f13 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -196,6 +196,10 @@ fn verify_dependencies( if super::check_dep_has_version(dep, true)? { continue; } + // Allow publishing to crates.io with index.crates.io as a source replacement. + if registry_src.is_default_registry() && dep.source_id().is_default_registry() { + continue; + } // TomlManifest::prepare_for_publish will rewrite the dependency // to be just the `version` field. if dep.source_id() != registry_src { diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index 0e2b24efb647..ff3b9ccb9578 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -91,6 +91,15 @@ impl<'cfg> SourceConfigMap<'cfg> { replace_with: None, }, )?; + if config.cli_unstable().http_registry { + base.add( + CRATES_IO_REGISTRY, + SourceConfig { + id: SourceId::crates_io_maybe_http(config)?, + replace_with: None, + }, + )?; + } Ok(base) } @@ -248,7 +257,7 @@ restore the source replacement configuration to continue the build check_not_set("rev", def.rev)?; } if name == CRATES_IO_REGISTRY && srcs.is_empty() { - srcs.push(SourceId::crates_io(self.config)?); + srcs.push(SourceId::crates_io_maybe_http(self.config)?); } match srcs.len() { diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 95510e313b65..413734e10ecb 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -186,6 +186,7 @@ use crate::util::{restricted_names, CargoResult, Config, Filesystem, OptVersionR const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok"; pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index"; +pub const CRATES_IO_HTTP_INDEX: &str = "sparse+https://index.crates.io/"; pub const CRATES_IO_REGISTRY: &str = "crates-io"; pub const CRATES_IO_DOMAIN: &str = "crates.io"; const CRATE_TEMPLATE: &str = "{crate}";