boyanio / wasm-wheel

Demo project aiming to show the diversity of languages that compile to WebAssembly. See demo at https://boyan.io/wasm-wheel/
MIT License
43 stars 6 forks source link

Compiling the rand crate with rust #1

Closed ColinEberhardt closed 9 months ago

ColinEberhardt commented 6 years ago

I've just spotted that your rust code 'cheats' a little by using Math.random. The rand crate has a wasm branch that supports the wasm32-unknown-unknown target:

https://github.com/ColinEberhardt/wasm-rust-chip8/blob/master/Cargo.toml#L10

boyanio commented 6 years ago

Hey @ColinEberhardt Thanks for opening this issue. I had indeed some issues compiling the rand crate to WASM and that's why I decided to import JavaScript's randomizer. I tried to use the wasm branch you point to and it seems to compile fine. Unfortunately, I get the following error when calling the feelingLucky method:

wasm-0003c356-50:768 Uncaught RuntimeError: unreachable
    at wasm-function[50]:1578
    at wasm-function[2]:40
    at wasm-function[6]:454
    at wasm-function[1]:342
    at Object.feelingLucky (http://localhost:8080/js/index.js?v=2:47:49)
    ...

I created a separate branch with this. Do you have any idea why it fails?

ColinEberhardt commented 6 years ago

Just tested this with some of my own code, and se exactly the same failure. I'll raise an issue.

metronom72 commented 6 years ago

I've thought that it was problem with js loader, but looks like that this is problem with resolve dependencies? But if use some another operation without rand code successful exec.

boyanio commented 6 years ago

@metronom72 exactly, the same here. I have now upgraded to version 4.2.1 of the official branch and the compilation works fine. Unfortunately, I still get error when calling the function. I think these issues are "known" and will be fixed in the next version (AFAIU from reading the issues on the repo)

metronom72 commented 6 years ago

Thanks for answer. Will wait)

boyanio commented 9 months ago

After some years I have finally managed to do it ^_^