Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support import_name and import_module attributes when targeting wasm32 #2918

Open
nasso opened this issue Sep 1, 2024 · 1 comment
Open

Comments

@nasso
Copy link

nasso commented Sep 1, 2024

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();
}
@nasso nasso changed the title Support import_name and import_module attributes Support import_name and import_module attributes when targeting wasm32 Sep 1, 2024
@pvdrz
Copy link
Contributor

pvdrz commented Sep 7, 2024

My first impression is that this shouldn't be too difficult to do as we already do some attribute detection for other things. Maybe the hardest part would be to set the attribute for the extern "C" block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants