From eb7cf42710f77328c62096a0583c8bb88d8ab583 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Mon, 14 Sep 2020 11:31:50 +0000 Subject: [PATCH 01/19] Faasm configuration --- config.site | 8 ++++++++ config.sub | 4 +++- configure | 6 ++++++ configure.ac | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 config.site diff --git a/config.site b/config.site new file mode 100644 index 00000000000000..a73573be5d50c7 --- /dev/null +++ b/config.site @@ -0,0 +1,8 @@ +ac_cv_file__dev_ptmx=no +ac_cv_file__dev_ptc=no +ac_cv_func_dlopen=yes +ac_cv_lib_socket_socket=no +ac_cv_header_linux_vm_sockets_h=yes +ac_cv_little_endian_double=yes +ax_cv_c_float_words_bigendian=no + diff --git a/config.sub b/config.sub index ba37cf99e26b9d..289051b4e2e0f2 100755 --- a/config.sub +++ b/config.sub @@ -118,7 +118,7 @@ case $maybe_os in linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ kopensolaris*-gnu* | cloudabi*-eabi* | \ - storm-chaos* | os2-emx* | rtmk-nova*) + storm-chaos* | os2-emx* | rtmk-nova* | wasi ) os=-$maybe_os basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -1524,6 +1524,8 @@ case $os in ;; -nacl*) ;; + -wasi*) + ;; -ios) ;; -none) diff --git a/configure b/configure index a979363acffc41..db10414f5133cf 100755 --- a/configure +++ b/configure @@ -3274,6 +3274,9 @@ then *-*-vxworks*) ac_sys_system=VxWorks ;; + *-*-wasi*) + ac_sys_system=Wasi + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -3324,6 +3327,9 @@ if test "$cross_compiling" = yes; then *-*-vxworks*) _host_cpu=$host_cpu ;; + *-*-wasi*) + _host_cpu= + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" diff --git a/configure.ac b/configure.ac index e57ef7c38bf7f3..5f217bc0f18325 100644 --- a/configure.ac +++ b/configure.ac @@ -382,6 +382,9 @@ then *-*-vxworks*) ac_sys_system=VxWorks ;; + *-*-wasi*) + ac_sys_system=Wasi + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -431,6 +434,9 @@ if test "$cross_compiling" = yes; then *-*-vxworks*) _host_cpu=$host_cpu ;; + *-*-wasi*) + _host_cpu= + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" From 97546f0516ec7bcfce7e6847ed3794bd1cf986e2 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Mon, 14 Sep 2020 14:04:22 +0000 Subject: [PATCH 02/19] Extra undefines --- pyconfig-extra.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pyconfig-extra.h diff --git a/pyconfig-extra.h b/pyconfig-extra.h new file mode 100644 index 00000000000000..30a447bf67f689 --- /dev/null +++ b/pyconfig-extra.h @@ -0,0 +1,26 @@ +/* + * NOTE: The following definitions are copied into place + * _in addition_ to the rest of the file which is auto-generated. + * + * They are here to explicitly switch off or override certain + * auto-detected features, or to avoid compilation bugs. + */ + +#ifndef Py_PYCONFIG_EXTRAS_H +#define Py_PYCONFIG_EXTRAS_H + +#undef HAVE_MKNOD +#undef HAVE_DEVICE_MACROS + +#undef HAVE_EPOLL +#undef HAVE_EPOLL_CREATE1 +#undef HAVE_LINUX_VM_SOCKETS_H +#undef HAVE_SOCKETPAIR +#undef HAVE_UTIMENSAT +#undef HAVE_SIGACTION + +#define CONFIG_32 +#define ANSI + +#endif + From eeb920f7ebe22e53c4fab88bbb456f94b46b502c Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Mon, 14 Sep 2020 15:11:56 +0000 Subject: [PATCH 03/19] Exclude install dir --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b662374b1255cb..ad71b9448faeeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Faasm-specific +install/ + ##### # First, rules intended to apply in all subdirectories. # These contain no slash, or only a trailing slash. From 0fe2902cca791a81b12a3d9e50607712e9552eae Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 17 Sep 2020 13:06:15 +0000 Subject: [PATCH 04/19] Setup.local for modules --- .gitignore | 2 +- Modules/Setup.local | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Modules/Setup.local diff --git a/.gitignore b/.gitignore index ad71b9448faeeb..f07e9699eb0ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,7 @@ Misc/python.pc Misc/python-embed.pc Misc/python-config.sh Modules/Setup.config -Modules/Setup.local +#Modules/Setup.local Modules/config.c Modules/ld_so_aix Programs/_freeze_importlib diff --git a/Modules/Setup.local b/Modules/Setup.local new file mode 100644 index 00000000000000..5db30f8797642b --- /dev/null +++ b/Modules/Setup.local @@ -0,0 +1,42 @@ +# This file is used to configure how CPython builtins get built. +# +# It's based on Modules/Setup + +# To build all modules statically, we put this line near the top +# (see https://wiki.python.org/moin/BuildStatically) +*static* + +posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls +errno errnomodule.c # posix (UNIX) errno values +pwd pwdmodule.c # this is needed to find out the user's home dir + # if $HOME is not set +_sre _sre.c # Fredrik Lundh's new regular expressions +_codecs _codecsmodule.c # access to the builtin codecs and codec registry +_weakref _weakref.c # weak references +_abc _abc.c # Abstract base classes +_stat _stat.c # stat.h interface +_thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c # low-level threading interface + +# access to ISO C locale support +_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl + +array arraymodule.c # array objects +cmath cmathmodule.c _math.c # -lm # complex math library functions +math mathmodule.c _math.c # -lm # math library functions, e.g. sin() +_contextvars _contextvarsmodule.c # Context Variables +_struct _struct.c # binary structure packing/unpacking +_weakref _weakref.c # basic weak reference support +_random _randommodule.c # Random number generator +#_pickle _pickle.c # pickle accelerator +_datetime _datetimemodule.c # datetime accelerator +_bisect _bisectmodule.c # Bisection algorithms +_heapq _heapqmodule.c # Heap queue algorithm +_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups +_statistics _statisticsmodule.c # statistics accelerator + +# Disable things we definitely don't need + +*disabled* + +_sqlite3 _tkinter _curses pyexpat +_codecs_jp _codecs_kr _codecs_tw unicodedata From 90f434ed6378556f483af29a694ac29f7f124968 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Mon, 21 Sep 2020 16:43:12 +0000 Subject: [PATCH 05/19] Added decimal module to static build --- Modules/Setup.local | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/Setup.local b/Modules/Setup.local index 5db30f8797642b..8c59b3434ac4e1 100644 --- a/Modules/Setup.local +++ b/Modules/Setup.local @@ -34,6 +34,9 @@ _heapq _heapqmodule.c # Heap queue algorithm _json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups _statistics _statisticsmodule.c # statistics accelerator +# decimal module - sources derived from setup.py detect_decimal() +_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -I$(srcdir)/Modules/_decimal/libmpdec + # Disable things we definitely don't need *disabled* From 48d02af2bb21769f2e0820006037a88fea652fa2 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 24 Sep 2020 10:27:11 +0000 Subject: [PATCH 06/19] Attempt to switch off long doubles --- pyconfig-extra.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyconfig-extra.h b/pyconfig-extra.h index 30a447bf67f689..8bbcd2531b4e5a 100644 --- a/pyconfig-extra.h +++ b/pyconfig-extra.h @@ -12,6 +12,8 @@ #undef HAVE_MKNOD #undef HAVE_DEVICE_MACROS +#undef HAVE_LONG_DOUBLE + #undef HAVE_EPOLL #undef HAVE_EPOLL_CREATE1 #undef HAVE_LINUX_VM_SOCKETS_H From 289cb975d31f1b9ebfdadf8150e196019440ac43 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 24 Sep 2020 11:08:03 +0000 Subject: [PATCH 07/19] Reverted long double removal --- pyconfig-extra.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyconfig-extra.h b/pyconfig-extra.h index 8bbcd2531b4e5a..30a447bf67f689 100644 --- a/pyconfig-extra.h +++ b/pyconfig-extra.h @@ -12,8 +12,6 @@ #undef HAVE_MKNOD #undef HAVE_DEVICE_MACROS -#undef HAVE_LONG_DOUBLE - #undef HAVE_EPOLL #undef HAVE_EPOLL_CREATE1 #undef HAVE_LINUX_VM_SOCKETS_H From 7c887a721b3cce5a18e6967de55b7cd9ea357c5a Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 24 Sep 2020 16:37:49 +0000 Subject: [PATCH 08/19] Remove ANSI definition --- pyconfig-extra.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyconfig-extra.h b/pyconfig-extra.h index 30a447bf67f689..b70be2f1719d9e 100644 --- a/pyconfig-extra.h +++ b/pyconfig-extra.h @@ -9,6 +9,7 @@ #ifndef Py_PYCONFIG_EXTRAS_H #define Py_PYCONFIG_EXTRAS_H +// Switch off some features we know we don't need #undef HAVE_MKNOD #undef HAVE_DEVICE_MACROS @@ -19,8 +20,8 @@ #undef HAVE_UTIMENSAT #undef HAVE_SIGACTION +// 32-bit #define CONFIG_32 -#define ANSI #endif From f51a124bc5c4b4b6623bd9421f9d628cd3b58afa Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Wed, 16 Dec 2020 13:52:07 +0000 Subject: [PATCH 09/19] Merge changes from https://github.com/python/cpython/pull/20451/ --- Makefile.pre.in | 1 + configure | 3 +++ configure.ac | 3 +++ setup.py | 8 +++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index a914a9c70f6794..8f972ea2f7e0fe 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -291,6 +291,7 @@ IO_OBJS= \ ########################################################################## LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@ +LIBFFI_LIBDIR= @LIBFFI_LIBDIR@ ########################################################################## # Parser diff --git a/configure b/configure index db10414f5133cf..117da4a8ded348 100755 --- a/configure +++ b/configure @@ -654,6 +654,7 @@ DTRACE TCLTK_LIBS TCLTK_INCLUDES LIBFFI_INCLUDEDIR +LIBFFI_LIBDIR PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG @@ -10405,8 +10406,10 @@ fi if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" + LIBFFI_LIBDIR="`"$PKG_CONFIG" libffi --libs-only-L 2>/dev/null | sed -e 's/^-L//;s/ *$//'`" else LIBFFI_INCLUDEDIR="" + LIBFFI_LIBDIR="" fi diff --git a/configure.ac b/configure.ac index 5f217bc0f18325..a93e64af1e1fe0 100644 --- a/configure.ac +++ b/configure.ac @@ -2996,10 +2996,13 @@ fi if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" + LIBFFI_LIBDIR="`"$PKG_CONFIG" libffi --libs-only-L 2>/dev/null | sed -e 's/^-L//;s/ *$//'`" else LIBFFI_INCLUDEDIR="" + LIBFFI_LIBDIR="" fi AC_SUBST(LIBFFI_INCLUDEDIR) +AC_SUBST(LIBFFI_LIBDIR) # Check for use of the system libmpdec library AC_MSG_CHECKING(for --with-system-libmpdec) diff --git a/setup.py b/setup.py index 20d7f35652fe50..fa4389006b2169 100644 --- a/setup.py +++ b/setup.py @@ -2056,15 +2056,21 @@ def detect_ctypes(self): ffi_inc = None print('Header file {} does not exist'.format(ffi_h)) ffi_lib = None + ffi_libdir = [sysconfig.get_config_var("LIBFFI_LIBDIR")] + ffi_libdir = [d for d in ffi_libdir if os.path.isdir(d)] if ffi_inc is not None: for lib_name in ('ffi', 'ffi_pic'): - if (self.compiler.find_library_file(self.lib_dirs, lib_name)): + fullpath = self.compiler.find_library_file(self.lib_dirs + ffi_libdir, lib_name) + if fullpath: ffi_lib = lib_name + ffi_libdir = os.path.normpath(os.path.dirname(fullpath)) break if ffi_inc and ffi_lib: ext.include_dirs.extend(ffi_inc) ext.libraries.append(ffi_lib) + if ffi_libdir not in self.lib_dirs: + ext.library_dirs.append(ffi_libdir) self.use_system_libffi = True if sysconfig.get_config_var('HAVE_LIBDL'): From 0a1d1d25dbc7f5cdd71e5b6eb6d9a99292089b49 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Wed, 16 Dec 2020 17:04:46 +0000 Subject: [PATCH 10/19] Hack for Faasm libffi --- configure | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 117da4a8ded348..a58778443a4010 100755 --- a/configure +++ b/configure @@ -10404,7 +10404,11 @@ $as_echo "$as_me: WARNING: --with(out)-system-ffi is ignored on this platform" > with_system_ffi="yes" fi -if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then +# Hack for Faasm build, will probably break otherwise +if test "$with_system_ffi"; then + LIBFFI_INCLUDEDIR="/usr/local/faasm/llvm-sysroot/include/" + LIBFFI_LIBDIR="/usr/local/faasm/llvm-sysroot/lib/wasm32-wasi/" +elif test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" LIBFFI_LIBDIR="`"$PKG_CONFIG" libffi --libs-only-L 2>/dev/null | sed -e 's/^-L//;s/ *$//'`" else From 0d1b29750f3c735b65b0df220904c2c0c22ddd8d Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Tue, 5 Jan 2021 08:06:36 +0000 Subject: [PATCH 11/19] Shortcut ctypes cache reset in wasm --- Lib/ctypes/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 8f0991147d72f2..c92799cf5aa4b3 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -259,6 +259,11 @@ class c_wchar(_SimpleCData): _type_ = "u" def _reset_cache(): + # Skip this in wasm + py_wasm = _os.getenv("PYTHONWASM", "NOT SET") + if py_wasm == "1": + return + _pointer_type_cache.clear() _c_functype_cache.clear() if _os.name == "nt": From a16f999a8ebf35ad68ff85556b3006b995e466a8 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Tue, 5 Jan 2021 16:52:00 +0000 Subject: [PATCH 12/19] Remove dodging the issue with ctypes --- Lib/ctypes/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index c92799cf5aa4b3..8f0991147d72f2 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -259,11 +259,6 @@ class c_wchar(_SimpleCData): _type_ = "u" def _reset_cache(): - # Skip this in wasm - py_wasm = _os.getenv("PYTHONWASM", "NOT SET") - if py_wasm == "1": - return - _pointer_type_cache.clear() _c_functype_cache.clear() if _os.name == "nt": From 7f945b7c94f291dadffcae1649f95a7b8ed472e5 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Mon, 18 Jan 2021 15:43:40 +0000 Subject: [PATCH 13/19] Adding in backtraces --- Objects/unicodeobject.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4c2b42f959b838..68316b87d3dd9c 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -53,6 +53,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif +#ifdef __wasm__ +#include +#endif + /* Uncomment to display statistics on interned strings at exit when using Valgrind or Insecure++. */ /* #define INTERNED_STATS 1 */ @@ -4938,6 +4942,9 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, endinpos = end - starts; break; case 1: +#ifdef __wasm__ + __faasm_backtrace(0); +#endif errmsg = "invalid start byte"; startinpos = s - starts; endinpos = startinpos + 1; @@ -4952,6 +4959,9 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, /* fall through */ case 3: case 4: +#ifdef __wasm__ + __faasm_backtrace(0); +#endif errmsg = "invalid continuation byte"; startinpos = s - starts; endinpos = startinpos + ch - 1; @@ -5124,10 +5134,16 @@ _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, *reason = "unexpected end of data"; break; case 1: +#ifdef __wasm__ + __faasm_backtrace(0); +#endif *reason = "invalid start byte"; break; /* 2, 3, 4 */ default: +#ifdef __wasm__ + __faasm_backtrace(0); +#endif *reason = "invalid continuation byte"; break; } From 3029a62ba9665fe68c7dac81c6d20af88c46af1c Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Wed, 20 Jan 2021 10:08:48 +0000 Subject: [PATCH 14/19] Added faasm backtrace to execption handling --- Modules/main.c | 8 ++++++++ pyconfig-extra.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Modules/main.c b/Modules/main.c index 2a360b58efa831..dabd2fd596befa 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -6,6 +6,10 @@ #include "pycore_pymem.h" #include "pycore_pystate.h" +#ifdef __faasm +#include +#endif + #ifdef __FreeBSD__ # include /* fedisableexcept() */ #endif @@ -111,6 +115,10 @@ stdin_is_interactive(const PyConfig *config) static int pymain_err_print(int *exitcode_p) { +#ifdef __faasm + __faasm_backtrace(0); +#endif + int exitcode; if (_Py_HandleSystemExit(&exitcode)) { *exitcode_p = exitcode; diff --git a/pyconfig-extra.h b/pyconfig-extra.h index b70be2f1719d9e..5f8253885d529a 100644 --- a/pyconfig-extra.h +++ b/pyconfig-extra.h @@ -21,7 +21,9 @@ #undef HAVE_SIGACTION // 32-bit +#ifndef CONFIG_32 #define CONFIG_32 +#endif #endif From ba2c73c4d5275c2e64d015d0004e5374b24c5bf6 Mon Sep 17 00:00:00 2001 From: Simon Shillaker Date: Thu, 21 Jan 2021 18:01:39 +0000 Subject: [PATCH 15/19] Removing backtrace logging --- Modules/main.c | 8 -------- Objects/unicodeobject.c | 16 ---------------- 2 files changed, 24 deletions(-) diff --git a/Modules/main.c b/Modules/main.c index dabd2fd596befa..2a360b58efa831 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -6,10 +6,6 @@ #include "pycore_pymem.h" #include "pycore_pystate.h" -#ifdef __faasm -#include -#endif - #ifdef __FreeBSD__ # include /* fedisableexcept() */ #endif @@ -115,10 +111,6 @@ stdin_is_interactive(const PyConfig *config) static int pymain_err_print(int *exitcode_p) { -#ifdef __faasm - __faasm_backtrace(0); -#endif - int exitcode; if (_Py_HandleSystemExit(&exitcode)) { *exitcode_p = exitcode; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 68316b87d3dd9c..4c2b42f959b838 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -53,10 +53,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifdef __wasm__ -#include -#endif - /* Uncomment to display statistics on interned strings at exit when using Valgrind or Insecure++. */ /* #define INTERNED_STATS 1 */ @@ -4942,9 +4938,6 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, endinpos = end - starts; break; case 1: -#ifdef __wasm__ - __faasm_backtrace(0); -#endif errmsg = "invalid start byte"; startinpos = s - starts; endinpos = startinpos + 1; @@ -4959,9 +4952,6 @@ unicode_decode_utf8(const char *s, Py_ssize_t size, /* fall through */ case 3: case 4: -#ifdef __wasm__ - __faasm_backtrace(0); -#endif errmsg = "invalid continuation byte"; startinpos = s - starts; endinpos = startinpos + ch - 1; @@ -5134,16 +5124,10 @@ _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, *reason = "unexpected end of data"; break; case 1: -#ifdef __wasm__ - __faasm_backtrace(0); -#endif *reason = "invalid start byte"; break; /* 2, 3, 4 */ default: -#ifdef __wasm__ - __faasm_backtrace(0); -#endif *reason = "invalid continuation byte"; break; } From c2741c8d7fb9c630d25de0bae09a1662eb00b3a7 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 22 Dec 2022 10:55:42 +0000 Subject: [PATCH 16/19] build ctypes statically --- Modules/Setup.local | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Modules/Setup.local b/Modules/Setup.local index 8c59b3434ac4e1..f27aeeebe371ef 100644 --- a/Modules/Setup.local +++ b/Modules/Setup.local @@ -37,6 +37,11 @@ _statistics _statisticsmodule.c # statistics accelerator # decimal module - sources derived from setup.py detect_decimal() _decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -I$(srcdir)/Modules/_decimal/libmpdec +# ctypes module - flags and sources derived from pyodide +# https://github.com/pyodide/pyodide/blob/main/cpython/Setup.local#L22-L23 +CTYPES_FLAGS=-DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1 +_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/cfield.c _ctypes/stgdict.c $(CTYPES_FLAGS) -L/usr/local/faasm/llvm-sysroot/lib/wasm32-wasi -lffi + # Disable things we definitely don't need *disabled* From 5534e771766070155c71de6fbc6a2c84d8f774d5 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 9 Jan 2023 11:08:43 +0000 Subject: [PATCH 17/19] _blake2: build statically all hashing modules --- Modules/Setup.local | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/Setup.local b/Modules/Setup.local index f27aeeebe371ef..1cfdb7b9e07ccb 100644 --- a/Modules/Setup.local +++ b/Modules/Setup.local @@ -42,6 +42,15 @@ _decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/con CTYPES_FLAGS=-DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1 _ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/cfield.c _ctypes/stgdict.c $(CTYPES_FLAGS) -L/usr/local/faasm/llvm-sysroot/lib/wasm32-wasi -lffi +# Hashing support - build statically as pyodide does +# https://github.com/pyodide/pyodide/blob/main/cpython/Setup.local#L37-L42 +_sha1 sha1module.c +_sha256 sha256module.c +_sha512 sha512module.c +_sha3 _sha3/sha3module.c +_md5 md5module.c +_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c + # Disable things we definitely don't need *disabled* From f6890ba59fc1fc1c86cf397175f4f8382e85e096 Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Thu, 23 Feb 2023 10:52:35 +0000 Subject: [PATCH 18/19] mmap: build statically --- Modules/Setup.local | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/Setup.local b/Modules/Setup.local index 1cfdb7b9e07ccb..a40e9158a93db9 100644 --- a/Modules/Setup.local +++ b/Modules/Setup.local @@ -51,6 +51,9 @@ _sha3 _sha3/sha3module.c _md5 md5module.c _blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c +# mmap module - build statically as pyodide does +mmap mmapmodule.c + # Disable things we definitely don't need *disabled* From 7e1130ff24992c3fe365ad22fb50c170948a6bed Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 19 Feb 2024 16:11:09 +0000 Subject: [PATCH 19/19] llvm17: changes to make cpython build with latest wasi-libc --- Modules/Setup.local | 2 +- Modules/timemodule.c | 4 ++-- config.sub | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/Setup.local b/Modules/Setup.local index a40e9158a93db9..7d8136fce4b8da 100644 --- a/Modules/Setup.local +++ b/Modules/Setup.local @@ -40,7 +40,7 @@ _decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/con # ctypes module - flags and sources derived from pyodide # https://github.com/pyodide/pyodide/blob/main/cpython/Setup.local#L22-L23 CTYPES_FLAGS=-DHAVE_FFI_PREP_CIF_VAR=1 -DHAVE_FFI_PREP_CLOSURE_LOC=1 -DHAVE_FFI_CLOSURE_ALLOC=1 -_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/cfield.c _ctypes/stgdict.c $(CTYPES_FLAGS) -L/usr/local/faasm/llvm-sysroot/lib/wasm32-wasi -lffi +_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/cfield.c _ctypes/stgdict.c $(CTYPES_FLAGS) -lffi # Hashing support - build statically as pyodide does # https://github.com/pyodide/pyodide/blob/main/cpython/Setup.local#L37-L42 diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 5e0010c8a81996..01df1376d783b2 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1765,10 +1765,10 @@ PyInit_time(void) #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_SETTIME) || defined(HAVE_CLOCK_GETRES) #ifdef CLOCK_REALTIME - PyModule_AddIntMacro(m, CLOCK_REALTIME); + PyModule_AddIntMacro(m, (long) CLOCK_REALTIME); #endif #ifdef CLOCK_MONOTONIC - PyModule_AddIntMacro(m, CLOCK_MONOTONIC); + PyModule_AddIntMacro(m, (long) CLOCK_MONOTONIC); #endif #ifdef CLOCK_MONOTONIC_RAW PyModule_AddIntMacro(m, CLOCK_MONOTONIC_RAW); diff --git a/config.sub b/config.sub index 289051b4e2e0f2..9d8aab5923fa10 100755 --- a/config.sub +++ b/config.sub @@ -118,7 +118,7 @@ case $maybe_os in linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ kopensolaris*-gnu* | cloudabi*-eabi* | \ - storm-chaos* | os2-emx* | rtmk-nova* | wasi ) + storm-chaos* | os2-emx* | rtmk-nova* | wasi* ) os=-$maybe_os basic_machine=`echo "$1" | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;;