From 1b96c460582787a92839a37bd6cecd1d9dd7e117 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 14 Jan 2022 11:29:03 +0100 Subject: [PATCH 1/2] bpo-40280: Build WASM stdlib bundle for Emscripten/browser target --- Makefile.pre.in | 1 + configure | 14 ++++++++++---- configure.ac | 11 +++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 0782d95482576a..0b4d9a5240158c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -2399,6 +2399,7 @@ clean-retain-profile: pycremoval -rm -f Lib/lib2to3/*Grammar*.pickle -rm -f _bootstrap_python -rm -f python.html python*.js python.data + -rm -rf $(WASM_STDLIB) -rm -f Programs/_testembed Programs/_freeze_module -rm -f Python/deepfreeze/*.[co] -rm -f Python/frozen_modules/*.h diff --git a/configure b/configure index ccbf4fc0b180f7..0e87f2ea70c4dd 100755 --- a/configure +++ b/configure @@ -6577,7 +6577,13 @@ fi $as_echo "$LDLIBRARY" >&6; } # LIBRARY_DEPS, LINK_PYTHON_OBJS and LINK_PYTHON_DEPS variable -LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)' +case $ac_sys_system/$ac_sys_emscripten_target in #( + Emscripten/browser) : + LIBRARY_DEPS='$(PY3LIBRARY) $(WASM_STDLIB)' ;; #( + *) : + LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)' + ;; +esac LINK_PYTHON_DEPS='$(LIBRARY_DEPS)' if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS" @@ -7669,14 +7675,14 @@ fi case $ac_sys_system/$ac_sys_emscripten_target in #( Emscripten/browser) : - LDFLAGS_NODIST="$(LDFLAGS_NODIST) -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file \$(WASM_ASSETS_DIR)" + LDFLAGS_NODIST="$LDFLAGS_NODIST -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file \$(WASM_ASSETS_DIR)" WASM_ASSETS_DIR=".\$(prefix)" WASM_STDLIB="\$(WASM_ASSETS_DIR)/local/lib/python\$(VERSION)/os.py" ;; #( Emscripten/node) : - LDFLAGS_NODIST="$(LDFLAGS_NODIST) -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1 -s USE_PTHREADS -s PROXY_TO_PTHREAD" - CFLAGS_NODIST="$(CFLAGS_NODIST) -pthread" + LDFLAGS_NODIST="$LDFLAGS_NODIST -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1 -s USE_PTHREADS -s PROXY_TO_PTHREAD" + CFLAGS_NODIST="$CFLAGS_NODIST -pthread" ;; #( WASI) : diff --git a/configure.ac b/configure.ac index 89041b205f50d4..4750258beb3201 100644 --- a/configure.ac +++ b/configure.ac @@ -1354,7 +1354,10 @@ fi AC_MSG_RESULT($LDLIBRARY) # LIBRARY_DEPS, LINK_PYTHON_OBJS and LINK_PYTHON_DEPS variable -LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)' +AS_CASE([$ac_sys_system/$ac_sys_emscripten_target], + [Emscripten/browser], [LIBRARY_DEPS='$(PY3LIBRARY) $(WASM_STDLIB)'], + [LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)'] +) LINK_PYTHON_DEPS='$(LIBRARY_DEPS)' if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS" @@ -1839,13 +1842,13 @@ fi # WASM flags AS_CASE([$ac_sys_system/$ac_sys_emscripten_target], [Emscripten/browser], [ - LDFLAGS_NODIST="$(LDFLAGS_NODIST) -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file \$(WASM_ASSETS_DIR)" + LDFLAGS_NODIST="$LDFLAGS_NODIST -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file \$(WASM_ASSETS_DIR)" WASM_ASSETS_DIR=".\$(prefix)" WASM_STDLIB="\$(WASM_ASSETS_DIR)/local/lib/python\$(VERSION)/os.py" ], [Emscripten/node], [ - LDFLAGS_NODIST="$(LDFLAGS_NODIST) -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1 -s USE_PTHREADS -s PROXY_TO_PTHREAD" - CFLAGS_NODIST="$(CFLAGS_NODIST) -pthread" + LDFLAGS_NODIST="$LDFLAGS_NODIST -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -s EXIT_RUNTIME=1 -s USE_PTHREADS -s PROXY_TO_PTHREAD" + CFLAGS_NODIST="$CFLAGS_NODIST -pthread" ], [WASI], [ AC_DEFINE([_WASI_EMULATED_SIGNAL], [1], [Define to 1 if you want to emulate signals on WASI]) From 87bcb68e75b32bc75a4adac728e1f266977e225c Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 14 Jan 2022 11:33:10 +0100 Subject: [PATCH 2/2] bpo-40280: Build more modules for Emscripten/node target --- configure | 20 ++++++++++++-------- configure.ac | 33 +++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/configure b/configure index 0e87f2ea70c4dd..b5a6e0c51bd524 100755 --- a/configure +++ b/configure @@ -21300,22 +21300,26 @@ $as_echo "yes" >&6; } fi -case $ac_sys_system in #( - AIX) : +case $ac_sys_system/$ac_sys_emscripten_target in #( + AIX/*) : py_stdlib_not_available="_scproxy spwd" ;; #( - VxWorks*) : + VxWorks*/*) : py_stdlib_not_available="_scproxy _crypt termios grp" ;; #( - Darwin) : + Darwin/*) : py_stdlib_not_available="ossaudiodev spwd" ;; #( - CYGWIN*) : + CYGWIN*/*) : py_stdlib_not_available="_scproxy nis" ;; #( - QNX*) : + QNX*/*) : py_stdlib_not_available="_scproxy nis" ;; #( - FreeBSD*) : + FreeBSD*/*) : py_stdlib_not_available="_scproxy spwd" ;; #( - Emscripten) : + Emscripten/browser) : py_stdlib_not_available="_ctypes _curses _curses_panel _dbm _gdbm _multiprocessing _posixshmem _posixsubprocess _scproxy _tkinter _xxsubinterpreters fcntl grp nis ossaudiodev resource readline spwd syslog termios" + ;; #( + Emscripten/node) : + + py_stdlib_not_available="_ctypes _curses _curses_panel _dbm _gdbm _scproxy _tkinter nis ossaudiodev spwd syslog" ;; #( *) : py_stdlib_not_available="_scproxy" diff --git a/configure.ac b/configure.ac index 4750258beb3201..300d793ad7dfa4 100644 --- a/configure.ac +++ b/configure.ac @@ -6339,14 +6339,14 @@ AC_SUBST(TEST_MODULES) dnl Modules that are not available on some platforms dnl AIX has shadow passwords, but access is not via getspent() dnl VxWorks does not provide crypt() function -AS_CASE([$ac_sys_system], - [AIX], [py_stdlib_not_available="_scproxy spwd"], - [VxWorks*], [py_stdlib_not_available="_scproxy _crypt termios grp"], - [Darwin], [py_stdlib_not_available="ossaudiodev spwd"], - [CYGWIN*], [py_stdlib_not_available="_scproxy nis"], - [QNX*], [py_stdlib_not_available="_scproxy nis"], - [FreeBSD*], [py_stdlib_not_available="_scproxy spwd"], - [Emscripten], [ +AS_CASE([$ac_sys_system/$ac_sys_emscripten_target], + [AIX/*], [py_stdlib_not_available="_scproxy spwd"], + [VxWorks*/*], [py_stdlib_not_available="_scproxy _crypt termios grp"], + [Darwin/*], [py_stdlib_not_available="ossaudiodev spwd"], + [CYGWIN*/*], [py_stdlib_not_available="_scproxy nis"], + [QNX*/*], [py_stdlib_not_available="_scproxy nis"], + [FreeBSD*/*], [py_stdlib_not_available="_scproxy spwd"], + [Emscripten/browser], [ py_stdlib_not_available="m4_normalize([ _ctypes _curses @@ -6370,6 +6370,23 @@ AS_CASE([$ac_sys_system], termios ])" ], + dnl Some modules like _posixsubprocess do not work. We build them anyway + dnl so imports in tests do not fail. + [Emscripten/node], [ + py_stdlib_not_available="m4_normalize([ + _ctypes + _curses + _curses_panel + _dbm + _gdbm + _scproxy + _tkinter + nis + ossaudiodev + spwd + syslog + ])" + ], [py_stdlib_not_available="_scproxy"] )