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

Support aot compilation to native executable binary. #2977

Closed
liudonghua123 opened this issue Jun 27, 2022 · 4 comments
Closed

Support aot compilation to native executable binary. #2977

liudonghua123 opened this issue Jun 27, 2022 · 4 comments
Labels
🎉 enhancement New feature!

Comments

@liudonghua123
Copy link

Motivation

Like C/C++ porgrams, the output could be native executable binary which is more efficient.

Proposed solution

Build wasm file using aot method and then package with the runtime, and output platform specific native executable binary. When running the program, no runtime is needed.

Alternatives

Build all using aot method like C/C++ does.

Additional context

The dart language support both JIT and AOT compilation, maybe we can learn from it.

@liudonghua123 liudonghua123 added the 🎉 enhancement New feature! label Jun 27, 2022
@liudonghua123
Copy link
Author

@ptitSeb
Copy link
Contributor

ptitSeb commented Jun 27, 2022

Wasmer already use AoT (not JIT).
create-exe is disable for now on current master, as we are migrating to some new internal structure (it will return), but if you take last stable v2.3 it will be there.

Basicaly, what you ask is already there.

@liudonghua123
Copy link
Author

@ptitSeb Thanks, I tried create-exe on windows, after a few errors, I build a windows native binary succussed.

D:\code\rust\wasm>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

D:\code\rust\wasm>
# Need to install LLVM and add to the PATH
D:\code\rust\wasm>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: C code compile failed with: stdout:

       stderr: clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
       In file included from wasmer_main.c:1:
       C:\Users\Liu.D.H\.wasmer\include\wasmer.h:98:10: fatal error: 'stdlib.h' file not found
       #include <stdlib.h>
                ^~~~~~~~~~
       1 error generated.


# [STRANGE] The standard header file like `stdlib.h` is not included in LLVM,
# I have to invoke `vcvarsall.bat` of visual studio to provide some header files like `stdlib.h`
D:\code\rust\wasm>vs2022_64
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

D:\code\rust\wasm>wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
✔ Native executable compiled successfully to `hello.exe`.

D:\code\rust\wasm>

And I also tried to build on ubuntu linux using WSL2. It's quite easy than windows. And for a hello-world program, the binary size is about 9MB for windows and 23MB for linux. The build time is also great different, it is just 1 seconds on windows while almost 1 minutes on linux.

D:\code\rust\wasm>timeit wasmer create-exe hello.wasm -o hello.exe
Engine: staticlib
Compiler: cranelift
Target: x86_64-pc-windows-msvc
✔ Native executable compiled successfully to `hello.exe`.

Version Number:   Windows NT 6.2 (Build 9200)
Exit Time:        9:25 am, Tuesday, June 28 2022
Elapsed Time:     0:00:01.621
Process Time:     0:00:00.250
System Calls:     208743
Context Switches: 93009
Page Faults:      322436
Bytes Read:       71255776
Bytes Written:    2950589
Bytes Other:      387820

D:\code\rust\wasm>
D:\code\rust\wasm>dir hello.exe
 Volume in drive D is Programs
 Volume Serial Number is CEF0-10CA

 Directory of D:\code\rust\wasm

2022/06/28  09:25         9,440,768 hello.exe
               1 File(s)      9,440,768 bytes
               0 Dir(s)  425,444,306,944 bytes free

D:\code\rust\wasm>

liudonghua@DESKTOP-DELL:/mnt/d/code/rust/wasm$ time wasmer create-exe hello.wasm -o hello
Engine: staticlib
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
✔ Native executable compiled successfully to `hello`.

real    0m51.859s
user    0m5.682s
sys     0m10.895s
liudonghua@DESKTOP-DELL:/mnt/d/code/rust/wasm$ ll -lhS hello
-rwxrwxrwx 1 liudonghua liudonghua 23M Jun 28 09:28 hello*
liudonghua@DESKTOP-DELL:/mnt/d/code/rust/wasm$

@ptitSeb
Copy link
Contributor

ptitSeb commented Jun 28, 2022

Well, create-exe generate some files, and WSL2 has notable slow file access, especialy when using ntfs native filesystem. I guess that slow things down a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature!
Projects
None yet
Development

No branches or pull requests

3 participants