Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make -Z http-registry use index.crates.io when accessing crates-io #10725

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<SourceId> {
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<SourceId> {
let url = config.get_registry_index(key)?;
Expand Down Expand Up @@ -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`.
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down