Wasmer: Function signature mismatch when trying to run simple Rust program

Created on 17 Feb 2019  ·  7Comments  ·  Source: wasmerio/wasmer

I'm trying to run a very simple Rust program that uses println!. I'm not sure if this is even supposed to work like I did it (please tell me if not), but certainly the error message could be improved.

The Rust program:

enum E {
    A = 0x1234_5678,
    B = 0xF321_8765,
}

use std::mem::size_of;

fn main() {
    println!("{}", size_of::<E>());
}

Compiled with (current Rust stable or nightly produce the same issue here) rustc test.rs --target=wasm32-unknown-unknown, then running wasmer run test.wasm gives this error:

"Resolve(Signature { expected: FuncSig { params: [I32, I32], returns: [I32] }, found: [] })"

(this is on the current wasmer master 7602071e1a1633f8d007fc0efc4e1049d2b8419e)

❓ question

Most helpful comment

@jonas-schievink Thanks for reporting this issue. I agree, seems like println should just work, right?

Both @lachlansneff and @CryZe are correct. Right now, Wasmer does not support "binary" applications. Instead, one can create cdylib projects, but these are limited in many ways. This is a great start for Wasmer, but like you noticed it's not very useful for some problems. One can build a cydlib with Rust using the target wasm32-unknown-unknown.

There is a way to get what you want but it involves a little bit of extra work: build with for the wasm32-unknown-emscripten target. Both nginx.wasm and lua.wasm were made with emscripten, which a project that helps you compile code to wasm. The wasm32-unknown-emscripten target will allow you to build binary applications with Rust. Wasmer will have experimental support in Wasmer 0.2.0 release for this target.

If you would like to experiment with this more, you can pull down the master branch of wasmer and start hacking with the emscripten target. I got your example (with a few modifications) to run locally. To get started with wasm32-unknown-emscripten target, you first must download emscripten here, and setup your environment. This is pretty easy if you follow the instructions.

When your environment is setup for emscripten, you can build the project (your toy project, NOT wasmer) with cargo build --target wasm32-unknown-emscripten. The wasm file will be in your target/wasm32-unknown-emscripten directory.

Then run with wasmer from the source:

> path/to/wasmer/target/debug/wasmer run path/to/proj/target/wasm32-unknown-emscripten/proj.wasm

This runs locally for me! If it doesn't work, please let me know ❗️ I will work with you on it.

All 7 comments

You compiled the Rust code as a library, not binary, that won‘t work. Rust can‘t really target executables with the unknown target at the moment anyway afaik.

I see. Although that invocation should create a binary anyways.

As @CryZe said, rust doesn't really support creating standalone wasm modules. You could compile using the emscripten target if you wanted.

@jonas-schievink Thanks for reporting this issue. I agree, seems like println should just work, right?

Both @lachlansneff and @CryZe are correct. Right now, Wasmer does not support "binary" applications. Instead, one can create cdylib projects, but these are limited in many ways. This is a great start for Wasmer, but like you noticed it's not very useful for some problems. One can build a cydlib with Rust using the target wasm32-unknown-unknown.

There is a way to get what you want but it involves a little bit of extra work: build with for the wasm32-unknown-emscripten target. Both nginx.wasm and lua.wasm were made with emscripten, which a project that helps you compile code to wasm. The wasm32-unknown-emscripten target will allow you to build binary applications with Rust. Wasmer will have experimental support in Wasmer 0.2.0 release for this target.

If you would like to experiment with this more, you can pull down the master branch of wasmer and start hacking with the emscripten target. I got your example (with a few modifications) to run locally. To get started with wasm32-unknown-emscripten target, you first must download emscripten here, and setup your environment. This is pretty easy if you follow the instructions.

When your environment is setup for emscripten, you can build the project (your toy project, NOT wasmer) with cargo build --target wasm32-unknown-emscripten. The wasm file will be in your target/wasm32-unknown-emscripten directory.

Then run with wasmer from the source:

> path/to/wasmer/target/debug/wasmer run path/to/proj/target/wasm32-unknown-emscripten/proj.wasm

This runs locally for me! If it doesn't work, please let me know ❗️ I will work with you on it.

@xmclark thanks for the explanation, that's very helpful!

Can we close the issue then?

Your decision. A better error message would be nice, and @xmclark's great explanation above could probably be moved to a more visible place, but if you think this should be closed anyways, go ahead.

Was this page helpful?
0 / 5 - 0 ratings