Changing Cargo's Intermediate Compilation Directory

When Cargo builds crates, it creates a temporary directory for compiler output. I can see this if I dump the command line for link.exe invocation:

In order to get a reproducible build, these files need to be produced in a known directory. This is required because msvc sometimes embeds paths into generated binaries. Those paths can be normalized with the /pathMap switch, but only if they are known (the above path is a random name in $TEMP).

I've tried using -Csave-temps and --out-dir but these don't change the output directory, only copy files from that temporary directory after they are built. What I need is a way to change the intermediate compilation directory to a known value.

Does Cargo currently support this functionality?

This temporary directory is created by rustc not cargo. Rustc doesn't allow configuring it. It always uses the tempfile crate to generate a random directory.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.