Generate inlineable C code for short exported rust functions

I’ve been writing a FFI for my Rust code, and I’ve used cbindgen to generate my C/C++ compatible header file. All good so far.

Some of my FFI functions are pretty small and likely to be hot, and I’m curious to know if there’s a way to generate “inline C” code for these rather than compile to a linkable function. It would be cool if these short functions could be transpiled into C, and emitted as inline functions in the header file produced by cbindgen.

I’ve not come across anything like this yet. So I’m wondering if it’s possible, or if there’s another approach that I should be considering.

This seems pretty convoluted; why not turn on LTO instead in your C toolchain? That'd take care of inlining across modules/object files.

LTO for the consumer would only work if the rust compiler produced a library in the right format for the C consumers, no?

For example, if my consumer uses GCC, I’d need rustc to emit GIMPLE. If my consumer uses MSVC, rustc would need to emit whatever it needs.. and so on and on for different C toolchains.

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.