From f71be92b4dceed1c58b41e555c83b382b2b8eaab Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Feb 2024 16:30:50 +0900 Subject: [PATCH 01/16] ports/unix/Makefile: Don't assume Linux by default. Motivation: allow to override this with "make UNAME_S=wasi" Signed-off-by: YAMAMOTO Takashi --- ports/unix/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index d5bd6d4098..9a9df82629 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -103,7 +103,7 @@ CC = clang endif # Use clang syntax for map file LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip -else +else ifeq ($(UNAME_S),Linux) # Use gcc syntax for map file LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections endif From f43e62ac83d10374226eb29d0eee8a813ac8c569 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Feb 2024 16:35:28 +0900 Subject: [PATCH 02/16] ports/unix/unix_mphal.c: Disable signal mask stuff for WASI. WASI dosen't have signals. Signed-off-by: YAMAMOTO Takashi --- ports/unix/unix_mphal.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 5f5abc2e05..3ea3107d54 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -43,7 +43,13 @@ #endif #endif -#ifndef _WIN32 +#if defined(_WIN32) || defined(__wasi__) +#define HAS_SIGNAL 0 +#else +#define HAS_SIGNAL 1 +#endif + +#if HAS_SIGNAL != 0 #include static void sighandler(int signum) { @@ -75,7 +81,7 @@ static void sighandler(int signum) { void mp_hal_set_interrupt_char(char c) { // configure terminal settings to (not) let ctrl-C through if (c == CHAR_CTRL_C) { - #ifndef _WIN32 + #if HAS_SIGNAL != 0 // enable signal handler struct sigaction sa; sa.sa_flags = 0; @@ -84,7 +90,7 @@ void mp_hal_set_interrupt_char(char c) { sigaction(SIGINT, &sa, NULL); #endif } else { - #ifndef _WIN32 + #if HAS_SIGNAL != 0 // disable signal handler struct sigaction sa; sa.sa_flags = 0; From 4d078ad140aae57172dd770644438b45cea8838a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 15 Feb 2024 16:09:44 +0900 Subject: [PATCH 03/16] ports/unix: Add build-wasi.sh script. For now, mainly for documentation purpose. As you can see, this involves a lot of experimental things. Signed-off-by: YAMAMOTO Takashi --- ports/unix/build-wasi.sh | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 ports/unix/build-wasi.sh diff --git a/ports/unix/build-wasi.sh b/ports/unix/build-wasi.sh new file mode 100755 index 0000000000..1f7acb8d9a --- /dev/null +++ b/ports/unix/build-wasi.sh @@ -0,0 +1,70 @@ +#! /bin/sh + +# prerequisites +# +# https://github.com/WebAssembly/wasi-libc/pull/467 +# https://github.com/WebAssembly/wasi-libc/pull/473 +# https://github.com/WebAssembly/binaryen/pull/6294 +# https://github.com/WebAssembly/binaryen/pull/6259 +# +# WASI_SDK: wasi-sdk 21.0 +# WASM_OPT: binaryen wasm-opt built with the above patches +# WASI_SYSROOT: wasi-libc built with the above patches +# ../../../micropython-ulab: check out https://github.com/v923z/micropython-ulab + +WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-21.0} +WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot} +BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin} +WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt} + +# MICROPY_PY_THREAD: GC uses signals, which is not available on wasi. + +# the following things seem building well. i disabled them just because +# i was not intererested in them. +# MICROPY_VFS_FAT +# MICROPY_VFS_LFS1 +# MICROPY_VFS_LFS2 + +# micropython-ulab was added just as an example of user C module. +# you can remove it if you don't use it. + +CFLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -mllvm -wasm-enable-sjlj" \ +LDFLAGS="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman" \ +make \ +CC="${WASI_SDK}/bin/clang --sysroot=${WASI_SYSROOT}" \ +LD="${WASI_SDK}/bin/wasm-ld" \ +STRIP="${WASI_SDK}/bin/strip" \ +SIZE="${WASI_SDK}/bin/size" \ +UNAME_S=wasi \ +MICROPY_PY_FFI=0 \ +MICROPY_PY_THREAD=0 \ +MICROPY_PY_SOCKET=0 \ +MICROPY_PY_SSL=0 \ +MICROPY_PY_BTREE=0 \ +MICROPY_PY_TERMIOS=0 \ +MICROPY_USE_READLINE=0 \ +MICROPY_VFS_FAT=0 \ +MICROPY_VFS_LFS1=0 \ +MICROPY_VFS_LFS2=0 \ +USER_C_MODULES=../../../micropython-ulab \ +"$@" + +PROG=build-standard/micropython + +# We doesn't have a way to scan GC roots like WASM locals. +# Hopefully --spill-pointers can workaround it. +${WASM_OPT} \ +--spill-pointers \ +-o ${PROG}.spilled ${PROG} + +# LLVM still uses the older version of EH proposal. +# Convert to the latest version of EH proposal. +${WASM_OPT} \ +--translate-to-new-eh --enable-exception-handling \ +-o ${PROG}.spilled.neweh ${PROG}.spilled + +# now you can run it with EH-enabled runtimes. +# eg. (using the latest EH) +# toywasm --wasi build-standard/micropython.spilled.neweh +# eg. (using the old EH) +# iwasm build-standard/micropython.spilled From e44af7fdc9e4063d21730b8f7ba52b63c02b73ad Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:34:10 +0900 Subject: [PATCH 04/16] ports/unix: Add wasi VARIANT. Start from a copy of standard. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/manifest.py | 3 ++ ports/unix/variants/wasi/mpconfigvariant.h | 31 +++++++++++++++++++++ ports/unix/variants/wasi/mpconfigvariant.mk | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 ports/unix/variants/wasi/manifest.py create mode 100644 ports/unix/variants/wasi/mpconfigvariant.h create mode 100644 ports/unix/variants/wasi/mpconfigvariant.mk diff --git a/ports/unix/variants/wasi/manifest.py b/ports/unix/variants/wasi/manifest.py new file mode 100644 index 0000000000..d27bf3c47f --- /dev/null +++ b/ports/unix/variants/wasi/manifest.py @@ -0,0 +1,3 @@ +include("$(PORT_DIR)/variants/manifest.py") + +include("$(MPY_DIR)/extmod/asyncio") diff --git a/ports/unix/variants/wasi/mpconfigvariant.h b/ports/unix/variants/wasi/mpconfigvariant.h new file mode 100644 index 0000000000..75201e9abc --- /dev/null +++ b/ports/unix/variants/wasi/mpconfigvariant.h @@ -0,0 +1,31 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// Set base feature level. +#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) + +// Enable extra Unix features. +#include "../mpconfigvariant_common.h" diff --git a/ports/unix/variants/wasi/mpconfigvariant.mk b/ports/unix/variants/wasi/mpconfigvariant.mk new file mode 100644 index 0000000000..c91db1aa10 --- /dev/null +++ b/ports/unix/variants/wasi/mpconfigvariant.mk @@ -0,0 +1,3 @@ +# This is the default variant when you `make` the Unix port. + +FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py From 9ac61a51b6f4849389f522f80c7dedd8816163a8 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:35:39 +0900 Subject: [PATCH 05/16] ports/unix: Make MICROPY_PY_SELECT_POSIX_OPTIMISATIONS overridable. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/mpconfigvariant_common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 2e34055bf7..26508042d0 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -112,7 +112,9 @@ #endif // The "select" module is enabled by default, but disable select.select(). +#ifndef MICROPY_PY_SELECT_POSIX_OPTIMISATIONS #define MICROPY_PY_SELECT_POSIX_OPTIMISATIONS (1) +#endif #define MICROPY_PY_SELECT_SELECT (0) // Enable the "websocket" module. From f215714280a368a8c91bb6cff02a0529e6a2e833 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:38:31 +0900 Subject: [PATCH 06/16] ports/unix: Make MICROPY_PY_OS_SYSTEM overridable. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/mpconfigvariant_common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 26508042d0..5f709d3b51 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -96,7 +96,9 @@ #define MICROPY_PY_OS_ERRNO (1) #define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) #define MICROPY_PY_OS_SEP (1) +#ifndef MICROPY_PY_OS_SYSTEM #define MICROPY_PY_OS_SYSTEM (1) +#endif #define MICROPY_PY_OS_URANDOM (1) // Enable the unix-specific "time" module. From 53256773079be72daa52cf86930aed789f5f912a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:39:53 +0900 Subject: [PATCH 07/16] ports/unix/variants/wasi: Disable MICROPY_PY_SELECT_POSIX_OPTIMISATIONS. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/mpconfigvariant.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/unix/variants/wasi/mpconfigvariant.h b/ports/unix/variants/wasi/mpconfigvariant.h index 75201e9abc..e54ba42cf3 100644 --- a/ports/unix/variants/wasi/mpconfigvariant.h +++ b/ports/unix/variants/wasi/mpconfigvariant.h @@ -27,5 +27,8 @@ // Set base feature level. #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) +// WASI has different values for POLL constants. +#define MICROPY_PY_SELECT_POSIX_OPTIMISATIONS (0) + // Enable extra Unix features. #include "../mpconfigvariant_common.h" From b38ab04fcb791709e73029ce2a8c561eac286c8c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:41:37 +0900 Subject: [PATCH 08/16] ports/unix/variants/wasi: Disable MICROPY_PY_OS_SYSTEM. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/mpconfigvariant.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/unix/variants/wasi/mpconfigvariant.h b/ports/unix/variants/wasi/mpconfigvariant.h index e54ba42cf3..e09b3f8b58 100644 --- a/ports/unix/variants/wasi/mpconfigvariant.h +++ b/ports/unix/variants/wasi/mpconfigvariant.h @@ -30,5 +30,8 @@ // WASI has different values for POLL constants. #define MICROPY_PY_SELECT_POSIX_OPTIMISATIONS (0) +// WASI doesn't have executable or process. +#define MICROPY_PY_OS_SYSTEM (0) + // Enable extra Unix features. #include "../mpconfigvariant_common.h" From 7997321af4f448201f789fc33743fd62ad08d495 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:42:36 +0900 Subject: [PATCH 09/16] ports/unix/variants/wasi: Disable MICROPY_PY_SYS_EXECUTABLE. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/mpconfigvariant.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/unix/variants/wasi/mpconfigvariant.h b/ports/unix/variants/wasi/mpconfigvariant.h index e09b3f8b58..95d0a47fe8 100644 --- a/ports/unix/variants/wasi/mpconfigvariant.h +++ b/ports/unix/variants/wasi/mpconfigvariant.h @@ -32,6 +32,7 @@ // WASI doesn't have executable or process. #define MICROPY_PY_OS_SYSTEM (0) +#define MICROPY_PY_SYS_EXECUTABLE (0) // Enable extra Unix features. #include "../mpconfigvariant_common.h" From 8ff034289ae941e8732e350f40a54a1e305cc9da Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 17:46:05 +0900 Subject: [PATCH 10/16] ports/unix: Make MICROPY_PY_SYS_EXECUTABLE overridable. Signed-off-by: YAMAMOTO Takashi --- ports/unix/mpconfigport.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 1086baea06..3265ca84e8 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -155,7 +155,9 @@ typedef long mp_off_t; #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0) // Enable sys.executable. +#ifndef MICROPY_PY_SYS_EXECUTABLE #define MICROPY_PY_SYS_EXECUTABLE (1) +#endif #define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128) From 0b39e83570102f3df5592eb0dcf545ef69c9eecd Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 18:15:10 +0900 Subject: [PATCH 11/16] ports/unix/variants/wasi/mpconfigvariant.mk: Disable several things. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/mpconfigvariant.mk | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ports/unix/variants/wasi/mpconfigvariant.mk b/ports/unix/variants/wasi/mpconfigvariant.mk index c91db1aa10..b70151b9c4 100644 --- a/ports/unix/variants/wasi/mpconfigvariant.mk +++ b/ports/unix/variants/wasi/mpconfigvariant.mk @@ -1,3 +1,28 @@ # This is the default variant when you `make` the Unix port. FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py + +# WASI doesn't have FFI +MICROPY_PY_FFI=0 + +# When threading is enabled, micropython GC uses signals, which is +# not available on WASI. +MICROPY_PY_THREAD=0 + +# Disable for now because network support is limited in WASI. +MICROPY_PY_SOCKET=0 +MICROPY_PY_SSL=0 + +# ../../lib/berkeley-db-1.xx/PORT/include/db.h:40:10: +# fatal error: 'sys/cdefs.h' file not found +MICROPY_PY_BTREE=0 + +# WASI doesn't have termios +MICROPY_PY_TERMIOS=0 +MICROPY_USE_READLINE=0 + +# The following things might just work as they are. +# Disabled for now because I'm not interested in them. +MICROPY_VFS_FAT=0 +MICROPY_VFS_LFS1=0 +MICROPY_VFS_LFS2=0 From d4644a818e5c33e17522736f4ff7661e09c75b3f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 18:15:51 +0900 Subject: [PATCH 12/16] ports/unix/build-wasi.sh: Switch to use VARIANT. VARIANT=wasi. Also remove hardcoded ulab. Signed-off-by: YAMAMOTO Takashi --- ports/unix/build-wasi.sh | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/ports/unix/build-wasi.sh b/ports/unix/build-wasi.sh index 1f7acb8d9a..056846b394 100755 --- a/ports/unix/build-wasi.sh +++ b/ports/unix/build-wasi.sh @@ -10,24 +10,12 @@ # WASI_SDK: wasi-sdk 21.0 # WASM_OPT: binaryen wasm-opt built with the above patches # WASI_SYSROOT: wasi-libc built with the above patches -# ../../../micropython-ulab: check out https://github.com/v923z/micropython-ulab WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-21.0} WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot} BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin} WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt} -# MICROPY_PY_THREAD: GC uses signals, which is not available on wasi. - -# the following things seem building well. i disabled them just because -# i was not intererested in them. -# MICROPY_VFS_FAT -# MICROPY_VFS_LFS1 -# MICROPY_VFS_LFS2 - -# micropython-ulab was added just as an example of user C module. -# you can remove it if you don't use it. - CFLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -mllvm -wasm-enable-sjlj" \ LDFLAGS="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman" \ make \ @@ -36,20 +24,10 @@ LD="${WASI_SDK}/bin/wasm-ld" \ STRIP="${WASI_SDK}/bin/strip" \ SIZE="${WASI_SDK}/bin/size" \ UNAME_S=wasi \ -MICROPY_PY_FFI=0 \ -MICROPY_PY_THREAD=0 \ -MICROPY_PY_SOCKET=0 \ -MICROPY_PY_SSL=0 \ -MICROPY_PY_BTREE=0 \ -MICROPY_PY_TERMIOS=0 \ -MICROPY_USE_READLINE=0 \ -MICROPY_VFS_FAT=0 \ -MICROPY_VFS_LFS1=0 \ -MICROPY_VFS_LFS2=0 \ -USER_C_MODULES=../../../micropython-ulab \ +VARIANT=wasi \ "$@" -PROG=build-standard/micropython +PROG=build-wasi/micropython # We doesn't have a way to scan GC roots like WASM locals. # Hopefully --spill-pointers can workaround it. @@ -65,6 +43,6 @@ ${WASM_OPT} \ # now you can run it with EH-enabled runtimes. # eg. (using the latest EH) -# toywasm --wasi build-standard/micropython.spilled.neweh +# toywasm --wasi build-wasi/micropython.spilled.neweh # eg. (using the old EH) -# iwasm build-standard/micropython.spilled +# iwasm build-wasi/micropython.spilled From 7942515409075393746436b6019beb4027fff54d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Feb 2024 18:25:34 +0900 Subject: [PATCH 13/16] ports/unix/variants/wasi/mpconfigvariant.mk: Update a comment. Signed-off-by: YAMAMOTO Takashi --- ports/unix/variants/wasi/mpconfigvariant.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/unix/variants/wasi/mpconfigvariant.mk b/ports/unix/variants/wasi/mpconfigvariant.mk index b70151b9c4..c78d9cc15b 100644 --- a/ports/unix/variants/wasi/mpconfigvariant.mk +++ b/ports/unix/variants/wasi/mpconfigvariant.mk @@ -1,4 +1,4 @@ -# This is the default variant when you `make` the Unix port. +# Build for WASI FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py From 6bf0003cdba1e3f6d9e18f77b18ef2602c2f04a6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 2 Apr 2024 15:29:16 +0900 Subject: [PATCH 14/16] ports/unix/build-wasi.sh: Update toolchain patches. Signed-off-by: YAMAMOTO Takashi --- ports/unix/build-wasi.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ports/unix/build-wasi.sh b/ports/unix/build-wasi.sh index 056846b394..9a99fca3c9 100755 --- a/ports/unix/build-wasi.sh +++ b/ports/unix/build-wasi.sh @@ -2,24 +2,30 @@ # prerequisites # -# https://github.com/WebAssembly/wasi-libc/pull/467 -# https://github.com/WebAssembly/wasi-libc/pull/473 -# https://github.com/WebAssembly/binaryen/pull/6294 -# https://github.com/WebAssembly/binaryen/pull/6259 +# https://github.com/WebAssembly/wasi-libc/pull/483 (wasi-sdk 22.0?) +# https://github.com/WebAssembly/wasi-libc/pull/473 (wasi-sdk 22.0?) +# https://github.com/WebAssembly/binaryen/pull/6294 (version_117) +# https://github.com/WebAssembly/binaryen/pull/6259 (version_117) +# https://github.com/llvm/llvm-project/pull/84137 (LLVM 19?) # # WASI_SDK: wasi-sdk 21.0 # WASM_OPT: binaryen wasm-opt built with the above patches # WASI_SYSROOT: wasi-libc built with the above patches +# CLANG: clang built with the above patches WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-21.0} WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot} BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin} WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt} +RESOURCE_DIR=$(${WASI_SDK}/bin/clang --print-resource-dir) +LLVM_BUILD_DIR=${LLVM_BUILD_DIR:-/Volumes/PortableSSD/llvm/build} +CLANG=${CLANG:-${LLVM_BUILD_DIR}/bin/clang} +CC="${CLANG} --sysroot ${WASI_SYSROOT} -resource-dir ${RESOURCE_DIR}" CFLAGS="-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -mllvm -wasm-enable-sjlj" \ -LDFLAGS="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman" \ +LDFLAGS="-lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman -lsetjmp" \ make \ -CC="${WASI_SDK}/bin/clang --sysroot=${WASI_SYSROOT}" \ +CC="${CC}" \ LD="${WASI_SDK}/bin/wasm-ld" \ STRIP="${WASI_SDK}/bin/strip" \ SIZE="${WASI_SDK}/bin/size" \ From ab9cc991b121775660ca7323e8c9979d02147572 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 2 May 2024 15:31:11 +0900 Subject: [PATCH 15/16] ports/unix/build-wasi.sh: Update WASI-SDK. Signed-off-by: YAMAMOTO Takashi --- ports/unix/build-wasi.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/unix/build-wasi.sh b/ports/unix/build-wasi.sh index 9a99fca3c9..3846a4dabb 100755 --- a/ports/unix/build-wasi.sh +++ b/ports/unix/build-wasi.sh @@ -2,18 +2,18 @@ # prerequisites # -# https://github.com/WebAssembly/wasi-libc/pull/483 (wasi-sdk 22.0?) -# https://github.com/WebAssembly/wasi-libc/pull/473 (wasi-sdk 22.0?) +# https://github.com/WebAssembly/wasi-libc/pull/483 (wasi-sdk 22.0) +# https://github.com/WebAssembly/wasi-libc/pull/473 (wasi-sdk 22.0) # https://github.com/WebAssembly/binaryen/pull/6294 (version_117) # https://github.com/WebAssembly/binaryen/pull/6259 (version_117) # https://github.com/llvm/llvm-project/pull/84137 (LLVM 19?) # -# WASI_SDK: wasi-sdk 21.0 +# WASI_SDK: wasi-sdk 22.0 # WASM_OPT: binaryen wasm-opt built with the above patches # WASI_SYSROOT: wasi-libc built with the above patches # CLANG: clang built with the above patches -WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-21.0} +WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-22.0} WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot} BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin} WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt} From b070ffc590bf5019013942ee802ad2de7839140e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 2 May 2024 15:59:53 +0900 Subject: [PATCH 16/16] ports/unix/build-wasi.sh: Use wasi-libc from wasi-sdk. Also, update comments. Signed-off-by: YAMAMOTO Takashi --- ports/unix/build-wasi.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/unix/build-wasi.sh b/ports/unix/build-wasi.sh index 3846a4dabb..36f3f399c8 100755 --- a/ports/unix/build-wasi.sh +++ b/ports/unix/build-wasi.sh @@ -8,13 +8,13 @@ # https://github.com/WebAssembly/binaryen/pull/6259 (version_117) # https://github.com/llvm/llvm-project/pull/84137 (LLVM 19?) # -# WASI_SDK: wasi-sdk 22.0 -# WASM_OPT: binaryen wasm-opt built with the above patches -# WASI_SYSROOT: wasi-libc built with the above patches -# CLANG: clang built with the above patches +# WASI_SDK: wasi-sdk 22.0 or later +# WASM_OPT: binaryen wasm-opt version_117 or later +# WASI_SYSROOT: sysroot from wasi-sdk 22.0 or later +# CLANG: clang from LLVM 19 or later, which contains the above mentioned PR WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-22.0} -WASI_SYSROOT=${WASI_SYSROOT:-${HOME}/git/wasi-libc/sysroot} +WASI_SYSROOT=${WASI_SYSROOT:-${WASI_SDK}/share/wasi-sysroot} BINARYEN_BIN=${BINARYEN_BIN:-${HOME}/git/wasm/binaryen/b/bin} WASM_OPT=${WASM_OPT:-${BINARYEN_BIN}/wasm-opt} RESOURCE_DIR=$(${WASI_SDK}/bin/clang --print-resource-dir)