How can I specify a custom Cargo output directory?

耗尽温柔 提交于 2020-11-29 05:31:38

问题


I put this in my Cargo.toml

[build]
target-dir = "../my-target"

However, Cargo doesn't recognize this key.

cargo run --release --bin my_project

warning: unused manifest key: build
error: failed to open: /.../project-root/target/releases/.cargo-lock

Caused by:
  Permission denied (os error 13)

The custom target dir with the environment variable works:

CARGO_TARGET_DIR=../my-target cargo run --bin my_project

but how can I specify '../my-target' in Cargo.toml?


回答1:


[build] is a Cargo-level configuration rather than for the project:

This document will explain how Cargo’s configuration system works, as well as available keys or configuration. For configuration of a project through its manifest, see the manifest format.

Put your [build] inside $PROJECT_DIR/.cargo/config or even $HOME/.cargo/config. See the above link for all the options.




回答2:


Use the CARGO_TARGET_DIR environment variable:

CARGO_TARGET_DIR=../my-target cargo run --bin my_project

(This is stated in the question, but I wanted to highlight it for anyone that skips over that)



来源:https://stackoverflow.com/questions/50364390/how-can-i-specify-a-custom-cargo-output-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!