Skip to content

support for implementing "extern" functions required by C code when it's declared in a C header/rust-binding #58493

@M1cha

Description

@M1cha

Some C libraries require the user of the lib to implement (platform/sys) functions which are then used by the lib.

The library header usually declares the function so you can implement it wherever you want and get a compiler error if the signature has changed and your implementation is thus wrong now.

If I use bindgen to generate rust bindings for such a library I'm unable to implement such functions using rust, because they already are declared as extern to rust and the compiler treats this as duplicate/mismatching implementations.

If I would just blacklist these functions in bindgen so they'd not be part of the generated bindings there'd be no check if my rust function's signature actually matches the one declared in the C header which is installed on the system.

I think the solution to this would be adding a new function-attribute which lets you explicitly implement an extern function in rust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions