Skip to content

Commit ba9f9d1

Browse files
Port gitbook document to main (#4621)
* Import Gitbook v1.0 (#1732) Modify existing documents, add markdown files for Gitbook to generate the webpage
1 parent 3b8b265 commit ba9f9d1

File tree

38 files changed

+804
-1
lines changed

38 files changed

+804
-1
lines changed

SUMMARY.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Summary: structure of chapters and subchapters of the book
2+
3+
* [WAMR Document Home Page](gitbook/home_page.md)
4+
5+
## Basics
6+
7+
* [Introduction](gitbook/basics/introduction/README.md)
8+
* [WebAssembly](gitbook/basics/introduction/webassembly.md)
9+
* [WAMR Project](gitbook/basics/introduction/wamr_project.md)
10+
* [Security Feature](gitbook/basics/introduction/security_feature.md)
11+
12+
* [Getting Started](gitbook/basics/getting-started/README.md)
13+
* [Host Environment Preparation](gitbook/basics/getting-started/host_prerequsites.md)
14+
* [Hello-world Program On Host](gitbook/basics/getting-started/on_host.md)
15+
* [Docker Environment Preparation](doc/devcontainer.md)
16+
* [Hello-world Program On Docker](gitbook/basics/getting-started/on_docker.md)
17+
* [Build And Run WASM Application](doc/build_wasm_app.md)
18+
* [More Tools To Create WASM Application](doc/other_wasm_compilers.md)
19+
20+
## WAMR In Practice
21+
22+
* [Tutorial](gitbook/tutorial/README.md)
23+
* [WAMR Running Modes](gitbook/tutorial/running-modes/README.md)
24+
* [Build Tutorial](gitbook/tutorial/build-tutorial/README.md)
25+
* [Build iwasm](doc/build_wamr.md)
26+
* [Build wamrc](gitbook/tutorial/build-tutorial/build_wamrc.md)
27+
* [Language Embedding](gitbook/tutorial/language-embedding/README.md)
28+
* [C/C++](doc/embed_wamr.md)
29+
* [Python](language-bindings/python/README.md)
30+
* [Go](language-bindings/go/README.md)
31+
* [Debugging & IDE Support](gitbook/tutorial/debugging%26IDE-support/README.md)
32+
* [WAMR Source Debugging With LLDB](doc/source_debugging.md)
33+
* [VS Code Support](test-tools/wamr-ide/README.md)
34+
* [Enable Debugging In VS Code](test-tools/wamr-ide/VSCode-Extension/README.md)
35+
* [Move LLDB Binaries](test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md)
36+
37+
* [Advance Tutorial](gitbook/advance-tutorial/README.md)
38+
* [Performance Test](gitbook/advance-tutorial/performance-benchmark/README.md)
39+
* [PolyBench](tests/benchmarks/polybench/README.md)
40+
* [CoreMark](tests/benchmarks/coremark/README.md)
41+
* [Sightglass](tests/benchmarks/sightglass/README.md)
42+
* [JetStream2](tests/benchmarks/jetstream/README.md)
43+
* [Memory Usage Tunning](doc/memory_tune.md)
44+
* [WAMR Porting Guide](doc/port_wamr.md)
45+
46+
* [Features](gitbook/features/README.md)
47+
* [Export Native APIs To WASM Applications](doc/export_native_api.md)
48+
* [Example 1: Export C Functions to WASM](samples/basic/README.md)
49+
* [Example 2: Using "native-lib"](samples/native-lib/README.md)
50+
* [Multiple Modules As Dependencies](doc/multi_module.md)
51+
* [Multi-modules Example](samples/multi-module/README.md)
52+
* [Multi-thread, Pthread APIs And Thread Management](doc/pthread_library.md)
53+
* [Multi-thread Example](samples/multi-thread/README.md)
54+
* [Linux SGX(Intel Software Guard Extension) Support](doc/linux_sgx.md)
55+
* [Linux SGX Remote Attestation](samples/sgx-ra/README.md)
56+
* [XIP(Execution In Place) Support](doc/xip.md)
57+
* [Socket Support](doc/socket_api.md)
58+
* [Example: Use Socket Api in WAMR](samples/socket-api/README.md)
59+
* [Post-MVP Features](gitbook/features/demo-examples/README.md)
60+
* [WASM C API](samples/wasm-c-api/README.md)
61+
* [128-bit SIMD](samples/workload/README.md)
62+
* [Reference Types](samples/ref-types/README.md)
63+
64+
* [More Examples](gitbook/examples/README.md)
65+
* [File Interaction Of WASI](samples/file/README.md)
66+
* [Same WASM Program Executing Concurrently](samples/spawn-thread/README.md)
67+
* [Build And Run Workload](samples/workload/README.md)
68+
69+
* [User Case](gitbook/features/user-case/README.md)
70+
71+
## Programmer's Manual
72+
73+
* [Programmer's Manual](gitbook/programmer's-manual/README.md)
74+
* [C API Lists](gitbook/programmer's-manual/C_API_Lists.md)
75+
76+
## Community
77+
78+
* [How To Contribute](CONTRIBUTING.md)
79+
80+
* [WAMR On Github](https://github.com/bytecodealliance/wasm-micro-runtime)
81+
82+
* [WAMR Blogs](https://bytecodealliance.github.io/wamr.dev/)
83+
84+
## Appendix
85+
86+
* [Appendix A. Background Knowledge And Glossary Of Terms](gitbook/appendix/background_knowledge.md)
87+
88+
* [Appendix B. WebAssembly Details](gitbook/appendix/webassembly_details.md)
89+
90+
* [Appendix C. Complete WAMR Guide](README.md)

gitbook/advance-tutorial/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Advance tutorial
2+
3+
Welcome to the chapter of the advanced tutorial.
4+
5+
If you care about performance(don't we all?), want to know whether WAMR stands out among other wasm runtimes with respect to your demands, or wish to fine-tune your wasm application's memory footprint. You could refer to [this section](performance-benchmark/README.md)
6+
7+
In later sections, you can find the tutorial on how to use [application framework](../../doc/wamr_api.md) and [dynamic management](remote-applicatoin-management/README.md). Also, there is a tutorial on [how to port WAMR to the platform](../../doc/port_wamr.md)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Performance Test
2+
3+
Like word on the street said(no way it's just us saying!) or you may saw in previous chapters(maybe multiple times), WAMR is a **lightweight** standalone WebAssembly (WASM) runtime with **small footprint**, **high performance** and highly configurable features.
4+
5+
Well, you don't have to take our word for it. You could run the [Benchmarks in our repo](https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/tests/benchmarks) and decide whether the performance is good enough.
6+
7+
We provide multiple benchmarks that you could try:
8+
9+
- [PolyBench](../../../tests/benchmarks/polybench/README.md)
10+
- [CoreMark](../../../tests/benchmarks/coremark/README.md)
11+
- [Sightglass](../../../tests/benchmarks/sightglass/README.md)
12+
- [JetStream2](../../../tests/benchmarks/jetstream/README.md)
13+
14+
For the memory footprint, you can refer to the links below.
15+
16+
- [Performance and footprint data](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/Performance): checkout [here](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/Performance) for the performance and footprint data
17+
18+
And in the next section, we provide tutorials on memory usage tuning. You can [profile memory usage](../../../doc/build_wamr.md#enable-memory-profiling-experiment) and [tunning memory usage](../../../doc/memory_tune.md)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Remote application management
2+
3+
The WAMR application manager supports **remote application management**(check out local directory {WAMR-DIR}/core/app-mgr or [same directory on GitHub](https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/core/app-mgr) for more) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes.
4+
5+
The tool **host_tool** (check out local directory {WAMR-DIR}/test-tools/host-tool or [same directory on GitHub](https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/test-tools/host-tool) for more) communicates to the WAMR app manager for installing/uninstalling the wasm applications on the companion chip from the host system.
6+
7+
We have two example demos of the use of **host_tool**. One is the [simple example](../../../samples/simple/README.md) using the tool "host_tool" to remotely install/uninstall wasm applications from the WAMR runtime over either TCP socket or UART cable; the other is the [IoT App Store Demo](../../../test-tools/IoT-APP-Store-Demo/README.md) showing the concept of remotely managing the device applications from the cloud.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Some background knowledge
2+
3+
In this section, we aggregate some basic background knowledge and jargon in our project field. This section could be served as a refresher for those who have left academia for a while and cannot fully recall all the weary details and exact meaning of jargon in the Compiler course. Also, it would be a great primer for those who did not take such a course and are interested in such a field(and, of course, our fantastic WAMR project).
4+
5+
We think providing such a section would be nice so that you do not have to Google around. If there is anything you find inaccurate, you think should be included, or even better, you have something for us that would perfect this section, do feel free to reach out to us on [GitHub](https://github.com/bytecodealliance/wasm-micro-runtime)!
6+
7+
Let's dive right into our exciting recitation/learning journey without further ado!
8+
9+
## 1. Compiler
10+
11+
### 1.1 What is a Compiler?
12+
13+
Strictly speaking(formal definition you usually find in textbooks), the compiler is a special computer program, a system program(serves as a platform for other software), to be more precise. It takes a source program as input and outputs a target program. The source program is written in the source programming language, and usually, it is a high-level programming language such as C/C++, Java, Rust, and so on. The target program is written in a target programming language would be a low-level programming language like assembly. Take C/C++ as an example, the input for the GCC compiler(component) is a C/C++ translation unit(a source file along with any header it used), and the output is platform-dependent assembly code.
14+
15+
However, in our daily life, what we usually mean when we refer to the word compiler is the compiler toolchain, which comprises a compiler, assembler, and linker. The assembler is in charge of translating the compiled translation unit(object file) from assembly to truly machine-readable machine code. The linker is used to link all the parts of the program(object files) into one executable file. Together, they can translate our human-readable source code(potentially many files) into a program that can run on the machine.
16+
17+
For now, we will mainly focus on the more strict definition because I think the concept and algorithm compiler use more closely pertain to our WAMR project.
18+
19+
<!-- TODO: graph -->
20+
21+
### 1.2 Structure and algorithm involved
22+
23+
<!-- TODO: graph -->
24+
25+
Since we alright know what a compiler is, now let's learn more details about compilers. First, let's talk about the structure of the compiler and the algorithm related to each part. Typically, the compiler consists of three parts, Front End, Optimizer and Back End:
26+
27+
- Front End: in some sense, this part is more "mature." The theory involved and actual implementation is more or less stable nowadays. Its primary purpose is to gather textual information from source-language programs and understand it syntactically and semantically. After that, it encodes the knowledge it has into Intermediate Representation. The theory behind Front End is formal language theory(Scanners & Parsers) and lattice theory(Elaboration for type checking).
28+
29+
- Optimizer: as the name suggests, the Optimizer's goal is to optimize our program's performance. Clever readers may be conscious of the difficulty when they hear the word "optimize." Indeed, the Optimizer is very challenging to design and implement since it's a vital part of compiler infrastructure and imposes a heavy performance impact. It analyses the input IR and transforms it into definitive IR, usually through multiple passes, gradually accumulating knowledge of the program and applying a better(hopefully) transformation to it. The output(definitive IR) is semantically equivalent to the input IR to preserve the original meaning of the program we are compiling. The theories and algorithms that could be used for Optimizer are too many to list here. Here are examples: Number theory, some graph algorithms for static analysis, and fixed-point algorithms for data-flow analysis. It's still an active field that attracts many people to research.
30+
31+
- Back End: the Back End is in charge of mapping programs (in IR form) to low-level code forms that can run on the target machine. Usually, there is more than one Back End, so the compiler is portable for different platforms (ISA). Its main functionality includes instruction selection, register allocation, and instruction scheduling, in which many algorithms are applied, like heuristic search, graph coloring, and some dynamic programming. Like Optimizer, the Back End has many open problems to tackle and also is a field many people hold great interest in.
32+
33+
## 2. Interpreter
34+
35+
### 2.1 What is an Interpreter?
36+
37+
The Interpreter is also a system computer program. Like the compiler, it takes a source program as input; but instead of outputting a target program, it directly executes the program line by line and returns the corresponding results. One thing worth noting is that it's not uncommon for an interpreter to adapt widely used techniques in the compilers to improve its performance. Sometimes they are even used together.
38+
39+
Based on the levels of the source language(high or low) and compilation strategies, the interpreters can be divided into several different categories. Let's look at them in more detail in the following section.
40+
41+
### 2.2 Technique and jargon in Interpreter
42+
43+
- Bytecode:
44+
45+
The bytecode is a kind of low-level programming language in a very highly optimized and compact format. It could be the target language for the compiler. Because the instruction-like bytecode can be executed line by line in an interpreter on any platform, regardless of what hardware-related ISA it uses, it is also called p-code(portable). One example of bytecode you may be familiar with is Java bytecode.
46+
47+
- Ahead-of-time(AOT) and Just-in-time(JIT) compilation:
48+
49+
- AOT: as the name suggests, the AOT compilation means that the compilation happens before the program run time. Normally the target language after AOT compilation is some low-level machine code or bytecode. Then the compiled code can be executed by either a process VM or a normal computer.
50+
51+
- JIT: just in time compilation is a technique widely adopted by the Interpreter to improve its performance. It detects the heavily used code section when interpreting the program and compiles them into more efficient machine code. When that code section is called again, the machine code is executed rather than having the bytecode interpreted.
52+
53+
## 3. Virtual machines
54+
55+
When it comes to the word "Virtual Machines," we usually would remember or refer to that System virtual machines managed by hypervisors such as KVM, VirtualBox, or VMware. We often use them as a substitute for real computers to resolve dependency or compatibility issues for courses or daily work.
56+
57+
But there is also another type of virtual machine you may have heard of(even you may get really confused at first) and related more closely to the field where our project is. Process (application) virtual machines provide an environment independent of hardware, aiming to run computer programs written in a certain language. Take JVM as an example. It provides an environment for Java bytecode to execute across many platforms.
58+
59+
## 4. Runtime system
60+
61+
It's a rather vague term that is really difficult to explain or understand. To make things worse, when people sometimes refer to it as runtime, it's easily confused with compilation runtime, runtime library. The runtime system is an infrastructure that participates in the creation and running of our program. Typically, the components are the execution environment(Application VM maybe) to provide a place for the program to run, and the compiler front end or/and compiler back end to do the necessary analysis, transformation(from source code to bytecode), and optimization.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
description: "This page is under construction/refinement. p.s. wanna hear a construction joke? we are still working on it"
3+
---
4+
# WebAssembly details
5+
6+
Meanwhile, if you can't wait to learn more about Wasm, check out this book: _WebAssembly in Action_. It's a great book showcasing wasm basics and how to use wasm with JavaScript inside a browser.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Getting started: a hello world program
2+
3+
In this chapter, you'll learn how to run a simple hello world wasm program on your host or the Docker environment using WAMR. The docker tutorial is recommended so you don't have to worry about all the platform-related dependencies and compatibility problems. The hello world program will give you a taste of what our WAMR could do as server-side runtime and ready you for a more detailed guide at the end of this chapter. The [latter guide](../../../doc/build_wasm_app.md) covers the meaning of the compile and build option in detail and gives suggestions on fine-tuning your wasm module. More example programs can be found in [chapter 4. features](../../features/README.md)
4+
5+
Now, here is the last piece of gibberish before you get your hand dirty:
6+
7+
Clone our source code repo and use
8+
9+
```sh
10+
git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
11+
```
12+
13+
Or download from <https://github.com/bytecodealliance/wasm-micro-runtime> use any way you like
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Prerequisites for your host environment
2+
3+
## Ubuntu
4+
5+
First, install the needed packages and libraries.
6+
7+
```sh
8+
apt-get update \
9+
&& apt-get install -y apt-transport-https apt-utils build-essential \
10+
ca-certificates curl g++-multilib git gnupg \
11+
libgcc-9-dev lib32gcc-9-dev lsb-release \
12+
ninja-build ocaml ocamlbuild python2.7 \
13+
software-properties-common tree tzdata \
14+
unzip valgrind vim wget zip --no-install-recommends
15+
```
16+
17+
Then install CMake and wasi-sdk-16.0
18+
19+
```sh
20+
wget --progress=dot:giga -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg > /dev/null \
21+
&& echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | tee /etc/apt/sources.list.d/kitware.list >/dev/null \
22+
&& apt-get update \
23+
&& rm /usr/share/keyrings/kitware-archive-keyring.gpg \
24+
&& apt-get install -y kitware-archive-keyring --no-install-recommends \
25+
&& apt-get install -y cmake --no-install-recommends
26+
27+
wget -c --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/wasi-sdk-16.0-linux.tar.gz -P /opt \
28+
&& tar xf /opt/wasi-sdk-16.0-linux.tar.gz -C /opt \
29+
&& ln -fs /opt/wasi-sdk-16.0 /opt/wasi-sdk \
30+
&& rm /opt/wasi-sdk-16.0-linux.tar.gz
31+
```
32+
33+
This should be sufficient to build WAMR and run our hello world program.
34+
<!--
35+
TODO:
36+
37+
## MacOS
38+
39+
## Windows
40+
-->
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Using docker
2+
3+
Now that we have set up docker, we could run the following command directly in VS Code terminal(or the bash of your if you prefer ssh docker container directly).
4+
5+
Similarly, build iwasm vmcore.
6+
7+
```sh
8+
cd product-mini/platforms/linux
9+
mkdir build && cd build
10+
cmake ..
11+
make
12+
```
13+
14+
Then you are ready to go to the directory that contains the hello world program and copy our iwasm vmcore
15+
16+
```sh
17+
cp iwasm ../../../app-samples/hello-world
18+
cd ../../../app-samples/hello-world
19+
./build.sh
20+
```
21+
22+
Now you can execute your first wasm program!
23+
24+
```sh
25+
./iwasm test.wasm
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Compile, build and test hello world on the host
2+
3+
Now we have our host set up, we can build our hello world program and run it using WAMR.
4+
5+
First, build iwasm vmcore on your platform.
6+
7+
```sh
8+
cd ${WAMR-dir}/product-mini/platforms/${your platform}
9+
mkdir build && cd build
10+
cmake ..
11+
make
12+
```
13+
14+
Then you are ready to go to the directory that contains the hello world program and copy our iwasm vmcore
15+
16+
```sh
17+
cp iwasm ../../../app-samples/hello-world
18+
cd ${WAMR-dir}/product-mini/app-samples/hello-world
19+
./build.sh
20+
```
21+
22+
Now you could execute your first wasm program!
23+
24+
```sh
25+
./iwasm test.wasm
26+
```

0 commit comments

Comments
 (0)