允许使用 Rust stable 和 nightly 频道并行编译代码有多困难? [英] How difficult is it to allow parallel compilation of code with the Rust stable and nightly channels?

查看:83
本文介绍了允许使用 Rust stable 和 nightly 频道并行编译代码有多困难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

同时允许stable/nightly-compiler 的并行编译有多困难.例如使用目录

How difficult is it to also allow parallel compilation of stable/nightly-compiler. For example using the directories

  • 目标/调试/稳定
  • 目标/调试/夜间

我知道它可以通过监狱/容器来完成,但我希望有一个更像 Cargo-ish 的解决方案.

I am aware it can be done with jails/containers, but I was hoping for a somewhat more Cargo-ish solution.

推荐答案

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

相信这是为增量编译所做的工作的副作用:编译器版本(或等效的东西)被用作用于构建工件的散列算法的一部分.因此,来自多个工具链的工件可以共存.

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.

是否可以取消货物中的文件锁定?,您可以设置环境变量您感兴趣的每个频道的 CARGO_TARGET_DIR:

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!

这篇关于允许使用 Rust stable 和 nightly 频道并行编译代码有多困难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆