My goal is to create a C API where the user is required to provide a block of memory with a certain size. This size happens to be the size of a struct in my rust library, and so I'd like to extract the size of the rust struct and place it in a header file as a C macro.
The problem is that I'm cross-compiling my library, so I can't run a program on my computer that prints core::mem::size_of::<MyStruct>()
. But I can store that value in a const
variable in my library.
Is there any way to extract the value of this const
variable representing the size of my struct at compile time such that I can then paste it into a C header file?