Hi, I recently encountered an issue when trying to compile & run two rust binaries of the same workspace using two toolchains version (one stable, and one nightly). I could not compile both at the same time because rustc lock the whole target
directory when compiling.
This lead me to the following question: why isn't cargo creating one target sub-directory for each toolchain version/triple ?
The fact that compiling a program using a nightly toolchain, and then compile it again using a stable toolchain only redoes the linking step (building the final binary file) makes me think that the build artifacts are not shared between the two versions of the rust toolchain.
If so, wouldn't it make more sense to separate the toolchain artifacts into different folders ? This would allow for a more granular target locking mechanism (allowing multiple targets to be built in parallel), and would prevent the final binary from being replaced by each toolchain. This would also play well with compiling on Windows (targeting windows-msvc) and in WSL (targeting linux-gnu for example) at the same time. And finally, it would allow to cargo clean
a single target (so you don't have to re-compile everything for the other targets afterwards).
I skimmed through the RFC and IRLO posts mentioning the target folder, but couldn't find anything about this specific problem.
I was thinking about something like
target/
ββ stable-1.57-x86_64-unknown-linux-gnu/
ββ stable-1.57-x86_64-pc-windows-msvc/
ββ stable-1.56-x86_64-pc-windows-msvc/
ββ nightly-2021-12-07-unknown-linux-gnu/
Where there would be one "target folder" for each toolchain version/target.
If little is shared between two toolchains, this shouldn't cause any problems, cargo already has to know which toolchain version/target to use in order to execute its commands (such as run/test/build/check/etc...).
Of course, this is all purely based on what little understanding I have of the build artifacts produced by rustc. If there is a large amount of data shared between multiple targets, then it might be better to continue using a single target directory.