Skip to content

Commit 9798468

Browse files
committed
Fixed commands for makefile update
1 parent 579796d commit 9798468

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

src/chapters/additional/makefile-wasm.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,47 @@
22

33
This tutorial assumes you have the
44
[rlbox_wasm2c_sandbox](https://github.com/PLSysSec/rlbox_wasm2c_sandbox/) git
5-
repo is in the path $(RLBOX_WASM2C_PATH), and you have installed
5+
repo is in the path $RLBOX_WASM2C_PATH, and you have installed
66
[wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases) on your computer in
7-
the path $(WASI_SDK_PATH)
7+
the path $WASI_SDK_PATH
88

99
Build the sources of your library along with the file
10-
`$(RLBOX_WASM2C_PATH)/c_src/wasm2c_sandbox_wrapper.c`. Pass the flags `-Wl,--export-all -Wl,--stack-first -Wl,-z,stack-size=262144 -Wl,--no-entry -Wl,--growable-table -Wl,--import-memory -Wl,--import-table`
10+
`$RLBOX_WASM2C_PATH/c_src/wasm2c_sandbox_wrapper.c`. Pass the flags `-Wl,--export-all -Wl,--stack-first -Wl,-z,stack-size=262144 -Wl,--no-entry -Wl,--growable-table -Wl,--import-memory -Wl,--import-table`
1111
to the linker using the wasi-clang compiler. This will produce a wasm module.
1212

1313
To edit an existing Make based build system, you can run the commmand.
1414

1515
```bash
16-
$(WASI_SDK_PATH)/bin/clang --sysroot $(WASI_SDK_PATH)/share/wasi-sysroot $(RLBOX_WASM2C_PATH)/c_src/wasm2c_sandbox_wrapper.c -c -o $(RLBOX_WASM2C_PATH)/c_src/wasm2c_sandbox_wrapper.o
17-
18-
AR=$(WASI_SDK_PATH)/bin/ar \
19-
CC=$(WASI_SDK_PATH)/bin/clang \
20-
CXX=$(WASI_SDK_PATH)/bin/clang++ \
21-
CFLAGS="--sysroot $(WASI_SDK_PATH)/share/wasi-sysroot" \
22-
LD=$(WASI_SDK_PATH)/bin/wasm-ld \
23-
LDLIBS=$(RLBOX_WASM2C_PATH)/c_src/wasm2c_sandbox_wrapper.o \
16+
$WASI_SDK_PATH/bin/clang --sysroot $WASI_SDK_PATH/share/wasi-sysroot $RLBOX_WASM2C_PATH/c_src/wasm2c_sandbox_wrapper.c -c -o $RLBOX_WASM2C_PATH/c_src/wasm2c_sandbox_wrapper.o
17+
18+
AR=$WASI_SDK_PATH/bin/ar \
19+
CC=$WASI_SDK_PATH/bin/clang \
20+
CXX=$WASI_SDK_PATH/bin/clang++ \
21+
CFLAGS="--sysroot $WASI_SDK_PATH/share/wasi-sysroot" \
22+
LD=$WASI_SDK_PATH/bin/wasm-ld \
23+
LDLIBS=$RLBOX_WASM2C_PATH/c_src/wasm2c_sandbox_wrapper.o \
2424
LDFLAGS="-Wl,--export-all -Wl,--stack-first -Wl,-z,stack-size=262144 -Wl,--no-entry -Wl,--growable-table -Wl,--import-memory -Wl,--import-table" \
2525
make
2626
```
27+
28+
If the Makefile you are modifying produces a binary executable, this will change it produce a Wasm executable instead and that should be it.
29+
30+
If the Makefile produces a static library (e.g., `mylib.a`) instead. You need
31+
one additional step to make it usable as a Wasm library that can be imported by
32+
rlbox.
33+
34+
First create a dummy main file somewhere called `dummy-main.c` consisting of
35+
36+
```c
37+
int main(int argc, char**argv){
38+
return 0;
39+
}
40+
```
41+
42+
Then you can run the following command
43+
44+
```bash
45+
$WASI_SDK_PATH/bin/clang --sysroot $WASI_SDK_PATH/share/wasi-sysroot -o mylib.wasm dummy-main.c -Wl,--whole-archive mylib.a -Wl,--no-whole-archive -Wl,--export-all
46+
```
47+
48+
This compiles a Wasm file with all symbols from the library included and exported.

0 commit comments

Comments
 (0)