Rust packages (crates)
Publish a Rust crate to Zaryn with cargo, use it from another project, keep it private, and fix the usual errors. Every step explained.
Search for a command to run…
Publish a Rust crate to Zaryn with cargo, use it from another project, keep it private, and fix the usual errors. Every step explained.
Rust's package manager, cargo, can download crates from more than one registry. You tell it about Zaryn once, and from then on cargo publish, cargo add and cargo build work with Zaryn the same way they work with crates.io.
Only want crates.io to download faster? You don't need any of this page: see the crates.io mirror. Can't install Rust itself because static.rust-lang.org is out of reach? See rustup through Zaryn.
Open (or create) the file ~/.cargo/config.toml, the settings file cargo reads every time it runs, and add:
[registries.zaryn]index = "sparse+https://api.zaryn.xyz/v1/packages/cargo/index/"[registries.zaryn] gives the registry a short name, zaryn, that you'll use in commands.index is where cargo looks up which crates and versions exist. sparse+ means it asks for one small file per crate instead of downloading a list of everything.On Packages, press Create a publish token and copy it. Then:
cargo login --registry zarynPaste the token when cargo asks. cargo keeps it in ~/.cargo/credentials.toml, so you only do this once.
In your crate's Cargo.toml, make sure the [package] part has a description and a license, and say where it may be published:
[package]name = "hello-zaryn"version = "0.1.0"edition = "2021"description = "Says hello"license = "MIT"publish = ["zaryn"] # only ever to Zaryn, never by accident to crates.ioThen:
cargo publish --registry zaryncargo builds the crate once to make sure it compiles, packs it into a .crate file and uploads it. The crate appears on Packages right away.
To publish a fix, raise version (for example to 0.1.1) and run cargo publish --registry zaryn again. A version that's already published can't be replaced.
cargo add --registry zaryn hello-zarynThat adds this line to Cargo.toml (you can also write it by hand):
[dependencies]hello-zaryn = { version = "0.1", registry = "zaryn" }cargo build downloads it from Zaryn. Your crate can depend on crates.io crates as usual; cargo fetches each from where it lives.
A crate becomes private on its page: open it from Packages and press Make private. Only you, or the members of the organization that owns it, can see and install it.
Reading a private crate needs your token on every request, so it goes through a second registry name:
[registries.zaryn-private]index = "sparse+https://api.zaryn.xyz/v1/packages/cargo/private/index/"credential-provider = "cargo:token"cargo login --registry zaryn-privatecargo add --registry zaryn-private my-secret-crateThe private index also lists your public crates, so a team can use just zaryn-private.
| To… | Run |
|---|---|
| find crates on Zaryn | cargo search --registry zaryn hello |
| hide a broken version | cargo yank --registry zaryn --version 0.1.0 hello-zaryn |
| bring it back | cargo yank --registry zaryn --version 0.1.0 --undo hello-zaryn |
Yanking doesn't delete anything: projects whose Cargo.lock already uses that version keep building. New projects just won't choose it.
| cargo says | What it means | Fix |
|---|---|---|
401 or "this index needs a token" | cargo has no token for this registry | cargo login --registry zaryn (or zaryn-private) |
| "this token can't publish packages" | the token lacks package:write | create a new one on Packages |
| "this package name belongs to someone else" | another account published that name first | choose another name |
"crate foo_bar already exists…" | foo-bar and foo_bar count as the same name, as on crates.io | choose another name |
| "this version is already published" | versions can't be replaced | raise version in Cargo.toml |
| "package storage on the Free plan is full" | your packages and images use 500 MB | yanked versions still count; Premium has 100 GB |
no matching package named … | wrong registry name, or a private crate through zaryn | check the registry = in Cargo.toml |
Zaryn speaks cargo's own registry protocol: the sparse index (one file per crate listing every version, its dependencies and features), the download address, and the publish, yank and search API. Each .crate file is stored by its SHA-256 hash, and that hash is in the index, so cargo checks every download and refuses a file that doesn't match.