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

Error with create-exe #2895

Closed
cyw3 opened this issue May 21, 2022 · 14 comments
Closed

Error with create-exe #2895

cyw3 opened this issue May 21, 2022 · 14 comments
Assignees
Labels
bug Something isn't working create-exe 🍋 Low-hanging Fruit priority-medium Medium priority issue
Milestone

Comments

@cyw3
Copy link
Contributor

cyw3 commented May 21, 2022

Describe the bug

  • when i use create-exe
$ wasmer create-exe hello.wasm -o ./hello --enable-all
Engine: staticlib
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
error: Failed to compile C source code
╰─▶ 1: C code compile failed with: stdout: 
       
       stderr: wasmer_main.c: In function ‘handle_arguments’:
       wasmer_main.c:49:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
          for (int i = 1; i < argc; ++i) {
          ^
       wasmer_main.c:49:3: note: use option -std=c99 or -std=gnu99 to compile your code
       
  • And after i add .arg("-std=c99") at this line and build the wasmer again:
$ wasmer create-exe hello.wasm -o ./hello
Engine: staticlib
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
✔ Native executable compiled successfully to `./hello`.


$ RUST_BACKTRACE=1 ./hello
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Custom { kind: UnexpectedEof, error: "" })', lib/engine-staticlib/src/artifact.rs:327:81
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fatal runtime error: failed to initiate panic, error 5
Aborted


$ RUST_BACKTRACE=full ./hello
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Custom { kind: UnexpectedEof, error: "" })', lib/engine-staticlib/src/artifact.rs:327:81
stack backtrace:
   0:           0xa728dc - std::backtrace_rs::backtrace::libunwind::trace::h3fea1eb2e0ba2ac9
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:           0xa728dc - std::backtrace_rs::backtrace::trace_unsynchronized::h849d83492cbc0d59
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:           0xa728dc - std::sys_common::backtrace::_print_fmt::he3179d37290f23d3
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:67:5
   3:           0xa728dc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h140f6925cad14324
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:46:22
fatal runtime error: failed to initiate panic, error 5
Aborted

Steps to reproduce

  1. it is a go project.
// main.go
package main

func main() {
	println("Hello World!")
}
  1. Then use tinygo to build go file to wasm.
docker run --rm -v $(pwd):/src tinygo/tinygo:0.23.0 \
    /bin/bash -c "
    cd /src
    tinygo build -o hello.wasm -target wasi main.go
    "
  1. use wasmer to create exe.
wasmer create-exe hello.wasm -o ./hello
./hello

Expected behavior

Actual behavior

Additional context

@cyw3 cyw3 added the bug Something isn't working label May 21, 2022
@ptitSeb
Copy link
Contributor

ptitSeb commented May 21, 2022

I think you need to gives much more information on your system. What hardware/OS are you using, and the different compiler version too.

@cyw3
Copy link
Contributor Author

cyw3 commented May 21, 2022

$ uname -a
Linux VM-89-86-centos 3.10.107-1-tlinux2_kvm_guest-0053 #1 SMP Fri Jul 3 20:40:27 CST 2020 x86_64 x86_64 x86_64 GNU/Linux

$ arch
x86_64

$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 

$ rustc -V
rustc 1.59.0 (9d1b2106e 2022-02-23)

@ptitSeb
Copy link
Contributor

ptitSeb commented May 21, 2022

gcc is 4.8 !!! :O
This is a really old version of gcc. I assume the OS is old too. We'll need to find a way to reproduce the issue.

@cyw3
Copy link
Contributor Author

cyw3 commented May 21, 2022

Can you provide a docker image to use the Wasmer's create-exe?

Thanks!

@epilys
Copy link
Contributor

epilys commented May 21, 2022

Centos with 3.10 kernel is also from 2014.

@cyw3
Copy link
Contributor Author

cyw3 commented May 22, 2022

  • I use the docker to build wasmer, create-exe and run ./hello.
    But have the same error.

    docker run --rm -v $(pwd):/src rust:1 \
        /bin/bash -c "
        cd /src
        make build-wasmer
        "
    
    export TARGET_DIR=/data/example/go/hello
    export WASMER_DIR=~/.wasmer/
    docker run --rm \
        -v $(pwd)/target/release:/wasmer/bin \
        -v ${TARGET_DIR}:/test \
        -v ${WASMER_DIR}:/root/.wasmer \
        rust:1 \
        /bin/bash -c "
            cd /test
            export WASMER_DIR=/root/.wasmer/
            /wasmer/bin/wasmer create-exe hello.wasm -o ./hello
    "
    
    docker run --rm \
        -v ${TARGET_DIR}:/test \
        rust:1 \
        /bin/bash -c "
            cd /test
            ./hello
    "
    
  • And when I use the ./hello above in Centos with 3.10 kernel (the old OS I using daily), I get a new error:

    $ ./hello
    ./hello: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by ./hello)

    Can I use ./hello without installing other libraries?

@cyw3
Copy link
Contributor Author

cyw3 commented May 22, 2022

  • I use the docker to build wasmer, create-exe and run ./hello.
    But have the same error.

  • And when I use the ./hello above in Centos with 3.10 kernel (the old OS I using daily), I get a new error:

    $ ./hello
    ./hello: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by ./hello)

    Can I use ./hello without installing other libraries?

  1. I use the test, and get the same error:
$ cd ./tests/examples

$ export WASMER_DIR=/root/.wasmer/

$ /wasmer/bin/wasmer create-exe fib.wat -o ./fib
Engine: staticlib
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
✔ Native executable compiled successfully to `./fib`.

$ ./fib
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Custom { kind: UnexpectedEof, error: "" })', lib/engine-staticlib/src/artifact.rs:327:81
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

@syrusakbary syrusakbary added this to the v3.0 milestone Jun 1, 2022
@syrusakbary
Copy link
Member

This issue is somewhat related to #2916

@cyw3
Copy link
Contributor Author

cyw3 commented Jun 12, 2022

Today, I update the codebase and try it again. The error was gone, but I get a new error:

$ cd ./tests/examples

$ export WASMER_DIR=/workspaces/wasmer/package/

$ /workspaces/wasmer/target/release/wasmer create-exe fib.wat -o ./fib
Engine: staticlib
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
✔ Native executable compiled successfully to `./fib`.

$ ./fib
Error getting WASI imports!
Error len: `52`
could not detect a WASI version on the given module

@epilys epilys added the priority-medium Medium priority issue label Jun 21, 2022
@syrusakbary
Copy link
Member

create-exe only works with WASI programs for now, so since fib doesn't have a main function, it fails.

Ideally, wasmer create-exe should require the wasm modules to be WASI ones and throw an error in case they are not

@syrusakbary syrusakbary assigned fschutt and unassigned syrusakbary Jun 21, 2022
@liudonghua123
Copy link

I have the same problems on windows. What's tools I need on windows?

C:\Users\LIUD~1.H\AppData\Local\Temp>cat hello.rs
fn main() {
    println!("Hello, world!");
}

C:\Users\LIUD~1.H\AppData\Local\Temp>rustc hello.rs --target wasm32-wasi

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer --version
wasmer 2.3.0

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer hello.wasm
Hello, world!

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
error: Failed to compile C source code
╰─▶ 1: program not found

C:\Users\LIUD~1.H\AppData\Local\Temp>vs2022
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************

C:\Users\LIUD~1.H\AppData\Local\Temp>cl /v
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31105 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/v'
cl : Command line error D8003 : missing source filename

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
error: Failed to compile C source code
╰─▶ 1: program not found

C:\Users\LIUD~1.H\AppData\Local\Temp>

@syrusakbary
Copy link
Member

syrusakbary commented Jun 29, 2022

We are working to re-add it in Wasmer (master) as part of #2987

@liudonghua123
Copy link

I have the same problems on windows. What's tools I need on windows?

C:\Users\LIUD~1.H\AppData\Local\Temp>cat hello.rs
fn main() {
    println!("Hello, world!");
}

C:\Users\LIUD~1.H\AppData\Local\Temp>rustc hello.rs --target wasm32-wasi

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer --version
wasmer 2.3.0

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer hello.wasm
Hello, world!

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
error: Failed to compile C source code
╰─▶ 1: program not found

C:\Users\LIUD~1.H\AppData\Local\Temp>vs2022
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************

C:\Users\LIUD~1.H\AppData\Local\Temp>cl /v
Microsoft (R) C/C++ Optimizing Compiler Version 19.31.31105 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '/v'
cl : Command line error D8003 : missing source filename

C:\Users\LIUD~1.H\AppData\Local\Temp>wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
error: Failed to compile C source code
╰─▶ 1: program not found

C:\Users\LIUD~1.H\AppData\Local\Temp>

I can use create-exe on windows now. All I need are to install llvm v11+ (I installed the latest v14), execute vcvarsall.bat (open visual studio Developer Command Prompt), see more details on #2977 (comment).

@epilys
Copy link
Contributor

epilys commented Aug 19, 2022

Closing this, I was able to create a hello world executable using master:

manos ~/wasmer % package/bin/wasmer create-exe ./tests/wasi-wast/wasi/snapshot1/hello.wasm -o hello
Compiler: cranelift
Target: aarch64-apple-darwin
Format: Symbols
Using libwasmer file: /Users/manos/wasmer/package/lib/libwasmer.a
Using path `/Users/manos/wasmer/package/lib/libwasmer.a` as libwasmer path.
✔ Native executable compiled successfully to `hello`.
manos ~/wasmer % ./hello
Hello, world!

@epilys epilys closed this as completed Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working create-exe 🍋 Low-hanging Fruit priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

6 participants