允许使用Rust稳定和夜间通道并行编译代码有多难?

时间:2016-11-16 21:15:18

标签: rust rust-cargo

Cargo创建的默认文件树允许并行编译发布和调试版本,因为它们位于自己的目录中;分别为target/releasetarget/debug

允许并行编译stable / nightly - 编译器有多困难。例如,使用目录

  • target/debug/stable
  • target/debug/nightly

我知道可以用jails /容器来完成,但我希望有更多的货物解决方案。

1 个答案:

答案 0 :(得分:12)

Modern Rust

我相信重建依赖关系的问题不再存在:

$ 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

相信这是渐进式编译工作的副作用:编译器版本(或等效的东西)用作构建工件的散列算法的一部分。因此,来自多个工具链的伪像可以共存。

涵盖了最终的工件,它具有固定的名称并将被覆盖。如果你真的需要保持两者并行,请继续阅读。

原始答案

Is it possible to deactivate file locking in cargo?中所述,您可以为您感兴趣的每个频道设置环境变量CARGO_TARGET_DIR

$ 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!