Expand description
§RustCrypto: CPU bits selection
Compile-time detection heuristics for the optimal word size to use for the
target CPU, which in some cases may differ from its address size a.k.a.
target_pointer_width.
Implemented as macro_rules!.
§Example
Below is a basic example of how you can use the cpubits! macro:
cpubits::cpubits! {
16 => { pub type Word = u16; }
32 => { pub type Word = u32; }
64 => { pub type Word = u64; }
}§License
Licensed under either of:
at your option.
Includes portions from the cfg-if crate, which are also dual-licensed Apache 2.0 + MIT.
Copyright (c) 2014 Alex Crichton.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
§Supported bit sizes
This crate supports the following bit sizes:
163264
This matches the available options for target_pointer_width in rustc:
expected values for `target_pointer_width` are: `16`, `32`, and `64`§Overriding the selection result via cfg
This crate supports overriding its detection heuristics via an explicit cfg setting:
cpubits = "16": force 16-bitcpubits = "32": force 32-bitcpubits = "64": force 64-bit
This can be useful for testing different backends, and also in the event you would like to override the default detection result (in which case we would appreciate it if you opened an issue and let us know why).
You can set cfg via the RUSTFLAGS environment variable:
$ RUSTFLAGS='--cfg cpubits="64"' cargo build --releaseOr you can persistently configure it for your project in .cargo/config.toml:
# In .cargo/config.toml
[build]
rustflags = ['--cfg', 'cpubits="64"']§Lint configuration for cfg(cpubits)
If you are using the cpubits! macro you will notice the following warning being emitted:
warning: unexpected `cfg` condition name: `cpubits`You will need to add the following configuration to your Cargo.toml to silence the warning:
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(cpubits, values("16", "32", "64"))']Macros§
- cpubits
- A macro for defining code based on the optimal word size to use for the target, as chosen
heuristically at compile-time using
cfg-based predicates.
Constants§
- CPUBITS
- Constant representing the detection result from
cpubits!on the current target.