You can use the cfg_attr(a, b) attribute:
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
pub struct MyStruct;
It’s described in the Rust reference about “conditional compilation”:
#[cfg_attr(a, b)] itemWill be the same as
#[b] itemifais set bycfg, anditemotherwise.