I'm currently working on implementing a custom cargo registry for GitLab. I've read about how git and sparse index work and thinking of implementing sparse index. Currently, I built a FastAPI-based web server with basic APIs for fetching config.json, publishing, and downloading. I've made a sample crate with the following Cargo.toml:

[package]
name = "local_package"
version = "0.1.30"
edition = "2021"
description = "A local package"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# clap = { version = "4.5.18"}

This is working well when I do:

➜  local_package git:(master) ✗ cargo publish --index sparse+http://localhost:8001/ --token cioINbd1Va8cwhP8ZGvjzmHP2wxCvAlVS3F --allow-dirty 
    Updating `sparse+http://localhost:8001/` index
warning: manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
   Packaging local_package v0.1.30 (/home/luna/Documents/local_package)
    Packaged 4 files, 1.2KiB (827.0B compressed)
   Verifying local_package v0.1.30 (/home/luna/Documents/local_package)
   Compiling local_package v0.1.30 (/home/luna/Documents/local_package/target/package/local_package-0.1.30)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.20s
   Uploading local_package v0.1.30 (/home/luna/Documents/local_package)
    Uploaded local_package v0.1.30 to registry `sparse+http://localhost:8001/`
note: waiting for `local_package v0.1.30` to be available at registry `sparse+http://localhost:8001/`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
   Published local_package v0.1.30 at registry `sparse+http://localhost:8001/

But as soon as I add clap as a dependency, I'm not sure why the publish command is waiting for something to be updated in the index:

➜  local_package git:(master) ✗ cargo publish --index sparse+http://localhost:8001/ --token cioINbd1Va8cwhP8ZGvjzmHP2wxCvAlVS3F --allow-dirty 
    Updating `sparse+http://localhost:8001/` index
warning: manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
   Packaging local_package v0.1.31 (/home/luna/Documents/local_package)
    Updating crates.io index
    Packaged 4 files, 6.3KiB (2.2KiB compressed)
   Verifying local_package v0.1.31 (/home/luna/Documents/local_package)
   Compiling utf8parse v0.2.2
   Compiling anstyle v1.0.10
   Compiling anstyle-query v1.1.2
   Compiling colorchoice v1.0.3
   Compiling is_terminal_polyfill v1.70.1
   Compiling strsim v0.11.1
   Compiling clap_lex v0.7.4
   Compiling anstyle-parse v0.2.6
   Compiling anstream v0.6.18
   Compiling clap_builder v4.5.26
   Compiling clap v4.5.26
   Compiling local_package v0.1.31 (/home/luna/Documents/local_package/target/package/local_package-0.1.31)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.40s
   Uploading local_package v0.1.31 (/home/luna/Documents/local_package)
    Uploaded local_package v0.1.31 to registry `sparse+http://localhost:8001/`
note: waiting for `local_package v0.1.31` to be available at registry `sparse+http://localhost:8001/`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
   Waiting [=>                          ] 6/60                                                                                                                                      

And my updated index looks like this:

{"name": "local_package", "vers": "0.1.30", "deps": [], "cksum": "bf3a78a3a0f4c1c318942f4dca82ddeae412b255391c63a61d709cec1dcdefd8", "features": {}, "yanked": false}
{"name": "local_package", "vers": "0.1.31", "deps": [{"optional": false, "default_features": true, "name": "clap", "features": [], "version_req": "^4.5.18", "target": null, "kind": "normal", "registry": "https://github.com/rust-lang/crates.io-index"}], "cksum": "1e5bbf4f287ea520ebbb5cf7a43d1bb5d3b6125ba70ec46eebd93cfaa6d9fb22", "features": {}, "yanked": false}

From the cargo source code, I can see that it's trying to do something with the dependent packages (cargo/src/cargo/ops/registry/publish.rs at master · rust-lang/cargo · GitHub). I'm not sure what it's trying to do. Meanwhile, in my web server, I don't see any failed API calls. It's GETting the index file.

Do I need to update anything else along with the package metadata when using dependent packages? I'm just storing the JSON metadata into the index and the crate file to the crate location.

1 post - 1 participant

Read full topic

Source: View source