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

integrating wasm-bindgen #13

Closed
ashleygwilliams opened this issue Mar 1, 2018 · 4 comments
Closed

integrating wasm-bindgen #13

ashleygwilliams opened this issue Mar 1, 2018 · 4 comments
Labels
question Further information is requested

Comments

@ashleygwilliams
Copy link
Member

ashleygwilliams commented Mar 1, 2018

there are several steps to using wasm-bindgen that i'd like to discuss here:

  1. rustup target add wasm32-unknown-unknown

  2. add wasm-bindgen as a dep to Cargo.toml:

     [lib]
     crate-type = ["cdylib"]
    
     [dependencies]
     wasm-bindgen = { git = 'https://github.com/alexcrichton/wasm-bindgen' }
  3. add the following code to your src/lib.rs:

    #![feature(proc_macro)]
    
    extern crate wasm_bindgen;
    
    use wasm_bindgen::prelude::*;
    
    #[wasm_bindgen]
    extern {
        fn alert(s: &str);
    }
  4. add this annotation to each publicly exported function:

    #[wasm_bindgen]
    #[no_mangle]
  5. cargo build --release --target wasm32-unknown-unknown

  6. cargo install --git https://github.com/alexcrichton/wasm-bindgen (this seems redundant with 2??? https://github.com/alexcrichton/wasm-bindgen/issues/44)

  7. wasm-bindgen target/wasm32-unknown-unknown/release/<name of lib>.wasm \ --out-dir . (ergonomics ask: https://github.com/alexcrichton/wasm-bindgen/issues/45)

i can see clear ways to integrate 1, 2, 5, 6, 7. 3 and 4 will need to be done manually by the user. @alexcrichton do you have any thoughts on this?

@ashleygwilliams ashleygwilliams added the question Further information is requested label Mar 1, 2018
@ashleygwilliams
Copy link
Member Author

ashleygwilliams commented Mar 1, 2018

also curious for @linclark, @yoshuawuyts, @sendilkumarn's thoughts on the ergonomics of this all.

i am leaning toward integrating steps 1 and 5-7 into the tool. leaving 3 and 4 to the user. check out @alexcrichton's issue on how the ergonomics of this should work here: https://github.com/alexcrichton/wasm-bindgen/issues/46

@alexcrichton
Copy link
Contributor

FWIW the code for this example in wasm-bindgen will one day be:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[no_mangle]
pub extern fn foo() {
    webabi_sys::alert("hello!");
}

in that #![feature] will eventually get stabilized (procedural macros), extern crate annotations will no longer be necessary (an epoch change), and the extern block won't be necessary with WebIDL-generated binding crates. It may also be reasonable to not require #[no_mangle] and extern functions for the #[wasm_bindgen] macro when exporting functions as well!

@sendilkumarn
Copy link
Member

@ashleygwilliams I haven't played enough with bindgen (which I will hopefully do it in next week) But having a quick look. I too find adding 1,5 and 7 and leaving 3 & 4 makes super sense. OTOH, would love to add a sample repo to how to do 3&4 would be cool 😎 WDYT?

@ashleygwilliams
Copy link
Member Author

@sendilkumarn done! totally agree :) see #17

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

No branches or pull requests

3 participants