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 extern bindings (imports) from within rust modules. #588

Closed
richard-uk1 opened this issue Jul 30, 2018 · 3 comments
Closed

Support extern bindings (imports) from within rust modules. #588

richard-uk1 opened this issue Jul 30, 2018 · 3 comments

Comments

@richard-uk1
Copy link
Contributor

richard-uk1 commented Jul 30, 2018

To support functionality like the following:

#![feature(proc_macro_mod)]

#[wasm_bindgen]
mod console {
    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(js_namespace = console)]
        pub fn log(s: &str);
    }
}

This is an attempt to split the issues #253, #254, #450, possibly others, into 2 parts - the codegen part and the AST transform part.

It would also be useful functionality, to allow rust developers to put their bindings into something other than the global namespace.

@alexcrichton
Copy link
Contributor

Note that this is supported today so long as console is pub (which is a bug). Are you thinking though that the macro itself should generate a module?

@richard-uk1
Copy link
Contributor Author

Yeah I was thinking of generating something like

mod console {
    pub fn log(s: &str) {
        __our_mangled_external_fn(s)
    }
}

extern "C" {
    #[doc(hidden)]
    pub fn __our_mangled_external_fn(s: TheABIType) {
        // ...
    }
}

or something else, I've not really figured out how wasm-bindgen joins the imports yet.

@richard-uk1
Copy link
Contributor Author

I've looked again, and I think this is probably a duplicate of that other issue.

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

No branches or pull requests

2 participants