制作crate并发布到Crates.io

准备


发布 crate 时, 一旦发布无法修改,无法覆盖, 因此要注意邮箱等一些个人信息

访问crates.io 的 帐号设定页面[1],生成Token

并在命令行 执行 cargo login your token

此命令将告诉 Cargo 你的 API 令牌, 并将其存储在本地 ~/.cargo/credentials

alt

crates.iocrate的名字, 会采取先到先得的方式分配.




打包 & 发布


对于 Cargo.toml:

[package]
name = "dashen"
version = "0.1.1"
authors = ["xxxx <x@xxxxxx.tech>"]
edition = "2018"

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

[dependencies]
ferris-says = "0.2"

执行cargo publish:

alt

这是因为缺少一些关键信息:关于该 crate 用途的描述和用户可能在何种条款下使用该 cratelicense

想要修正这个错误, 需要在 Cargo.toml 中引入这些信息.

描述通常是一两句话, 它会出现在 crate 的搜索结果中和 crate 页面里.

对于 license 字段, 需要一个 license 标识符值(license identifier value)

Linux 基金会的 Software Package Data Exchange (SPDX)[2] 列出了可以使用的标识符

例如指定 crate 使用 MIT License,可增加 MIT 标识符

[package]
name = "dashen"
version = "0.1.1"
authors = ["xxxx <xxx@xxxxx.tech>"]
edition = "2018"
description = "the first crate by xxxxx"
license = "MIT"

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

[dependencies]
ferris-says = "0.2"


再次执行 cargo publish:

alt

这是因为没有指定git仓库


新建一个仓库,指定为远程仓库,并提交代码

alt
alt

再次执行 cargo publish:

alt

此时也能在crates.io[3]搜到刚刚发布的crate

alt



英文版文档:

Publishing a Crate to Crates.io[4]

中文版文档:

将 crate 发布到 Crates.io[5]

参考资料

[1]

帐号设定页面: https://crates.io/me

[2]

Software Package Data Exchange (SPDX): http://spdx.org/licenses/

[3]

crates.io: https://crates.io/search?page=1&per_page=10&q=dashen

[4]

Publishing a Crate to Crates.io: https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html

[5]

将 crate 发布到 Crates.io: https://kaisery.github.io/trpl-zh-cn/ch14-02-publishing-to-crates-io.html

本文由 mdnice 多平台发布

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值