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

feat(cargo): support sparse registry indices #20375

Closed
wants to merge 3 commits into from

Conversation

tofay
Copy link
Contributor

@tofay tofay commented Feb 13, 2023

Changes

Allow Renovate to update dependencies from private sparse Rust crate registries.

Context

Sparse registries, documented at https://doc.rust-lang.org/nightly/cargo/reference/registry-index.html#sparse-protocol, use a HTTP file based index rather than git. Per https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html they will stabilize in the next Rust release (1.68). I use them at work, and have started using renovate to keep Rust dependencies up to date.

The directory structure of sparse registries (in particular the index suffixing e.g fo/ob/foobar) is identical to existing registries. Given that renovate already uses HTTP file based access to the crates.io index on github, this PR mainly consists of detecting the sparse+` prefix of index URLs and reusing the crates-io code path.

(I've not touched on authentication here as sparse registries aren't necessarily authenticated. I am running renovate self hosted and have this code working against authenticated sparse registries by:

  • configuring a host URL for renovate's HTTP calls to the index
  • configuring cargo to use authentication via environment variable
    )

I found #18941 when looking for related issues, though the changes in that draft PR looked specific to JFrog artifactory.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

I've been running this self-hosted against a few dozen private Azure DevOps repositories that use dependencies from a sparse registry for a couple of weeks, and had PRs raised succesfully.

docs/usage/rust.md Outdated Show resolved Hide resolved
docs/usage/rust.md Outdated Show resolved Hide resolved
Renovate can update dependencies hosted on a private sparse crate registry (<https://doc.rust-lang.org/beta/cargo/reference/registry-index.html#sparse-protocol>).
Since sparse registries are HTTP based, authentication for Renovate can be configured via additional hostRules.

Renovate can only update Cargo lockfiles for projects using dependencies from sparse registries if the local Rust toolchain has the sparse-registry feature enabled (i.e beta/nightly/or 1.68 or later - 1.68 is due for release on March 9th 2023).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Renovate can only update Cargo lockfiles for projects using dependencies from sparse registries if the local Rust toolchain has the sparse-registry feature enabled (i.e beta/nightly/or 1.68 or later - 1.68 is due for release on March 9th 2023).
Before Renovate can update Cargo lockfiles for projects using dependencies from sparse registries you must:
- Use Rust `1.68` or later
- Enable the `sparse-registry` feature in your local Rust toolchain

How about something like this?

The current sentence is too long, and has too much information in one go. So we should split things up into smaller parts. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps omit all mention of the sparse-registry feature, which is actually a compilation flag so unlikely something most users can control?

So:
"Before Renovate can update Cargo lockfiles for projects using dependencies from sparse registries you must use Rust 1.68 or later"

The only oddity with that is that Rust 1.68 isn't out yet, but anyone using sparse registries before then is likely using a beta/nightly toolchain, or a self-built with sparse-registry built in (I fall into this camp :)), and can figure out how to get it working.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps omit all mention of the sparse-registry feature, which is actually a compilation flag so unlikely something most users can control?

It sounds we have two groups of people here:

  1. General public who uses Renovate to update Rust dependencies
  2. Maintainers of Rust repositories who want Renovate to work properly for their published packages

Sounds like the compilation flag sparse-registry is aimed at number 2 then?

I'll let the Renovate maintainers decide what to keep in the docs and what to drop. 😉

The only oddity with that is that Rust 1.68 isn't out yet, but anyone using sparse registries before then is likely using a beta/nightly toolchain, or a self-built with sparse-registry built in (I fall into this camp :)), and can figure out how to get it working.

I'm okay with mentioning the Rust version 1.68 ahead of time. Are you sure that the sparse-registry feature will be included in version 1.68?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the sparse-registry feature will be included in version 1.68?

Yes, at least that's still the current plan: https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html

lib/modules/datasource/crate/types.ts Outdated Show resolved Hide resolved
@rarkins
Copy link
Collaborator

rarkins commented Feb 13, 2023

@Turbo87 could you please review?

lib/modules/datasource/crate/index.spec.ts Outdated Show resolved Hide resolved
lib/modules/datasource/crate/index.ts Outdated Show resolved Hide resolved
lib/modules/datasource/crate/index.ts Outdated Show resolved Hide resolved
lib/modules/datasource/crate/types.ts Outdated Show resolved Hide resolved
@viceice
Copy link
Member

viceice commented Feb 13, 2023

Copy link
Contributor

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks alright to me on first glance. I haven't tried it out locally though and my experience is limited to the sparse implementation for crates.io itself.

@tofay
Copy link
Contributor Author

tofay commented Apr 11, 2023

closing as #21187 has landed

@tofay tofay closed this Apr 11, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants