Upgrade cbindgen and use unsafe(no_mangle) attributes (#8539)

To be compatible with the 2024 edition, we need to wrap the
`no_mangle` attribute in `unsafe()`.

The parsing for that in cbindgen was only added in the version 0.28,
but we couldn't upgrade cbindgen before because of a regression in
cbindgen 0.27 that prevented us from upgrading.
Now that cbindgen 0.29 is released with a fix, we can prepare for the
2024 edition
This commit is contained in:
Olivier Goffart 2025-05-26 11:21:33 +02:00 committed by GitHub
parent 83db461f63
commit 23962b3e25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 278 additions and 279 deletions

View file

@ -34,7 +34,7 @@ pub use i_slint_backend_testing;
#[cfg(feature = "slint-interpreter")]
pub use slint_interpreter;
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_windowrc_init(out: *mut WindowAdapterRcOpaque) {
assert_eq!(
core::mem::size_of::<Rc<dyn WindowAdapter>>(),
@ -44,7 +44,7 @@ pub unsafe extern "C" fn slint_windowrc_init(out: *mut WindowAdapterRcOpaque) {
core::ptr::write(out as *mut Rc<dyn WindowAdapter>, win);
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_ensure_backend() {
with_platform(|_b| {
// Nothing to do, just make sure a backend was created
@ -53,7 +53,7 @@ pub unsafe extern "C" fn slint_ensure_backend() {
.unwrap()
}
#[no_mangle]
#[unsafe(no_mangle)]
/// Enters the main event loop.
pub extern "C" fn slint_run_event_loop(quit_on_last_window_closed: bool) {
with_platform(|b| {
@ -67,7 +67,7 @@ pub extern "C" fn slint_run_event_loop(quit_on_last_window_closed: bool) {
}
/// Will execute the given functor in the main thread
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_post_event(
event: extern "C" fn(user_data: *mut c_void),
user_data: *mut c_void,
@ -94,13 +94,13 @@ pub unsafe extern "C" fn slint_post_event(
.unwrap();
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_quit_event_loop() {
i_slint_core::api::quit_event_loop().unwrap();
}
#[cfg(feature = "std")]
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_register_font_from_path(
win: *const WindowAdapterRcOpaque,
path: &SharedString,
@ -117,7 +117,7 @@ pub unsafe extern "C" fn slint_register_font_from_path(
}
#[cfg(feature = "std")]
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_register_font_from_data(
win: *const WindowAdapterRcOpaque,
data: i_slint_core::slice::Slice<'static, u8>,
@ -130,7 +130,7 @@ pub unsafe extern "C" fn slint_register_font_from_data(
};
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_register_bitmap_font(
win: *const WindowAdapterRcOpaque,
font_data: &'static i_slint_core::graphics::BitmapFont,
@ -139,7 +139,7 @@ pub unsafe extern "C" fn slint_register_bitmap_font(
window_adapter.renderer().register_bitmap_font(font_data);
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32) -> bool {
match string.as_str().parse::<f32>() {
Ok(v) => {
@ -150,12 +150,12 @@ pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32)
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn slint_string_character_count(string: &SharedString) -> usize {
unicode_segmentation::UnicodeSegmentation::graphemes(string.as_str(), true).count()
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn slint_string_to_usize(string: &SharedString, value: &mut usize) -> bool {
match string.as_str().parse::<usize>() {
Ok(v) => {
@ -166,7 +166,7 @@ pub extern "C" fn slint_string_to_usize(string: &SharedString, value: &mut usize
}
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn slint_debug(string: &SharedString) {
i_slint_core::debug_log!("{string}");
}
@ -218,14 +218,14 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
#[cfg(feature = "esp-backtrace")]
use esp_backtrace as _;
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_set_xdg_app_id(_app_id: &SharedString) {
#[cfg(feature = "i-slint-backend-selector")]
i_slint_backend_selector::with_global_context(|ctx| ctx.set_xdg_app_id(_app_id.clone()))
.unwrap();
}
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_detect_operating_system(out: &mut SharedString) {
*out = i_slint_core::detect_operating_system();
}