Build binary with specific features


#1

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

# cargo build --features sslocal
[[bin]]
name = "sslocal"
path = "src/main.rs"
required-features = ["sslocal"]

# cargo build 
[[bin]]
name = "ssserver"
path = "src/main.rs"

Is there any way to do this?


#2

Hi,

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:

bye


#3

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.


#4

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.


#5

Thanks.