[−][src]Macro cfg_aliases::cfg_aliases
Create cfg
aliases
build.rs:
// Setup cfg aliases cfg_aliases! { // Platforms wasm: { target_arch = "wasm32" }, android: { target_os = "android" }, macos: { target_os = "macos" }, linux: { target_os = "linux" }, // Backends surfman: { all(unix, feature = "surfman", not(wasm)) }, glutin: { all(feature = "glutin", not(wasm)) }, wgl: { all(windows, feature = "wgl", not(wasm)) }, dummy: { not(any(wasm, glutin, wgl, surfman)) }, }
After you put this in your build script you can then check for those conditions like so:
#[cfg(surfman)] { // Do stuff related to surfman } #[cfg(dummy)] println!("We're in dummy mode, specify another feature if you want a smarter app!");
This greatly improves what would otherwise look like this without the aliases:
#[cfg(all(unix, feature = "surfman", not(target_arch = "wasm32")))] { // Do stuff related to surfman } #[cfg(not(any( target_arch = "wasm32", all(unix, feature = "surfman", not(target_arch = "wasm32")), all(windows, feature = "wgl", not(target_arch = "wasm32")), all(feature = "glutin", not(target_arch = "wasm32")), )))] println!("We're in dummy mode, specify another feature if you want a smarter app!");