rust - 使用 Rust 稳定版和夜间 channel 允许并行编译代码有多难?

标签 rust rust-cargo

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

相关文章:

rust - 为什么传递给 map() 的闭包不带引用,而传递给 filter() 的闭包带引用?

rust - 为什么 Vec::as_slice 和数组强制的生命周期检查不同?

installation - 通过 cargo : specified package has no binaries 安装箱子时出错

vector - 如何访问新类型的向量作为基础类型

rust - 我可以在没有 Cargo.toml 的情况下使用 Cargo 安装库吗?

rust - 将数字格式化/转换为任何基数的字符串(包括十进制或十六进制以外的基数)

windows - 我如何自动找到我的 Rust 程序使用的所有动态库(并将它们放入一个目录中)?

rust - 是否可以仅为 Release模式调用 build.rs?

macos - OpenSSL crate 在 Mac OS X 10.11 上编译失败

docker - Alpine dockerfile : "cannot produce proc-macro...does not support these crate types"