Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
os: [ubuntu-22.04, windows-latest]
cargo_flags:
- ""
- "--no-default-features"
- "--all-features"
include:
# Integration tests are disabled on Windows as they take *way* too
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["alternate-registries"]

alternate-registries = ["dep:git2"]
unstable = []
unstable-toolchain-ci = []

Expand All @@ -39,7 +42,7 @@ remove_dir_all = "1.0.0"
base64 = "0.22.0"
getrandom = { version = "0.4.1", features = ["std"] }
thiserror = "2.0.17"
git2 = "0.20.2"
git2 = { version = "0.20.2", optional = true }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.30.0", features = ["signal", "user"]}
Expand Down
2 changes: 2 additions & 0 deletions src/crates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::Workspace;
use log::info;
use std::path::Path;

#[cfg(feature = "alternate-registries")]
pub use registry::AlternativeRegistry;

trait CrateTrait: std::fmt::Display {
Expand All @@ -25,6 +26,7 @@ pub struct Crate(CrateType);

impl Crate {
/// Load a crate from specified registry.
#[cfg(feature = "alternate-registries")]
pub fn registry(registry: AlternativeRegistry, name: &str, version: &str) -> Self {
Crate(CrateType::Registry(registry::RegistryCrate::new(
registry::Registry::Alternative(registry),
Expand Down
9 changes: 9 additions & 0 deletions src/crates/registry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::CrateTrait;
use crate::Workspace;
#[cfg(feature = "alternate-registries")]
use anyhow::Context as _;
use flate2::read::GzDecoder;
use log::info;
Expand All @@ -11,11 +12,13 @@ use tar::Archive;
static CRATES_ROOT: &str = "https://static.crates.io/crates";

/// A type for alternative registry as described in rust-lang/rfcs#2141
#[cfg(feature = "alternate-registries")]
pub struct AlternativeRegistry {
registry_index: String,
key: Option<String>,
}

#[cfg(feature = "alternate-registries")]
impl AlternativeRegistry {
/// Registry for specified registry index
pub fn new(registry_index: impl Into<String>) -> AlternativeRegistry {
Expand All @@ -41,20 +44,23 @@ impl AlternativeRegistry {

pub(crate) enum Registry {
CratesIo,
#[cfg(feature = "alternate-registries")]
Alternative(AlternativeRegistry),
}

impl Registry {
fn cache_folder(&self) -> String {
match self {
Registry::CratesIo => "cratesio-sources".into(),
#[cfg(feature = "alternate-registries")]
Registry::Alternative(alt) => format!("{}-sources", alt.index_folder()),
}
}

fn name(&self) -> String {
match self {
Registry::CratesIo => "crates.io".into(),
#[cfg(feature = "alternate-registries")]
Registry::Alternative(alt) => alt.index().to_string(),
}
}
Expand All @@ -66,6 +72,7 @@ pub(super) struct RegistryCrate {
version: String,
}

#[cfg(feature = "alternate-registries")]
#[derive(serde::Deserialize)]
struct IndexConfig {
dl: String,
Expand All @@ -88,12 +95,14 @@ impl RegistryCrate {
.join(format!("{}-{}.crate", self.name, self.version))
}

#[allow(unused_variables)]
fn fetch_url(&self, workspace: &Workspace) -> anyhow::Result<String> {
match &self.registry {
Registry::CratesIo => Ok(format!(
"{0}/{1}/{1}-{2}.crate",
CRATES_ROOT, self.name, self.version
)),
#[cfg(feature = "alternate-registries")]
Registry::Alternative(alt) => {
let index_path = workspace
.cache_dir()
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ mod utils;
mod workspace;

pub use crate::build::{Build, BuildBuilder, BuildDirectory};
pub use crate::crates::{AlternativeRegistry, Crate};
#[cfg(feature = "alternate-registries")]
pub use crate::crates::AlternativeRegistry;
pub use crate::crates::Crate;
pub use crate::prepare::PrepareError;
pub use crate::toolchain::Toolchain;
pub use crate::workspace::{Workspace, WorkspaceBuilder};
Expand Down
1 change: 1 addition & 0 deletions tests/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "alternate-registries")]
mod crates_alt;
mod crates_git;
mod purge_caches;