Skip to content

Support import_name and import_module attributes when targeting wasm32 #2918

Open
@nasso

Description

@nasso

I know we already have wasm_import_module_name, but clang already has attributes for that! Supporting them directly would be much more convenient, I think?

See: https://clang.llvm.org/docs/AttributeReference.html#import-module

Another big motivation for this would be that it allows importing from different modules in the same header.

Input C/C++ Header

#ifdef __wasm__
__attribute__((visibility("default"), import_module("foo"), import_name("bar")))
#endif
void foo_bar();

Bindgen Invocation

$ bindgen input.h -- -target wasm32

Note that clang must be passed -target wasm32 to recognize the attributes.

Actual Results

/* automatically generated by rust-bindgen 0.70.1 */

extern "C" {
    pub fn foo_bar();
}

Expected Results

/* automatically generated by rust-bindgen 0.70.1 */

#[link(wasm_import_module = "foo")]
extern "C" {
    #[link_name = "bar"]
    pub fn foo_bar();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions