Support unsafe attribute for Rust 2024 edition
Summary
csbindgen connot generate C# Native method declarations from Rust 2024 edition sources
because some attributes (such as no_mangle and export_name) must now be marked as unsafe
using new introduced attribute unsafe but csbindgen cannot recognize it.
Workaround
Use 2021 edition and no_mangle and export_name without unsafe attribute.
Details
From Rust 1.82, some attributes has ability in all editions to mark as unsafe like this:
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hoge_init() {}
#[allow(non_snake_case)]
#[unsafe(export_name = "hoge_deinit")]
pub unsafe extern "C" fn Destroy() {}
Last February 21, Rust 1.85 stable has been released with 2024 edition!
But in 2024 edition, these attributes must be marked as unsafe.
csbindgen cannot recognize unsafe attribute, so generated codes contains no DllImported native methods.
Reproduce
- Extract the attached tarball.
- Run
cargo build. - Open
./target/csbindgen/NativeMethods.g.csbut It contains no DllImported methods.
+1
I also encountered this issue and was going to raise the same issue. I suggest change to if name == "no_mangle || name == "unsafe(no_mange)" in
https://github.com/Cysharp/csbindgen/blob/768761c834941ffd26d8c5c44f5d8403d485dad1/csbindgen/src/parser.rs#L126
I am noob in Rust, just correct me if if I make any mistakes.
Happened to have the same issue when migrated to Rust edition 2024.
#103 has been released in v1.9.4.