At the time of the request, if you have bin and lib in the same cargo project and you want to create bin and lib with specific rustc cfg parameters, it does not work.
You can create one or the other rustc cfg parameter, but not both. And if you try to build the lib library, then bin, when bin is compiled, it recompiled lib without rustc options.
Is there a way to do both, and if not why? Am I really doomed to create my own build script anyway? If so, what's the point of having a load?
EDIT
Ok so maybe i was a little dramatic
Prerequisites / Extensions
Let's say I had something like:
SIC / lib.rs
pub mod mylib { #[cfg(not(dosomething))] pub use self::without_cfg::dosomething; #[cfg(dosomething)] pub use self::with_cfg::dosomething; mod with_cfg { pub fn dosomething() { println!("config option"); } } mod without_cfg { pub fn dosomething() { println!("no config option"); } } }
Src / main.rs
extern crate modules; use modules::mylib::dosomething; fn main() { dosomething(); }
So, if I compiled with the cfg option dosomething, I would get one version of the function, but if I didnβt have the config, I would get the default behavior or something else.
Now, if I try to compile with cargo rustc, I can never get the bin version with cfg dosomething installed in lib.
The closest thing I have come to is to do all this in a truck:
cargo rustc -v --lib -- --cfg dosomething cargo rustc -v --bin [bin name] -- --cfg dosomething
which first command will compile lib using cfg, but the second command will recompile lib without cfg to create bin.
The only workaround I came up with is:
cargo rustc -v --bin [bin name] -- --cfg dosomething
copy what it spits out to compile the command, for example:
rustc src/main.rs --crate-name [bin name] --crate-type bin -g --cfg dosomething --out-dir [/path/to/project]/target/debug --emit=dep-info,link -L dependency=[/path/to/project]/target/debug -L dependency=[/path/to/project]/target/debug/deps --extern modules=[/path/to/project]/target/debug/libmodules.rlib`
then do:
cargo rustc -v --lib -- --cfg dosomething
and finally copy and paste the rustc command from earlier to compile bin with lib having the cfg option.
Is this the only way? Why can't I somehow indicate which libraries / libraries load the rustc cfg parameters that I want, even if it is in Cargo.toml? Or I and I do not understand this?
For those who asked ...
Cargo.toml:
[package] name = "[bin name]" version = "0.1.0" authors = ["[Me] <[my email]>"] [lib] name = "modules" path = "src/lib.rs"
PS Thanks to everyone who worked on rust and cargo. In general, I find it pleasant to work and love the language. Keep up the good work.