git-crate-registry provides a template for hosting a Rust crate registry on a private git server,
or local filesystem.
The template provides a Python 3 script, add-crate.py which packages a crate extracts, extacts
the neccesary metadata and commits it to this repository.
-
Clone this repository
-
If you do not want to use git lfs, delete
.gitattributesfrom the repository. -
Replace
PATH_TO_MASTER_RAW_FILESin config.json with the URL prefix to download a file from the master branch of your repository. For example:-
gitlab:
http://gitlab.com/USER/REPO/-/raw/master -
github:
https://raw.githubusercontent.com/USER/REPO/master
-
-
Commit these changes and push it to your git server
Clone the repository to your local machine and run the following
./add-crate.py ../my-crate/
git pushAny compilation errors should be printed to the console. If not, ensure that cargo metadata and
cargo package run without error.
-
Create or edit the
.cargo/configfile in either the folder of the project you're importing crates into, or your home folder (~/.cargo/configor%USERPROFILE%\.cargo.config) -
Add a registry entry pointing at the URL of your registry repository:
[registries] my-registry = { index = "https://mygitserver.local/USERNAME/registry" }
-
In
Cargo.toml, declare imported crates by specifying their version and your custom registry name[dependencies] my_crate = { version = "0.1", registry = "my-registry"}
This template can also be used as a local filesystem based crate registry.
To use it in this mode:
- replace
PATH_TO_MASTER_RAW_FILESwith afile://URI pointing at the registry's location on the filesystem. e.g.{ "dl": "file:///Users/USERNAME/projects/registry/crates/{crate}/{crate}-{version}.crate" }
2. Create a registry entry in `.cargo/config` with a `file://` URI pointing at the registry's
location. e.g.
```toml
[registries]
my-registry = { index = "file:///Users/USERNAME/projects/registry" }
```
If cargo is having issues resolving packages in your registry:
-
Remove the cached registry from
~/.cargo/registry/index/ -
Set the variable
export CARGO_LOG=cargo::sources -
Rerun your cargo command (e.g.
cargo build)