How to get OUT_DIR without running the build script?

I have a build script that generates some files and puts them in the directory specified by the OUT_DIR environment variable.

However, I want to do some post-processing on some of those files (or even just open them manually and verify they look right), but they’re in a directory like this:


Is there a Cargo command or some way I can figure out what the out dir path is going to be without running the build script? As far as I can tell, the path doesn’t change when I modify my code and rebuild, but it does change occasionally and I end up with several such directories lying around.

I would also like to know the answer to this! I’ve resorted to creating a stamp file, and then detecting the correct out directory by finding the most recently modified stamp file. This likely isn’t bullet proof, but it has worked for me in practice.

To find the stamp file:

To generate the stamp file:

I suspect the underlying requirement is a way to find final build artifacts. This keeps coming up in different forms, like this discussion which led to

On a related note, cargo is adding an --out-dir so users can control where the binary gets written to but doesn’t solve the problem of generated artifacts.

This is a problem relevant to the CLI-WG and was part of our discussion yesterday. I’m not yet sure where this will lead but I’m hoping we get a reasonable solution soon.

Ah, thanks for the information! I didn’t realise this would fall under the CLI-WG but that’s good to know.