Skip to content

Commit

Permalink
Initial Dockerfile (#97)
Browse files Browse the repository at this point in the history
* Initial Dockerfile

Dockerfile supports clang-8 and adds `iwasm` to `bin`.

* Updated README with Docker instructions

Added to Platform and app building section how to use the docker file to build the core and compile an app with clang.
  • Loading branch information
beriberikix authored and xwang98 committed Aug 14, 2019
1 parent 3f15fb3 commit 51ac31e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Currently supports clang-8 compiler
# Using the "test.c" app from the README.md:
# 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
# Pay attention to spacing above! ^
# iwasm test.wasm

FROM ubuntu:latest

RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential clang-8 cmake g++-multilib git lib32gcc-5-dev llvm-8 lld-8 nano

WORKDIR /root

RUN git clone https://github.com/intel/wasm-micro-runtime

RUN cd wasm-micro-runtime/core/iwasm/products/linux/ && mkdir build && \
cd build && cmake .. && make

RUN cd /usr/bin && ln -s wasm-ld-8 wasm-ld
RUN cd /usr/bin && ln -s ~/wasm-micro-runtime/core/iwasm/products/linux/build/iwasm iwasm
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ AliOS-Things
```
9. download the binary to developerkit board, check the output from serial port

Docker
-------------------------
[Docker](https://www.docker.com/) will download all the dependencies and build WAMR Core on your behalf.

Make sure you have Docker installed on your machine: [macOS](https://docs.docker.com/docker-for-mac/install/), [Windows](https://docs.docker.com/docker-for-windows/install/) or [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/).

Build the Docker image:

``` Bash
docker build --rm -f "Dockerfile" -t wamr:latest .
```
Run the image in interactive mode:
``` Bash
docker run --rm -it wamr:latest
```
You'll now enter the container at `/root`.

Build WASM app
=========================
You can write a simple ```test.c``` as the first sample.
Expand Down Expand Up @@ -181,7 +198,7 @@ int main(int argc, char **argv)
}
```
There are two methods to build a WASM binary. One is using Emscripten tool, another is using clang compiler.
There are three methods to build a WASM binary. They are Emscripten, the clang compiler and Docker.
## Use Emscripten tool
Expand Down Expand Up @@ -242,6 +259,19 @@ clang-8 --target=wasm32 -O3 -Wl,--initial-memory=131072,--allow-undefined,--expo

You will get ```test.wasm``` which is the WASM app binary.

## Using Docker

The last method availble is using [Docker](https://www.docker.com/). We assume you've already configured Docker (see Platform section above) and have a running interactive shell. Currently the Dockerfile only supports compiling apps with clang, with Emscripten planned for the future.

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
========================

Expand Down

0 comments on commit 51ac31e

Please sign in to comment.