Closed
Description
Currently the only way to have attributes that apply conditionally is to duplicate the whole item (e.g. #[link()]
extern metadata that change per platform, or wish to have dynamic/static linking toggled externally). It'd be nice to have be able to avoid this.
Proposal: add cfg_attr(predicate, attribute)
that only applies attribute
if predicate
is satisfied. e.g.
#[cfg_attr(windows, link(name="mylib_win"))]
#[cfg_attr(not(windows), link(name="mylib"))]
extern {
fn mylib_some_func();
// ...
}
currently has to be
#[cfg(windows)]
#[link(name="mylib_win")]
extern {
fn mylib_some_func();
// ...
}
#[cfg(not(windows))]
#[link(name="mylib")]
extern {
fn mylib_some_func();
// ...
}