Rustc ability similar to `gcc -Dxxx=yyy`

Does rust has the ability to check some definitions which is passed in by compiler (similar to gcc -Dxxx=yyy)?

In C++ I checked the endianness of the target platform (by using CMake) and pass this information to my program (by using #ifdef), I wondered if I can do the same in rust?

You can do this with #[cfg], but you don't need CMake; Rust directly provides the target_endian cfg option.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.