The default file-tree created by Cargo allows parallel compilation of release and debug builds as they are located in their own directories; target/release
and target/debug
, respectively.
How difficult is it to also allow parallel compilation of stable
/nightly
-compiler. For example using the directories
target/debug/stable
target/debug/nightly
I am aware it can be done with jails/containers, but I was hoping for a somewhat more Cargo-ish solution.
I believe that your main problem of rebuilding dependencies no longer exists:
$ cargo +nightly build
Updating crates.io index
Compiling either v1.5.0
Compiling itertools v0.8.0
Compiling example v0.1.0 (/private/tmp/example)
Finished dev [unoptimized + debuginfo] target(s) in 5.87s
$ cargo +stable build
Compiling either v1.5.0
Compiling itertools v0.8.0
Compiling example v0.1.0 (/private/tmp/example)
Finished dev [unoptimized + debuginfo] target(s) in 2.67s
$ cargo +nightly build
Finished dev [unoptimized + debuginfo] target(s) in 0.17s
$ cargo +stable build
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
I believe that this is a side-effect of the work done for incremental compilation: the compiler version (or something equivalent) is used as part of the hashing algorithm used for build artifacts. Thus, artifacts from multiple toolchains can coexist.
This does not cover the final artifact, which has a fixed name and will be overridden. Keep on reading if you really need to keep both in parallel.
As explained in Is it possible to deactivate file locking in cargo?, you can set the environment variable CARGO_TARGET_DIR
for each channel you are interested in:
$ CARGO_TARGET_DIR=$PWD/stable rustup run stable cargo build
Compiling many v0.1.0 (file:///private/tmp/many)
Finished debug [unoptimized + debuginfo] target(s) in 0.89 secs
$ CARGO_TARGET_DIR=$PWD/nightly rustup run nightly cargo build
Compiling many v0.1.0 (file:///private/tmp/many)
Finished debug [unoptimized + debuginfo] target(s) in 0.62 secs
$ ./stable/debug/many
Hello, world!
$ ./nightly/debug/many
Hello, world!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With