如何在离线环境中使用Cargo构建项目? [英] How to build a project using Cargo in an offline environment?

查看:93
本文介绍了如何在离线环境中使用Cargo构建项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台带有OS X系统的笔记本电脑,该笔记本电脑可以访问Internet,而Linux服务器出于某种安全原因而不能访问Internet.

I have a laptop with an OS X system which can access the internet, and a Linux server which can not access internet for some security reason.

我想构建一个对Linux服务器有一定依赖性的Rust项目.因为Linux服务器无法访问Internet,所以我在OSX便携式计算机上运行 cargo build 命令,并将依赖项源文件下载到 .cargo 目录,然后将这些文件复制到Linux服务器,然后将它们放入/root/.cargo 目录.

I want to build a Rust project with some dependency on the Linux server. Because the Linux server can not access internet, I run the cargo build command on the OSX laptop and download the dependency source file to the .cargo directory and then copy these files to the Linux server and put them into /root/.cargo directory.

我使文件结构相同,但是当我在Linux服务器上运行 cargo build 时,它仍然尝试连接到

I made the file structures the same, but when I run cargo build on the Linux server, it still tries to connect to this website and the build fails. The cargo build command always tries to connect internet although the dep source files are already in the .cargo directory.

如何在离线环境中构建具有依赖项的Rust项目?为什么复制依赖项的源文件不起作用?

How can I build a Rust project with dependencies in an offline environment? Why does copying the source file of the dependencies not work?

推荐答案

对于Rust 1.37+,请参见: https://stackoverflow.com/a/65254702/147192

最简单的答案是:高达1.37(不包括在内),这很复杂.

The short answer is: up to 1.37 (excluded), it's complicated.

长答案是 cargo 将尝试连接到 github ,以便检查 Cargo.toml 的板条箱索引文件引用.

The long answer is that cargo will attempt to connect to github in order to check the index of the crates that the Cargo.toml file references.

我建议您检查 cargo-vendor 原型以解决此问题(由aturon,是Rust工具小组的成员),否则您可以查看一些人

I recommend you to check the cargo-vendor prototype to solve this issue (by aturon, a member of the Rust tooling subteam), and otherwise you could look at how some people created a mirror for crates.io in order to avoid the dependency on Internet.

对Rust的需求是不要求Internet,而人们正在使用Internet,但是目前还没有一个好的解决方案.

There is a demand for Rust builds not to require Internet, and people working on it, however there is no blessed solution for now.

这篇关于如何在离线环境中使用Cargo构建项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆