Skip to content

Commit 443bcd2

Browse files
committed
ports/unix: Add build-wasi.sh script.
For now, mainly for documentation purpose. As you can see, this involves a lot of experimental things.
1 parent 46233b8 commit 443bcd2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

ports/unix/build-wasi.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#! /bin/sh
2+
3+
# prerequisites
4+
#
5+
# https://github.com/WebAssembly/wasi-libc/pull/467
6+
# https://github.com/WebAssembly/wasi-libc/pull/473
7+
# https://github.com/WebAssembly/binaryen/pull/6294
8+
# https://github.com/WebAssembly/binaryen/pull/6259
9+
#
10+
# WASI_SDK: wasi-sdk 21.0
11+
# WASM_OPT: binaryen wasm-opt built with the above patches
12+
# WASI_SYSROOT: wasi-libc built with the above patches
13+
# ../../../micropython-ulab: check out https://github.com/v923z/micropython-ulab
14+
15+
WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-21.0}
16+
WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot}
17+
BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin}
18+
WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt}
19+
20+
# MICROPY_PY_THREAD: GC uses signals, which is not available on wasi.
21+
22+
# the following things seem building well. i disabled them just because
23+
# i was not intererested in them.
24+
# MICROPY_VFS_FAT
25+
# MICROPY_VFS_LFS1
26+
# MICROPY_VFS_LFS2
27+
28+
# micropython-ulab was added just as an example of user C module.
29+
# you can remove it if you don't use it.
30+
31+
CFLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -mllvm -wasm-enable-sjlj" \
32+
LDFLAGS="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman" \
33+
make \
34+
CC="${WASI_SDK}/bin/clang --sysroot=${WASI_SYSROOT}" \
35+
LD="${WASI_SDK}/bin/wasm-ld" \
36+
STRIP="${WASI_SDK}/bin/strip" \
37+
SIZE="${WASI_SDK}/bin/size" \
38+
UNAME_S=wasi \
39+
MICROPY_PY_FFI=0 \
40+
MICROPY_PY_THREAD=0 \
41+
MICROPY_PY_SOCKET=0 \
42+
MICROPY_PY_SSL=0 \
43+
MICROPY_PY_BTREE=0 \
44+
MICROPY_PY_TERMIOS=0 \
45+
MICROPY_USE_READLINE=0 \
46+
MICROPY_VFS_FAT=0 \
47+
MICROPY_VFS_LFS1=0 \
48+
MICROPY_VFS_LFS2=0 \
49+
USER_C_MODULES=../../../micropython-ulab \
50+
"$@"
51+
52+
PROG=build-standard/micropython
53+
54+
# We doesn't have a way to scan GC roots like WASM locals.
55+
# Hopefully --spill-pointers can workaround it.
56+
${WASM_OPT} \
57+
--spill-pointers \
58+
-o ${PROG}.spilled ${PROG}
59+
60+
# LLVM still uses the older version of EH proposal.
61+
# Convert to the latest version of EH proposal.
62+
${WASM_OPT} \
63+
--translate-to-new-eh --enable-exception-handling \
64+
-o ${PROG}.spilled.neweh ${PROG}.spilled
65+
66+
# now you can run it with EH-enabled runtimes.
67+
# eg. (using the latest EH)
68+
# toywasm --wasi build-standard/micropython.spilled.neweh
69+
# eg. (using the old EH)
70+
# iwasm build-standard/micropython.spilled

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy