是否有所有 cfg 功能的列表?

Is there a list of all cfg features?

Rust 有能力 check configuration at build 时间,例如 #[cfg(target_os = "linux")]if cfg!(target_os = "linux") {...},其中 target_os 是一个 特征 .

是否有可以在 Rust 中检查的所有(或至少是常用的)功能的列表?


参见有关 属性的相关问题

"Conditional compilation" section of the Reference 有一个必须定义的配置列表(从 Rust 1.14 开始):

  • target_arch 的值如下:
    • x86
    • x86_64
    • mips
    • powerpc
    • powerpc64
    • arm
    • aarch64
  • target_os 的值如下:
    • windows
    • macos
    • ios
    • linux
    • android
    • freebsd
    • dragonfly
    • bitrig
    • openbsd
    • netbsd
  • target_family 的值如下:
    • unix
    • windows
  • unixtarget_family 的快捷方式)
  • windowstarget_family 的快捷方式)
  • target_env 的值如下:
    • gnu
    • msvc
    • musl
    • ""(空字符串)
  • target_endian 值:
    • little
    • big
  • target_pointer_width 的值如下:
    • 32
    • 64
  • target_has_atomic 的值如下:
    • 8
    • 16
    • 32
    • 64
    • ptr
  • target_vendor 的值如下:
    • apple
    • pc
    • unknown
  • test
  • debug_assertions

另请参阅 https://internals.rust-lang.org/t/all-the-rust-features/4322 以获取完整的功能列表。

请记住,部分/大部分功能不会稳定,因此只能在夜间提供一段时间,并且在稳定或停产之前会进行重大改进/升级。

rust nightly 中的特性是适者生存。

您也可以使用此命令:rustc --print target-list

每个三元组的格式如下:{arch}-{vendor}-{sys}-{abi}.

例如,三元组'arm-unknown-linux-gnueabihf'指的是:

  1. 架构:手臂
  2. 供应商:未知。在这种情况下,没有指定供应商。
  3. 系统:linux
  4. ABI:gnueabihf