Rust 下载依赖包

步骤

1. 生成 Cargo.lock

bash 复制代码
cargo generate-lockfile

或者直接:

bash 复制代码
cargo check

这步需要能访问 crates.io(和 git 仓库)。生成后会得到 Cargo.lock。

2. Vendor 源码

bash 复制代码
cargo vendor --versioned-dirs > vendor.toml

会创建 vendor/ 目录(所有依赖源码)和 vendor.toml(映射表)。

3. 配置 .cargo/config.toml 指向 vendor 目录

在项目根目录的 .cargo/config.toml 中加入:

toml 复制代码
[source]
registry = "sparse+https://index.crates.io/"
# 本地 vendor 映射
[registries.crates-io]
replace-with = "vendored-sources"
toml 复制代码
[source.vendored-sources]
directory = "vendor"

或者直接覆盖默认 source:

toml 复制代码
[source.crates-io]
replace-with = "vendored-sources"
toml 复制代码
[source.vendored-sources]
directory = "vendor"

4. 把整个项目拷到内网

需要拷贝的内容:

  • 项目源码
  • vendor/ 目录
  • .cargo/config.toml
  • Cargo.lock

5. 内网机器上构建

bash 复制代码
cargo build --release

此时 cargo 不会联网,完全从 vendor/ 读取源码。

相关推荐
SomeOtherTime3 小时前
第 11 讲(大结局):编译期元编程与零拷贝架构——卫生声明宏(macro_rules!)、过程宏 AST 手术刀与 Serde 零反射序列化的终极合龙
rust
SomeOtherTime8 小时前
番外篇(第 12 讲):走向工业界深水区——从物理定律看 Rust 在真实工程中的“降维打击”与“阿喀琉斯之踵”
开发语言·rust
Kapaseker9 小时前
Rust 桌面开发到底怎么选?先看这篇文章!
rust
奶油话梅糖10 小时前
容器启停 2.5 毫秒:11 天 1,700 Star 的 Kiri,用一个 900 KB 的 PID 1 干掉了 runc 和 dockerd
前端·人工智能·rust
wflynn1 天前
GitHub 今日推荐|kiri:clone3 系统调用直达容器,2.5 毫秒启动无 runc 中间层
docker·rust·kubernetes·开源·github·containers
SomeOtherTime1 天前
第 4 讲:突破静态枷锁——智能指针(Box/Rc/Arc)与内部可变性(Cell/RefCell/UnsafeCell)的内存暗道
rust
SomeOtherTime1 天前
第 9 讲:异步并发与 Pin 的底层解剖——async/await 无栈协程状态机脱糖、自引用死锁的终极救赎与 Future/Waker 驱动模型
rust
wflynn2 天前
GitHub 今日推荐|Stela:在 PC 上直接启动 macOS 的翻译层
rust·开源·github
aifannihao2 天前
Rust 1.100 的 DropGuard:用 Python 实测失败回滚与吞异常
python·rust·异常处理·标准库·contextlib
鶴哥只手遮天2 天前
《rustc 内幕》第 1 章 全景:rustc 编译流水线与 crate 版图
后端·rust·开源