Cargo 创建的默认文件树允许并行编译发布和调试版本,因为它们位于自己的目录中;分别为 target/release
和 target/debug
。
stable
/nightly
编译器的并行编译有多难。例如使用目录
目标/调试/稳定
目标/调试/每晚
我知道这可以用 jail /容器来完成,但我希望有一个更像 Cargo 的解决方案。
最佳答案
现代 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? 中所述,您可以为您感兴趣的每个 channel 设置环境变量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!
关于rust - 使用 Rust 稳定版和夜间 channel 允许并行编译代码有多难?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40642456/