Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

rust - Is there a list of all cfg features?

Rust has the ability to check configuration at build time with, e.g., #[cfg(target_os = "linux")] or if cfg!(target_os = "linux") {...}, where target_os is a feature.

Is there a list of all (or, at least, commonly used) features that can be checked in Rust?


See related question regarding attributes Is there an exhaustive list of standard attributes anywhere?.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The "Conditional compilation" section of the Reference has a list of configurations that must be defined (as of Rust 1.14):

  • target_arch with values like:
    • x86
    • x86_64
    • mips
    • powerpc
    • powerpc64
    • arm
    • aarch64
  • target_os with values like:
    • windows
    • macos
    • ios
    • linux
    • android
    • freebsd
    • dragonfly
    • bitrig
    • openbsd
    • netbsd
  • target_family with values like:
    • unix
    • windows
  • unix (shortcut for target_family)
  • windows (shortcut for target_family)
  • target_env with values like:
    • gnu
    • msvc
    • musl
    • "" (empty string)
  • target_endian with values:
    • little
    • big
  • target_pointer_width with values like:
    • 32
    • 64
  • target_has_atomic with values like:
    • 8
    • 16
    • 32
    • 64
    • ptr
  • target_vendor with values like:
    • apple
    • pc
    • unknown
  • test
  • debug_assertions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...