- https://www.osboxes.org/centos/ - Choose CentOS 6.9 - x86_64
- https://www.linuxvmimages.com/images/centos-6/
- /etc/yum.repos.d/* - replace base URL to
vault.centos.org
- yum update
- yum groupinstall 'Development Tools'
- curl http://linuxsoft.cern.ch/cern/scl/slc6-scl.repo > /etc/yum.repos.d/slc6-scl.repo
- /etc/yum.repos.d/slc6-scl.repo - replace
gpgcheck=1togpgcheck=0 - yum update
- yum install devtoolset-3
- scl enable devtoolset-3 bash
- yum install openssl-devel
- cd /usr/src
- wget https://github.com/Kitware/CMake/releases/download/v3.23.0-rc1/cmake-3.23.0-rc1.tar.gz
- tar xvfz cmake-3.23.0-rc1.tar.gz
- ./configure
- make
- make install
-
git clone https://github.com/bytecodealliance/wasm-micro-runtime
-
cd product-mini/platforms/linux/
-
Add
-lrtflag toCMakeList.txtset (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -lrt") -
Disable
-mindirect-branch-registerflag#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
cd product-mini/platforms/linux/
mkdir build
cd build
cmake .. -DWAMR_DISABLE_HW_BOUND_CHECK=1 -DWAMR_BUILD_REF_TYPES=1
make
See also: https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/build_wamr.md
$ ./iwasm
Usage: iwasm [-options] wasm_file [args...]
options:
-f|--function name Specify a function name of the module to run rather
than main
-v=n Set log verbose level (0 to 5, default is 2) larger
level with more log
--stack-size=n Set maximum stack size in bytes, default is 16 KB
--heap-size=n Set maximum heap size in bytes, default is 16 KB
--repl Start a very simple REPL (read-eval-print-loop) mode
that runs commands in the form of "FUNC ARG..."
--xip Enable XIP (Execution In Place) mode to run AOT file
generated with "--enable-indirect-mode" flag
--env=<env> Pass wasi environment variables with "key=value"
to the program, for example:
--env="key1=value1" --env="key2=value2"
--dir=<dir> Grant wasi access to the given host directories
to the program, for example:
--dir=<dir1> --dir=<dir2>
-
Download
wasi-sdk: https://github.com/WebAssembly/wasi-sdk/releases -
Create
test.cfile
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char *buf;
printf("Hello world!\n");
buf = malloc(1024);
if (!buf) {
printf("malloc buf failed\n");
return -1;
}
printf("buf ptr: %p\n", buf);
sprintf(buf, "%s", "1234\n");
printf("buf: %s", buf);
free(buf);
return 0;
}See also: https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/build_wasm_app.md
- Complile to
test.wasm
/opt/wasi-sdk/bin/clang -v test.c --sysroot=/opt/wasi-sdk/share/wasi-sysroot -o test.wasm
See also: WebAssembly/wasi-sdk#67
$ ./iwasm test.wasm
Hello world!
but ptr: 0x11500
buf: 1234