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/ 读取源码。

相关推荐
小灰灰搞电子2 小时前
Rust+Slint 实现高级动态消息提示框源码分享
开发语言·rust
qq_406981033 小时前
大白话rust系列08 当变量遮蔽遇上引用,探究变量遮蔽的本质
开发语言·后端·rust
轻舟技术A4 小时前
Pi、rpi、Pi-Bolt 重测:rpi 在启动、内存与读取上全面领先
人工智能·rust
用户14498433464755 小时前
我为什么做一个开源的 Mac 清理工具
rust
古城小栈7 小时前
Rust 学习路线,供初学者参考
开发语言·rust
小熊吃保安1 天前
Windows也能用 Apple Watch 解锁
windows·rust·开源
离歌漠2 天前
《我用 Tauri 做了一个本地开发工具箱》
rust·typescript·vue
小小龙学IT2 天前
Python Polars 高性能数据处理引擎深度解析
开发语言·python·rust·1024程序员节
zzu123zsw2 天前
为什么 Python 做 Agent 总在并发中崩溃?拆解 Blockcell 在 Rust 下的 Host-Cell 隔离与自愈状态机
开发语言·python·rust·大模型·ai agent