alexcrichton / wasm-sodium

PoC of libsodium being used in Rust on wasm32-unknown-unknown
25 stars 3 forks source link

error parsing #[wasm_bindgen] attribute options: failed to parse all tokens #3

Open qdwang opened 6 years ago

qdwang commented 6 years ago

with this toml info

[dependencies]
wasm-bindgen = "0.2.19"
lazy_static = "1.1.0"
sodiumoxide = { git = 'https://github.com/alexcrichton/sodiumoxide', branch = 'wasm32' }
libc-stub = { path = 'src/libc-stub' }

[patch.crates-io]
wasm-bindgen = { git = 'https://github.com/rustwasm/wasm-bindgen' }

getting this error

error: error parsing #[wasm_bindgen] attribute options: failed to parse all tokens
   --> src/libc-stub/src/lib.rs:164:16
    |
164 | #[wasm_bindgen(module = "crypto", version = "*")]
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `libc-stub`.

I'm trying to use parcel to bundle rust program with sodium into wasm. Don't know how to fix this.

alexcrichton commented 6 years ago

Thanks for the report! Unfortunately this is a bit of a bitrotted example at this point as the LLVM/Rust release are out of sync, but this should be fixable by dropping the version = "*" directive!

qdwang commented 6 years ago

Still having issues.

error[E0432]: unresolved import `std::heap`
  --> src/libc-stub/src/lib.rs:39:10
   |
39 | use std::heap::{GlobalAlloc, Global, Layout};
   |          ^^^^ Could not find `heap` in `std`

Then I change the code to

use std::alloc::Alloc;
use std::alloc::{GlobalAlloc, Global, Layout};

But another error showed up

   Compiling libc-stub v0.1.0 (file:///home/qdwang/Codes/tradebot/src/libc-stub)
error[E0605]: non-primitive cast: `std::result::Result<std::ptr::NonNull<u8>, std::alloc::AllocErr>` as `*mut usize`
  --> src/libc-stub/src/lib.rs:96:15
   |
96 |     let ptr = Global.alloc(layout) as *mut usize;
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

error[E0308]: mismatched types
   --> src/libc-stub/src/lib.rs:110:20
    |
110 |     Global.dealloc(ptr as *mut _, layout);
    |                    ^^^^^^^^^^^^^ expected struct `std::ptr::NonNull`, found *-ptr
    |
    = note: expected type `std::ptr::NonNull<u8>`
               found type `*mut _`

error: aborting due to 2 previous errors

I'm using rustc 1.28.0 (9634041f0 2018-07-30)

alexcrichton commented 6 years ago

The wonders of living on nightly! That should be fixable by switching to #[global_allocator] which likely has an updated signature.