Emit C attributes via cbindgen
C and C++ have supported attributes in some measure for decades. Attributes offer hints to the compiler such as if a function is deprecated or doesn't return. The latest revision of the C standard, C23, consolidates some of these attributes and uses a style similar to C++.
relibc
ships with a features.h
header that defined macros that
allowed using these attributes in a backwards compatible way. I updated
the macros to account for C23's attributes.
cbindgen
is able to auto emit these attributes based on Rust's
attributes. For example, #[deprecated = "Use foobar instead"]
turns
into [[deprecated("Use foobar instead")]]
. I updated relibc
's global
cbindgen
definitions to use the macros defined in "features.h".
The only caveat is that features.h
must be included where attributes
such as #[must_use]
are used. This is only a one line change in the
respective cbindgen.toml
where necessary.
I opted to rewrite the macros in features.h
because relibc
already
had similar macros defined there from musl
. However, I think it may be
better to move them to a different file which is indirectly included by
libc. It seems like glibc
does that, but I couldn't figure out how.
Finally, some tests squelch the new warnings in order to not
fail CI due to -Werror
.