Is it possible port bindgen into #![no_std] environment?

I'm writting a toy Rust lib for R plugins (mostly since the exist one, extendr_api, is slower than expected) and currently stuck at dealing with panic.

R have an unsafe function that could be regard as panic handler (libR_sys::Rf_error), but currently, libR_sys::Rf_error depends on std, thus I cannot bind it to #[panic_handler] directly.

Is there a better way to generate _sys crate without the dependency of std?
or, the only solution is writting an ugly macro that wrapping every function with std::panic::catch_unwind?

It's been a while since I've done this, so I'm going from pure memory, but are you passing bindgen the --use-core flag to tell it to use core instead of std? I also have vague recollections of needing to use the --ctypes-prefix flag to allow bindgen to find C FFI types outside std.

1 Like

If you use #[panic_handler] inside libR-sys, you will not be able to use this crate together with anything that needs libstd at all.

1 Like

Sorry for not searching the document entirely.
Thank you for your enthusiasm and patient:)

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.