Documentation on cargo target directory

Is there any documentation on the layout of the target directory for a crate built with cargo?

In particular I'd like to know how I can deterministically determine the path of the executable when building a binary?

It seems like it generally looks something like target/<target>/<profile>/<bin-name>. However, if the profile is "dev" (the default), then <profile> is "debug" instead of the expected "dev", and if no target is explicitly specified, then that portion of the path is excluded. But I've just been able to figure that out from experimentation, and haven't been able to find any documentation on this, so I'm not sure if there are other edge cases I'm missing.

The cargo book has a section on the build cache which describes the layout of the target directory. I hope this helps.

1 Like

Note that if you want to obtain the executable path from within something Cargo runs (cargo test, cargo run, build script, or during compilation) then the best way to do that is by asking directly, by consulting the environment variable CARGO_BIN_EXE_<bin-name>.

1 Like

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.