Skip to content

Commit 85e457e

Browse files
committed
Auto merge of rust-lang#10725 - arlosi:http-cratesio, r=Eh2406
Make -Z http-registry use index.crates.io when accessing crates-io Use `sparse+https://index.crates.io/` to access crates.io when `-Z http-registry` is set. * `Cargo.lock` files still emit the github URL `https://github.com/rust-lang/crates.io-index`. * Allows publishing to a source-replaced `crates-io` only for `index.crates.io`. Other source-replacements of `crates-io` are still blocked. Fixes rust-lang#10722 r? `@Eh2406`
2 parents bc3b99d + 445db94 commit 85e457e

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/cargo/core/source/source_id.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::core::PackageId;
2+
use crate::sources::registry::CRATES_IO_HTTP_INDEX;
23
use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
34
use crate::sources::{GitSource, PathSource, RegistrySource};
45
use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
@@ -206,6 +207,18 @@ impl SourceId {
206207
})
207208
}
208209

210+
/// Returns the `SourceId` corresponding to the main repository, using the
211+
/// http index if allowed.
212+
pub fn crates_io_maybe_http(config: &Config) -> CargoResult<SourceId> {
213+
if config.cli_unstable().http_registry {
214+
config.check_registry_index_not_set()?;
215+
let url = CRATES_IO_HTTP_INDEX.into_url().unwrap();
216+
SourceId::new(SourceKind::Registry, url, Some(CRATES_IO_REGISTRY))
217+
} else {
218+
Self::crates_io(config)
219+
}
220+
}
221+
209222
/// Gets the `SourceId` associated with given name of the remote registry.
210223
pub fn alt_registry(config: &Config, key: &str) -> CargoResult<SourceId> {
211224
let url = config.get_registry_index(key)?;
@@ -356,7 +369,8 @@ impl SourceId {
356369
SourceKind::Registry => {}
357370
_ => return false,
358371
}
359-
self.inner.url.as_str() == CRATES_IO_INDEX
372+
let url = self.inner.url.as_str();
373+
url == CRATES_IO_INDEX || url == CRATES_IO_HTTP_INDEX
360374
}
361375

362376
/// Hashes `self`.

src/cargo/ops/registry.rs

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ fn verify_dependencies(
196196
if super::check_dep_has_version(dep, true)? {
197197
continue;
198198
}
199+
// Allow publishing to crates.io with index.crates.io as a source replacement.
200+
if registry_src.is_default_registry() && dep.source_id().is_default_registry() {
201+
continue;
202+
}
199203
// TomlManifest::prepare_for_publish will rewrite the dependency
200204
// to be just the `version` field.
201205
if dep.source_id() != registry_src {

src/cargo/sources/config.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ impl<'cfg> SourceConfigMap<'cfg> {
9191
replace_with: None,
9292
},
9393
)?;
94+
if config.cli_unstable().http_registry {
95+
base.add(
96+
CRATES_IO_REGISTRY,
97+
SourceConfig {
98+
id: SourceId::crates_io_maybe_http(config)?,
99+
replace_with: None,
100+
},
101+
)?;
102+
}
94103
Ok(base)
95104
}
96105

@@ -248,7 +257,7 @@ restore the source replacement configuration to continue the build
248257
check_not_set("rev", def.rev)?;
249258
}
250259
if name == CRATES_IO_REGISTRY && srcs.is_empty() {
251-
srcs.push(SourceId::crates_io(self.config)?);
260+
srcs.push(SourceId::crates_io_maybe_http(self.config)?);
252261
}
253262

254263
match srcs.len() {

src/cargo/sources/registry/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ use crate::util::{restricted_names, CargoResult, Config, Filesystem, OptVersionR
186186

187187
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
188188
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
189+
pub const CRATES_IO_HTTP_INDEX: &str = "sparse+https://index.crates.io/";
189190
pub const CRATES_IO_REGISTRY: &str = "crates-io";
190191
pub const CRATES_IO_DOMAIN: &str = "crates.io";
191192
const CRATE_TEMPLATE: &str = "{crate}";

0 commit comments

Comments
 (0)