bytecodealliance/cargo-wasi

How to compile with SIMD?

Rochet2 opened this issue · 5 comments

Im having trouble compiling with SIMD. When trying to compile, I receive the following:

RUSTFLAGS="-C target-feature=+simd128" cargo wasi build --release --package app
<compilation output>
Finished release [optimized] target(s) in 0.09s
  Processing /home/rimi/Documents/example/target/wasm32-wasi/release/app.rustc.wasm
error: failed to process wasm at `/home/rimi/Documents/example/target/wasm32-wasi/release/app.rustc.wasm`
Caused by:
    failed to parse code section
Caused by:
    found type v128
Caused by:
    expected type i32
Caused by:
    The input WebAssembly is invalid

I suspect that there is a need to pass SIMD specific flags to some of the tooling, such as wasm-opt.
However, the same occurs even without the --release flag which should disable running the optimization step, so maybe the error originates from wasm bindgen? Its hard to tell what tool in the toolchain the error is originating from. Same is true for succeeding steps - there is no report on what tool actually succeeded in running
I am trying to target wasmtime and other standalone runtimes.
What kind of flags / steps do I need to take in order to compile with SIMD or is it not supported by cargo-wasi?

I also noted that if I have already compiled without SIMD successfully and then compile with SIMD unsuccessfully and try again, the compilation will simply skip the compilation and other steps altogether and report a success.
The compilation succeeds (as seen in the above error output), sure, but the optimization steps and such that are normally performed afterwards that cause an error are skipped. The files from a previous working non SIMD build are left in the target folder and could be used by a user if they are not careful.
For example:

cargo wasi build --release --package app # Success
RUSTFLAGS="-C target-feature=+simd128" cargo wasi build --release --package app # Error
RUSTFLAGS="-C target-feature=+simd128" cargo wasi build --release --package app # Success, even though shouldnt

Thanks for the report! You're doing all the right things, but the problem is that the dependencies used in the last-published binaries hadn't been updated for the simd proposal as-is today. I just pushed a new version of this tool, can you try that out and see if it fixes the issue for you?

Alas CI is failing, I'll have to fix that before a new version is published.

Ok it should be published now, if you can test the latest version.

to update, I tried the following

cargo wasi self update-check
    Checking for the latest release
error: failed to get successful response from https://crates.io/api/v1/crates/cargo-wasi: 403 Forbidden

I checked with browser if the URL works and it seems to work fine and returns a JSON.
I then continued to try with the normal installation command that worked fine cargo install cargo-wasi.
Afterward, the update command seems to work fine

cargo wasi self update-check
    Checking for the latest release
cargo-wasi v0.1.23 is up-to-date

And as for the SIMD compilation, it seems to work as expected now.

Ok great! I'm gonna close this assuming that error was spurious, but if it keeps cropping up I can try to investigate.