gccrs: Backport `cfg_select!` macro, gate behind version flag
gccrs backports the `cfg_select!` macro and gates it behind a compatibility version flag.
The cfg_select! macro, essential for compiling Rust’s c_char type used in widespread CStr implementations, has been backported into gccrs. To manage compatibility, its usage is now gated behind the -frust-compat-version=1.90 flag. This ensures that newer Rust features are available while maintaining stability for older projects.
In Details
GCC's Rust front-end (gccrs) now includes a backport of the cfg_select! macro, a construct used in newer Rust core libraries for conditional compilation based on cfg attributes. This macro is particularly important for compiling c_char and subsequently CStr, which have broad applicability in Rust for Linux development. To maintain ABI compatibility and manage feature availability, the macro's enablement is controlled via the -frust-compat-version=1.90 session flag. This change involves modifications to macro expansion logic and AST handling within gccrs.
- cfg_select!
- A Rust macro that allows conditional compilation based on
cfg(configuration) attributes. It selects one of several blocks of code to expand based on matching predicates. - macro
- A piece of code that writes other code, a form of metaprogramming. In Rust, macros are invoked using an exclamation mark, e.g.,
macro_name!. - backport
- The process of taking a feature or fix from a newer version of software and applying it to an older, stable version. In this case, a Rust macro is added to an older GCC release.
- -frust-compat-version
- A compiler flag in
gccrsthat specifies the Rust compatibility version to adhere to. Setting it to1.90enables features and behaviors from that Rust version. - CStr
- A Rust type representing a C-style string, which is a null-terminated sequence of bytes. It is widely used for interoperability with C code and libraries.
- c_char
- A Rust type alias for the C
chartype. It is fundamental for interacting with C APIs and string handling in Rust.