code.gitea.io/gitea@v1.22.3/docs/content/usage/packages/cargo.en-us.md (about) 1 --- 2 date: "2022-11-20T00:00:00+00:00" 3 title: "Cargo Package Registry" 4 slug: "cargo" 5 sidebar_position: 5 6 draft: false 7 toc: false 8 menu: 9 sidebar: 10 parent: "packages" 11 name: "Cargo" 12 sidebar_position: 5 13 identifier: "cargo" 14 --- 15 16 # Cargo Package Registry 17 18 Publish [Cargo](https://doc.rust-lang.org/stable/cargo/) packages for your user or organization. 19 20 ## Requirements 21 22 To work with the Cargo package registry, you need [Rust and Cargo](https://www.rust-lang.org/tools/install). 23 24 Cargo stores information about the available packages in a package index stored in a git repository. 25 This repository is needed to work with the registry. 26 The following section describes how to create it. 27 28 ## Index Repository 29 30 Cargo stores information about the available packages in a package index stored in a git repository. 31 In Gitea this repository has the special name `_cargo-index`. 32 After a package was uploaded, its metadata is automatically written to the index. 33 The content of this repository should not be manually modified. 34 35 The user or organization package settings page allows to create the index repository along with the configuration file. 36 If needed this action will rewrite the configuration file. 37 This can be useful if for example the Gitea instance domain was changed. 38 39 If the case arises where the packages stored in Gitea and the information in the index repository are out of sync, the settings page allows to rebuild the index repository. 40 This action iterates all packages in the registry and writes their information to the index. 41 If there are lot of packages this process may take some time. 42 43 ## Configuring the package registry 44 45 To register the package registry the Cargo configuration must be updated. 46 Add the following text to the configuration file located in the current users home directory (for example `~/.cargo/config.toml`): 47 48 ``` 49 [registry] 50 default = "gitea" 51 52 [registries.gitea] 53 index = "sparse+https://gitea.example.com/api/packages/{owner}/cargo/" # Sparse index 54 # index = "https://gitea.example.com/{owner}/_cargo-index.git" # Git 55 56 # [net] 57 # git-fetch-with-cli = true 58 ``` 59 60 | Parameter | Description | 61 | --------- | ----------- | 62 | `owner` | The owner of the package. | 63 64 If the registry is private or you want to publish new packages, you have to configure your credentials. 65 Add the credentials section to the credentials file located in the current users home directory (for example `~/.cargo/credentials.toml`): 66 67 ``` 68 [registries.gitea] 69 token = "Bearer {token}" 70 ``` 71 72 | Parameter | Description | 73 | --------- | ----------- | 74 | `token` | Your [personal access token](development/api-usage.md#authentication) | 75 76 ## Git vs Sparse 77 78 Currently, cargo supports two ways for fetching crates in a registry: Git index & sparse index. 79 Sparse index is the newest method and offers better performance when updating crates compared to git. 80 Since Rust 1.68, sparse is the default method for crates.io. 81 82 ## Publish a package 83 84 Publish a package by running the following command in your project: 85 86 ```shell 87 cargo publish 88 ``` 89 90 You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first. 91 92 ## Install a package 93 94 To install a package from the package registry, execute the following command: 95 96 ```shell 97 cargo add {package_name} 98 ``` 99 100 | Parameter | Description | 101 | -------------- | ----------- | 102 | `package_name` | The package name. | 103 104 ## Supported commands 105 106 ``` 107 cargo publish 108 cargo add 109 cargo install 110 cargo yank 111 cargo unyank 112 cargo search 113 ```