Skip to content

Allow generating a C header representing the exported symbols of a lib #10530

@huonw

Description

@huonw

For example,

#[crate_type="lib"];

pub struct Foo { x: i16 }

#[no_mangle]
pub extern "C" fn bar(x: u64) -> Foo { ... }

pub fn ignored() { ... } // wrong ABI

would correspond to

#ifndef FILENAME_H
#define FILENAME_H

#include<stdint.h>

struct Foo {
    int16_t x;
}

struct Foo bar(uint64_t);

#endif

so that one can call into Rust from C more easily.

(This is the inverse operation of the proposed #[header="stdio.h"] mod stdio; functionality for using libclang to read C headers into a form that rustc understands: #2124)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions