Build binary with specific features


I want to generate two binaries based on the same code but different features. For example:

# cargo build --features sslocal
name = "sslocal"
path = "src/"
required-features = ["sslocal"]

# cargo build 
name = "ssserver"
path = "src/"

Is there any way to do this?



I think you can use --release flag from cargo to do this.

cargo build --release

You will find in your release directory two binaries :slight_smile:



It actually generated two same binaries (them are all ssserver), what I want is two different binaries based on the depend features. In this case, if I want generate sslocal, I need Cargo.toml pass --features sslocal to cargo in a way.


Unfortunately, this is currently not possible. You will either need to run cargo twice specifying the correct --bin and --features for each run, or you can split your crate into two crates where the correct features for each are automatically selected.