Skip to content

Support unsafe attribute for Rust 2024 edition #102

@mezum

Description

@mezum

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

  1. Extract the attached tarball.
  2. Run cargo build.
  3. Open ./target/csbindgen/NativeMethods.g.cs but It contains no DllImported methods.

csbindgen-with-rust2024.tar.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions