简体   繁体   English

安装 Cargo 为打包目的构建的二进制文件的推荐方法是什么?

[英]What is the recommended way to install the binaries built by Cargo for packaging purposes?

How can I access the generated foo binary when I have this in my Cargo.toml?当我的 Cargo.toml 中有这个时,如何访问生成的foo二进制文件?

[[bin]]
name = "foo"
path = "src/foo.rs"

Ideally I would like to have something which works like理想情况下,我想要一些像

make install DESTDIR=$(pwd)/i

I tried:我试过:

  • cargo build --out-dir $(pwd)/i --> fails with "error: the --out-dir flag is unstable" cargo build --out-dir $(pwd)/i --> 失败并显示“错误:-- --out-dir标志不稳定”

  • cargo install --path . --root $(pwd)/i cargo install --path . --root $(pwd)/i --> comes near to the result, but it seems to be impossible to set flags like --release or its opposite variant (yes, I want the debug binary!) cargo install --path . --root $(pwd)/i --> 接近结果,但似乎不可能设置像--release或其相反变体这样的标志(是的,我想要调试二进制文件!)

  • OUT_DIR=$(pwd)/i cargo build --> does not seem to have any effect as there is no directory generated OUT_DIR=$(pwd)/i cargo build --> 似乎没有任何效果,因为没有生成目录

I could dig into the target directory, but there are a lot of unwanted files so globs will not work and I will have to know exactly the artifact name, including automatic suffices like .a , .so , .so.1.2.3 , etc.我可以深入到目标目录,但有很多不需要的文件,所以 globs 将无法工作,我必须确切地知道工件名称,包括.a.so.so.1.2.3等自动后缀.

How to access binaries built by cargo?如何访问由货物构建的二进制文件?

The cargo install --path . --root $(pwd)/i cargo install --path . --root $(pwd)/i cargo install --path . --root $(pwd)/i is the correct way to specify the destination installation directory. cargo install --path . --root $(pwd)/i是指定目标安装目录的正确方法。

but it seems to be impossible to set flags like --release or its opposite variant (yes: I want the debug binary!)但似乎不可能设置像 --release 或其相反变体这样的标志(是的:我想要调试二进制文件!)

It's possible with the --debug flag.可以使用--debug标志。

cargo install --debug --path . --root $(pwd)/i

See cargo install manual .参见货物安装手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM