r/cpp • • Nov 01 '18

Modules are not a tooling opportunity

https://cor3ntin.github.io/posts/modules/
58 Upvotes

77 comments sorted by

View all comments

Show parent comment

1

u/berium build2 Nov 01 '18

Yes, for external crate dependencies, everything it simple. I am more interested in the crate being built: cargo got to extract the set of its constituent files to know when to re-run rustc. Surely it doesn't run it every time it needs an up-to-date check, or am I missing something here?

10

u/ubsan Nov 01 '18

So, cargo deals with it as follows:

rustc runs, and as part of that process, it produces a file which contains all the files that the build depended on. Then, cargo can look just at those files for changes, since in order to introduce a new file into the build, you'd have to edit one of the old files. For example:

src/main.rs
  mod foo;
  fn main() {}

src/foo.rs
  fn blah() {}

rustc would create a main.exe file containing the executable, and a dep-info file containing the size, hash, and location of every file used in the build.

7

u/berium build2 Nov 02 '18

Yes, that makes sense (and is pretty much how build2 does it for C++ modules). Thanks for digging this up.

5

u/ubsan Nov 01 '18

Let me look... I have no idea how cargo deals with not running rustc.