[英]How to install a Rust dependency in an environment with no internet?
I would like to use the tango client crate for a Rust project at work, however the environment that I will be developing this in does not have direct access to the internet.我想在工作中将tango 客户端 crate用于 Rust 项目,但是我将在其中开发它的环境无法直接访问 Internet。 This means that the standard method of adding the dependency to
Cargo.toml
and running cargo build
fails due to a network error.这意味着将依赖项添加到
Cargo.toml
并运行cargo build
的标准方法由于网络错误而失败。
The environment doesn't prevent me from copying data downloaded to an internet-connected computer, and so I was hoping that there would be a way for me to package the necessary files locally, and then point Cargo.toml
to that location.该环境不会阻止我将下载的数据复制到连接互联网的计算机上,因此我希望有一种方法可以让我在本地打包必要的文件,然后将
Cargo.toml
指向该位置。
Is this possible?这可能吗? If so, how?
如果是这样,怎么做?
Answering my own question, thanks to a tip in a comment from @Dogbert.感谢@Dogbert 评论中的提示,回答我自己的问题。
The trick was to use cargo vendor
on the machine that has an internet connection.诀窍是在具有互联网连接的机器上使用
cargo vendor
。 This will produce a directory called vendor
that can be transferred to the other environment.这将生成一个名为
vendor
的目录,该目录可以转移到其他环境。 On that environment, and within the directory from which you will run cargo build
, create a new file in .cargo/config
.在该环境中,在您将运行
cargo build
的目录中,在.cargo/config
中创建一个新文件。
[source]
[source.local_vendor]
directory = "vendor"
[source.crates-io]
replace-with = "local_vendor"
Once you've done this, then cargo build
should work.完成此操作后,
cargo build
应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.