Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow place holders in build.target-dir #6210

Closed
ensc opened this issue Oct 23, 2018 · 3 comments
Closed

Allow place holders in build.target-dir #6210

ensc opened this issue Oct 23, 2018 · 3 comments
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@ensc
Copy link

ensc commented Oct 23, 2018

I would like to configure CARGO_TARGET_DIR globally so that build happens on a faster/larger partition than ${HOME} (usually on NFS).

Setting

[build]
target-dir = "/home/ensc/.cache/cargo"

in global ~/.cargo/config causes bad effects because builds of different software packages are mixed in a single directory.

It would be nice when target-dir accepts some place holders like

[build]
target-dir = "/home/ensc/.cache/cargo/%X"

where %X can be

  • %C ... the hash of the directory with Cargo.toml
  • %P ... the full path of the directory with Cargo.toml
  • %N ... the package.name (seems to be difficult with recent code)
@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 23, 2018
@joseluis
Copy link

joseluis commented Apr 5, 2019

%H ... the hostname

This would be useful in my case, since I work in the same project on different architectures, and I need to have separate target-dir per system.

I currently set the env variable CARGO_TARGET_DIR="target-$(hostname)", but this has the disadvantage of the target-dir being created in the working directory, instead of the root directory, which is annoying.

I really miss solution for having a custom target-dir name relative to the root of the project, not the current working directory.

@phiresky
Copy link

phiresky commented Jan 21, 2020

Solved this for myself by putting this in my ~/.zshrc

autoload -Uz add-zsh-hook
function cargo_target_chpwd {
	local dir=$PWD:t # just the last path component of the project
	export CARGO_TARGET_DIR=~/.cache/cargo-target/$dir
}
add-zsh-hook chpwd cargo_target_chpwd
cargo_target_chpwd # initial shell start

Basically just resets the cargo target dir on every dir change.

Same should be possible for other shells.

Still would be better if this feature was integrated since the above doesn't work for rls in IDEs.

@epage
Copy link
Contributor

epage commented Oct 24, 2023

As this is attempting to solve the same problem as #11156, I'm going to close in favor of that. Though the title of #11156 is more specific, the discussion has broadened to how to solve the need. If there is a reason we should re-evaluate this, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

6 participants