rust-lang / rust-lang/rust-bindgen

Support `import_name` and `import_module` attributes when targeting `wasm32`

Open
#2,918 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing wasm_import_module_name handling and how bindgen processes Clang attributes when invoked with -- -target wasm32. Use the provided input.h example as the reproduction, and consider the work complete when generated bindings include #[link(wasm_import_module = "foo")] and #[link_name = "bar"] for the annotated function.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.