Forgejo/docs/content/usage/packages/cargo.zh-cn.md
John Olheiser bd4c7ce578
Docusaurus-ify (#26051)
This PR cleans up the docs in a way to make them simpler to ingest by
our [docs repo](https://gitea.com/gitea/gitea-docusaurus).

1. It includes all of the sed invocations our ingestion did, removing
the need to do it at build time.
2. It replaces the shortcode variable replacement method with
`@variable@` style, simply for easier sed invocations when required.
3. It removes unused files and moves the docs up a level as cleanup.

---------

Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-07-26 04:53:13 +00:00

3 KiB
Raw Blame History

date title slug sidebar_position draft toc menu
2022-11-20T00:00:00+00:00 Cargo 软件包注册表 cargo 5 false false
sidebar
parent name sidebar_position identifier
packages Cargo 5 cargo

Cargo 软件包注册表

为您的用户或组织发布 Cargo 软件包。

要求

若要使用 Cargo 软件包注册表, 您需要安装 Rust 和 Cargo.

Cargo 将可用软件包的信息存储在一个存储在 git 仓库中的软件包索引中。 这个仓库是与注册表交互所必需的。 下面的部分将介绍如何创建它。

索引仓库

Cargo 将可用软件包的信息存储在一个存储在 git 仓库中的软件包索引中。 在 Gitea 中,这个仓库有一个特殊的名称叫做 _cargo-index。 在上传软件包之后,它的元数据会自动写入索引中。 不应手动修改这个注册表的内容。

用户或组织软件包设置页面允许创建这个索引仓库以及配置文件。 如果需要,此操作将重写配置文件。 例如,如果 Gitea 实例的域名已更改,这将非常有用。

如果存储在 Gitea 中的软件包与索引注册表中的信息不同步,设置页面允许重建这个索引注册表。 这个操作将遍历注册表中的所有软件包,并将它们的信息写入索引中。 如果有很多软件包,这个过程可能需要一些时间。

配置软件包注册表

要注册这个软件包注册表,必须更新 Cargo 的配置。 将以下文本添加到位于当前用户主目录中的配置文件中(例如 ~/.cargo/config.toml

[registry]
default = "gitea"

[registries.gitea]
index = "https://gitea.example.com/{owner}/_cargo-index.git"

[net]
git-fetch-with-cli = true
参数 描述
owner 软件包的所有者。

如果这个注册表是私有的或者您想要发布新的软件包,您必须配置您的凭据。 将凭据部分添加到位于当前用户主目录中的凭据文件中(例如 ~/.cargo/credentials.toml

[registries.gitea]
token = "Bearer {token}"
参数 描述
token 您的个人访问令牌

发布软件包

在项目中运行以下命令来发布软件包:

cargo publish

如果已经存在同名和版本的软件包,您将无法发布新的软件包。您必须先删除现有的软件包。

安装软件包

要从软件包注册表安装软件包,请执行以下命令:

cargo add {package_name}
参数 描述
package_name 软件包名称。

支持的命令

cargo publish
cargo add
cargo install
cargo yank
cargo unyank
cargo search