I’ve been hacking on rust-lexer recently and spend quite some time waiting for the stage1 compiler to build. Naturally, it was the perfect occasion to think about compilation firewalls for Rust.
My understanding is that, in gigantic projects, one goes out of the way to break compile-time dependencies between modules, to avoid excruciatingly slow rebuilds. In C++, this is achieved by carefully crafting header files: if you don’t change
.h, you don’t have to recompile anything, only re-link (which gives raise to the pimpl). I’ve heard that at Google they do something similar for Java, by producing so-called “interface jars”: jars with only
interface definitions, whose implementation is substituted at runtime using DI.
Do we have something similar for Rust already? I guess we can implement Java-style DI on top of
dyn traits by hand, but it feel that this is going to be really unwieldy and limiting.
Are there any plans for language/compiler features to enable these sorts of firewalls while maintaining static dispatch, a-la C++? I guess my ideal here is that if crate’s
pub API consist solely of non-generic functions, than any change not touching the API should not cause downstream dependencies to be rebuild at all. I this could work by compiler producing some-sort of “interface” file alongside the
.rlib, making intermediate downstream crates to depend only on this interface files, and making only the final artifact (binary, dylib, staticlib) to depend on both interfaces and