Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify a custom Cargo output directory?

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?

like image 941
mq7 Avatar asked May 16 '18 07:05

mq7


People also ask

Where does cargo build output go?

Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace. To change the location, you can set the CARGO_TARGET_DIR environment variable, the build. target-dir config value, or the --target-dir command-line flag.

Where is the cargo config file?

Windows: %USERPROFILE%\. cargo\config. toml.

Where does cargo build put the binary?

All binaries installed with cargo install are stored in the installation root's bin folder. If you installed Rust using rustup.rs and don't have any custom configurations, this directory will be $HOME/. cargo/bin. Ensure that directory is in your $PATH to be able to run programs you've installed with cargo install .

What is cargo command?

cargo new. The cargo new command allows you to create a new cargo package in the specified directory. Example usage of the command is as shown: $ cargo new [options] path. The command creates a new cargo package with the specified name in the current working directory.


1 Answers

[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.

like image 81
sdht0 Avatar answered Sep 21 '22 08:09

sdht0