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

相关推荐
Hi2024021719 分钟前
同一个 NMS 算子,两种语言实现:CUDA C 与 Rust 生成 LLVM IR 和 Vortex 汇编的差异
c语言·汇编·rust·gpgpu·vortex·cudac
滕州市燕猫虎计算机科技工作室个体工商户27 分钟前
《Rust程序设计》学习笔记一
开发语言·rust·学习笔记·rust程序设计
小道士写程序4 小时前
Windows Rust 环境安装指导
开发语言·windows·rust
leikooo2 天前
用餐厅和盘子理解栈和堆
java·数据结构·链表·rust
@大迁世界2 天前
JEV RAG:更高效的 RAG 系统解决方案?
开发语言·rust
进击的雷神2 天前
OpenClaw 太重、启动太慢?我试了试这个 Rust 重写的轻量版 AI 助手网关
开发语言·人工智能·rust·zeroclaw
选择即世界2 天前
高性能的 SGLang Rust 运行时
rust