9

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
PureW
  • 4,568
  • 3
  • 19
  • 27

1 Answers1

12

Modern Rust

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.

Original answer

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!
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • Exactly what I was hoping for! – PureW Nov 16 '16 at 21:24
  • 2
    @PureW Not worth a full answer, but I have a [`test-matrix.py`](https://github.com/DanielKeep/rust-script-toolbox/blob/master/test-matrix.py) script that does this for (simple) Travis CI configs. – DK. Nov 16 '16 at 23:14
  • Regarding your edited answer: Using CARGO_TARGET_DIR to specify a separate dir for clippy still seems to avoid recompilation. – PureW Dec 19 '19 at 22:33