Conditionally compile a module


#1

Sometimes while refactoring a change in one of the modules has impact on every other module, because say a type has been changed or a function parameter has been changed etc. In this case instead of changing everything and then compiling at once is there a way i can compile and run unit tests for only that particular module, tweak it to hearts content and when all is right changed the other modules etc and run the complete/normal cargo build/test ? Of-course one of the ways could be to manually comment/uncomment the module listings in their corresponding root module that introduces them, but is there any other way directly from say cargo test --someflag -only_this_module or something ?

Explaining More:

say I have following modules: a, b, c, d, e, f, g, h where f depends only on g and h but rest of a, b, c, d, e depend on f (and maybe g and h but that should not matter). g and h ofcourse dont depend on anything from above. So if i make a change to f i want to compile only f and test it without changing all of them. Since f depends only on g and h i assume that if things are fine with these three then i should be able to test f even though a, b ... e are broken and crate will not compile if i do the normal cargo build/test . Is this possible?


#2

Rust’s unit of compilation is a crate, so you can’t compile just individual modules.


#3

Crosspost on stackoverflow: http://stackoverflow.com/questions/30890188/conditionally-compile-only-one-module-at-a-time

If you really want this, you can add #![cfg(feature="activate_a")] before the mod a; and create your dependency tree in cargo with features: http://doc.crates.io/manifest.html#the-[features]-section

but the correct way would be to split your crate into multiple crates and let cargo do the dependency and recompilation math for you