-
Notifications
You must be signed in to change notification settings - Fork 825
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
Comments
I found something useful on #1729 (comment), https://docs.wasmer.io/ecosystem/wasmer/usage#wasmer-create-exe. |
Wasmer already use AoT (not JIT). Basicaly, what you ask is already there. |
@ptitSeb Thanks, I tried 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 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$ |
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. |
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.
The text was updated successfully, but these errors were encountered: