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

build failed when converting .rs to .wasm #900

Closed
SimonWang9610 opened this issue Aug 14, 2020 · 9 comments
Closed

build failed when converting .rs to .wasm #900

SimonWang9610 opened this issue Aug 14, 2020 · 9 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists wasm-opt

Comments

@SimonWang9610
Copy link

🐛 Bug description

When I followed the official document Rust and WebAssembly and coded the example Conway's Game of Life, I failed to run wasm-pack build. Error Message as below:

Fatal: error in validating input
Error: failed to execute ``wasm-opt``: exited with exit code: 1
full command: "C:\\Users\\Simon\\AppData\\Local\\.wasm-pack\\wasm-opt-171374efd61df962\\wasm-opt.exe" "C:\\projects\\learn-rust\\wasm-game-of-life\\pkg\\wasm_game_of_life_bg.wasm" "-o" "C:\\projects\\learn-rust\\wasm-game-of-life\\pkg\\wasm_game_of_life_bg.wasm-opt.wasm" "-O" To disable ``wasm-opt``, add ``wasm-opt = false`` to your package metadata in your ``Cargo.toml.`

Even though I disabled wasm-opt = false, the compiled process was passed but it failed to work with the glue code. I mean, run npm run start it did not work as expected.

the Rust code is the same as the example in the Doc Rust and WebAssembly.

🤔 Expected Behavior

I want to know it is a bug? or something wrong I did?
I am totally a beginner on Rust & WebAssembly, hope you guys can help me.

🌍 Your environment

Include the relevant details of your environment.
wasm-pack version: wasm-pack 0.9.1
rustc version: rustc 1.45.0 (5c1f21c3b 2020-07-13)
wee_alloc version: 0.4.5
wasm-bindgen version: 0.2.63
opt-level: 's'

Platform: Windows 10
IDE: VS code

@fermezz
Copy link

fermezz commented Aug 16, 2020

+1 here. Also very new to Rust/WASM. I was able to track down the error as coming from the render function for Universe. Apparently it's crashing because we return a String into Javascript? I tried commenting that function and it compiles fine. Also, I tried adding a totally unrelated

#[wasm_bindgen]
pub fn greet() -> String {
    format!("Hello")
}

function and the compilation error returned.

If you remove the #[wasm_bindgen] attribute, compilation goes back to normal.

@fermezz
Copy link

fermezz commented Aug 16, 2020

Problably related to rustwasm/wasm-bindgen#2279

@fermezz
Copy link

fermezz commented Aug 16, 2020

@SimonWang9610 you should be able to run cargo install --version 0.8.1 wasm-pack --force to go back to wasm-pack's 0.8.1 version, that's the last one I find this to be compiling correctly.

@SimonWang9610
Copy link
Author

SimonWang9610 commented Aug 16, 2020

@SimonWang9610 you should be able to run cargo install --version 0.8.1 wasm-pack --force to go back to wasm-pack's 0.8.1 version, that's the last one I find this to be compiling correctly.

Yeah, I tried your method. The compile process is passed, but the program did not work as expected. Like you said, probably because the returned value is String.
Thanks!

@fermezz
Copy link

fermezz commented Aug 17, 2020

@SimonWang9610 It should work if compiled successfully. It works for me, at least. What are you seeing?

@SimonWang9610
Copy link
Author

@fermezz but actually no. If I comment pun fn render() -> String {}, the compile is successful, and other functions work well.
if the function is pub and returns String type, the compiler will terminate at error in validating input.
if the function is not pub and return String type, the compiler works well.
all functions that return number like i32, u32, u8, f32 also work well.

So i am pretty sure there are some problems related to convert String from rust to wasm to JavaScript.

@fermezz
Copy link

fermezz commented Aug 17, 2020

@SimonWang9610 oh, yeah, totally. I meant that if you leave the render function untouched but downgrade the version for wasm-pack to 0.8.1 (instead of 0.9.1) you can compile successfully and have it working as expected.

@alvinhochun
Copy link

This is probably the same issue as #886. A workaround is mentioned in #886 (comment).

@ashleygwilliams ashleygwilliams added duplicate This issue or pull request already exists bug Something isn't working wasm-opt labels Dec 21, 2020
@ashleygwilliams
Copy link
Member

closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists wasm-opt
Projects
None yet
Development

No branches or pull requests

4 participants