-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Exprimental WASI support for ports/unix #13676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2b45ae2
194e015
d26e552
3ff3f3d
355f987
6f0f91d
9822893
cb11272
f50795d
7a88583
7374363
ab17034
70bf523
9b549c3
e2274d7
8509cba
7a7f6ec
5ab604d
437a392
7015fc5
9df64d0
5f409b2
9e05cf3
fad3b13
a984524
8e3e536
5098523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#! /bin/sh | ||
|
||
# prerequisites | ||
# | ||
# WASI_SDK: wasi-sdk 25.0 or later | ||
# WASM_OPT: binaryen wasm-opt version_117 or later | ||
|
||
# Note: | ||
# we specify the target "--target=wasm32-wasi" explicitly below for the case | ||
# where $CLANG is built with a configuration different from wasi-sdk. | ||
# ditto for "-B ${WASI_SDK}/bin/". | ||
|
||
set -e | ||
|
||
WASI_SDK=${WASI_SDK:-/opt/wasi-sdk-25.0} | ||
WASI_SYSROOT=${WASI_SYSROOT:-${WASI_SDK}/share/wasi-sysroot} | ||
WASM_OPT=${WASM_OPT:-wasm-opt} | ||
RESOURCE_DIR=$(${WASI_SDK}/bin/clang --print-resource-dir) | ||
LLVM_DIR=${LLVM_DIR:-${WASI_SDK}} | ||
CLANG=${CLANG:-${LLVM_DIR}/bin/clang} | ||
CC="${CLANG} --sysroot ${WASI_SYSROOT} -resource-dir ${RESOURCE_DIR}" | ||
|
||
CFLAGS="--target=wasm32-wasi -D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -mllvm -wasm-enable-sjlj" \ | ||
LDFLAGS="--target=wasm32-wasi -lwasi-emulated-process-clocks -lwasi-emulated-signal -lwasi-emulated-mman -lsetjmp -B ${WASI_SDK}/bin/" \ | ||
make \ | ||
CC="${CC}" \ | ||
STRIP="${WASI_SDK}/bin/strip" \ | ||
SIZE="${WASI_SDK}/bin/size" \ | ||
UNAME_S=wasi \ | ||
VARIANT=wasi \ | ||
"$@" | ||
|
||
PROG=build-wasi/micropython | ||
|
||
# Unlike emscripten, WASI doesn't provide 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. ("phase 3") | ||
# Convert to the latest version of EH proposal with exnref. | ||
${WASM_OPT} \ | ||
--translate-to-exnref --enable-exception-handling \ | ||
-o ${PROG}.spilled.exnref ${PROG}.spilled | ||
|
||
cat <<EOF | ||
Built successfully. | ||
|
||
Now you can run it with EH-enabled runtimes. | ||
eg. (using the latest EH) | ||
toywasm --wasi build-wasi/micropython.spilled.exnref | ||
eg. (using the old EH) | ||
iwasm build-wasi/micropython.spilled | ||
EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
#include <signal.h> | ||
|
||
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# include("$(PORT_DIR)/variants/manifest.py") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this file only has comments can it just be omitted? |
||
|
||
# include("$(MPY_DIR)/extmod/asyncio") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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) | ||
|
||
// 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) | ||
#define MICROPY_PY_SYS_EXECUTABLE (0) | ||
|
||
#define MICROPY_PY_WEBSOCKET (0) | ||
|
||
// Enable extra Unix features. | ||
#include "../mpconfigvariant_common.h" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Build for WASI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo not needed to state the obvious., |
||
|
||
FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py | ||
|
||
# WASI doesn't have FFI | ||
MICROPY_PY_FFI=0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have whitespace around the |
||
|
||
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try this with e.g. long-running scripts?