Specify build-output type through flags to cargo


In order to specify the output type of the build I normally use crate_type = "staticlib" etc in Cargo.toml. However i need to keep editing that in order to switch (from say static to building shared object). Is there a way i can do it from the command line invocation of cargo build instead ? Like cargo build --crate-type "dylib" or something like that ?


There isn’t any way to change between invocations, however it may be very useful for you to specify multiple outputs.

If you use crate_type = ["staticlib", "dylib", "rlib"], cargo will build a staticlib, dylib and rlib on every build. This isn’t exactly what you asked for, but is probably the best possible solution at the moment.