Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created January 4, 2022 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/7ee890172f3d84122e6a0501dd87c2d8 to your computer and use it in GitHub Desktop.
Save eduardonunesp/7ee890172f3d84122e6a0501dd87c2d8 to your computer and use it in GitHub Desktop.
if cfg!(target_os = "windows") { /* ... */ }
#[cfg(target_os = "linux")] // can be linux android windows macos ios
#[cfg(target_pointer_width = 64)] // target 64 bit systems
#[cfg(target_pointer_width = 32)] // target 32 bit systems
// Compiler features
#![feature(feature1, feature2, feature3)]
#[cfg(feature = "foo")]
// combining multiple conditions
#[cfg(any(unix, windows))]
#[cfg(not(macos))]
#[cfg(not(unix), all(target_os="macos", target_arch = "powerpc"))]
#![plugin(foo, bar)]
// Load a module from a specified file
#[path = "foo.rs"]
mod bar;
// Set crate type to library
#![crate_type = "lib"]
// You can set attributes based on a cfg variable
#[cfg_attr("is_cool", windows)] // sets the is_cool attribute if compiling for windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment