Build system as in C projects


#1

Is it possible to use the build system, as in C projects? I.e. separate the implementation and the interface into different files.


#2

Yes, you can define trait in one module in implement in another.


#3

But they must be in one crate. If I change any module, it’s needed recompile all crate.


#4

I’m talking about the building, as in the C projects. That is, each file is compiled into an object one, and then they are linked to the library. Is it possible in a Rust project?


#5

You can have traits in one crate, and its implementation in another.

Yes the minimal unit of compilation is crate, not module.
But since rustc 1.24 supports incremental compilation (debug build only),
so it may show that it recompile all crate like:

$ cargo build -vv
   Compiling foo v0.1.0 (file:///tmp/foo)
     Running `rustc --crate-name foo src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e64a933cc2c2e1ce -C extra-filename=-e64a933cc2c2e1ce --out-dir /tmp/foo/target/debug/deps -C incremental=/tmp/foo/target/debug/incremental -L dependency=/tmp/foo/target/debug/deps`

but actually it rebuild only modified modules.