Is there a way to set the compilation order of dependencies?

Say I have the following dependency graph:

- A
  - C
  - D
  - E
  - F
- B

Let's say every crate takes 5 seconds to compile, except for B, which takes 30 seconds to compile, and MyCrate. Let's say I have a two-cores processors.

I'm pretty sure how long the dependencies take to compile will depend on which order the crates are compiled in:

  • If A's dependencies are compiled before B, then the compilation sequence will be (C, D), (E, F), (G, H), (A, B), (B), (B), (B), (B), (B), (MyCrate) (where each tuple is a 5-seconds chunk), so a 50 seconds build.
  • If B is started right away, then the compilation sequence will be (B, C), (B, D), (B, E), (B, F), (B, G), (B, H), (A), (MyCrate), so a 40 seconds build.

(the above assumes that an individual crate gets no benefit from multi-threaded compilation, which I understand is close to true)

So, in the above scenario, is there a way to make sure B's compilation is started first?

(For the real world use-case, druid's build time on Linux is dominated by the gtk dependency, which is both the longest to compile and the last to be started. I'm wondering if reordering things in Cargo.toml might accelerate the build. Though now that I mention it, I guess I could test it myself. Mhh...)

1 Like

There is no way to enforce a specific order afaik. Cargo by default tries to minimize the amount of time necessary to compile the whole crate graph though under the assumption that every crate takes equal amount of time and can only start compiling as soon as all depndencies are finished.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.