From 4456ff89d876c64f3f71a0c2a41f0974074af369 Mon Sep 17 00:00:00 2001 From: aaltonenzhang Date: Tue, 4 Jun 2019 10:34:46 +0800 Subject: [PATCH 1/2] add guide to build hello world sample using clang-8 in README. (#37) --- README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2e85545277..e238165956 100644 --- a/README.md +++ b/README.md @@ -122,18 +122,9 @@ AliOS-Things Build WASM app ========================= -A popular method to build a WASM binary is to use ```emcc```. -Assuming you are using Linux, you may install emcc from Emscripten EMSDK following the steps below: -``` -git clone https://github.com/emscripten-core/emsdk.git -emsdk install latest -emsdk activate latest -``` -source ```./emsdk_env.sh```. -The Emscripten website provides other installation methods beyond Linux. - You can write a simple ```test.c``` as the first sample. -``` C + +```C #include #include @@ -158,6 +149,22 @@ int main(int argc, char **argv) return 0; } ``` + +There are two methods to build a WASM binary. One is using Emscripten tool, another is using clang compiler. + +## Use Emscripten tool + +A method to build a WASM binary is to use Emscripten tool ```emcc```. +Assuming you are using Linux, you may install emcc from Emscripten EMSDK following the steps below: + +``` +git clone https://github.com/emscripten-core/emsdk.git +emsdk install latest +emsdk activate latest +``` +source ```./emsdk_env.sh```. +The Emscripten website provides other installation methods beyond Linux. + Use the emcc command below to build the WASM C source code into the WASM binary. ``` Bash emcc -g -O3 *.c -s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHECK=2 \ @@ -165,8 +172,48 @@ emcc -g -O3 *.c -s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHE ``` You will get ```test.wasm``` which is the WASM app binary. +## Use clang compiler + +Another method to build a WASM binary is to use clang compiler```clang-8```. + +Add source to your system source list from llvm website, for ubuntu16.04, add following lines to /etc/apt/sources.list: + +```Bash +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main # 7 +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main # 8 +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main +``` + +Download and install clang-8 tool-chain using following commands: + +```Bash +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - +sudo apt-get update +sudo apt-get install llvm-8 lld-8 clang-8 +``` + +Create a soft link under /usr/bin: + +```Bash +cd /usr/bin +sudo ln -s wasm-ld-8 wasm-ld +``` + +Use the clang-8 command below to build the WASM C source code into the WASM binary. + +```Bash +clang-8 --target=wasm32 -O3 -Wl,--initial-memory=131072,--allow-undefined,--export=main, +--no-threads,--strip-all,--no-entry -nostdlib -o test.wasm test.c +``` + +You will get ```test.wasm``` which is the WASM app binary. + Run WASM app ======================== + Assume you are using Linux, the command to run the test.wasm is: ``` Bash cd iwasm/products/linux/bin From 20768d6b8eb5add0d15281569925d18306856c06 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 8 Jun 2019 03:37:44 -0700 Subject: [PATCH 2/2] Add Fedora dependency installation instructions (#38) --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e238165956..fed5aa90a0 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,13 @@ Linux First of all please install library dependencies of lib gcc. Use installation commands below for Ubuntu Linux: ``` Bash -sudo apt install lib32gcc-5-dev -sudo apt-get install g++-multilib +sudo apt install lib32gcc-5-dev g++-multilib ``` +Or in Fedora: +``` Bash +sudo dnf install glibc-devel.i686 +``` + After installing dependencies, build the source code: ``` Bash cd core/iwasm/products/linux/