@@ -1062,6 +1062,24 @@ AS_CASE([$ac_sys_system/$ac_sys_release],
10621062 ]
10631063)
10641064
1065+ AC_MSG_CHECKING ( [ for --with-emscripten-target] )
1066+ AC_ARG_WITH ( [ emscripten-target] ,
1067+ [ AS_HELP_STRING ( [ --with-emscripten-target=@<:@ browser|node@:>@ ] , [ Emscripten platform] ) ] ,
1068+ [
1069+ AS_VAR_IF ( [ ac_sys_system] , [ Emscripten] , [
1070+ AS_CASE ( [ $with_emscripten_target] ,
1071+ [ browser] , [ ac_sys_emscripten_target=browser] ,
1072+ [ node] , [ ac_sys_emscripten_target=node] ,
1073+ [ AC_MSG_ERROR ( [ Invalid argument: --with-emscripten-target=browser|node] ) ]
1074+ )
1075+ ] , [
1076+ AC_MSG_ERROR ( [ --with-emscripten-target only applies to Emscripten] )
1077+ ] )
1078+ ] , [
1079+ AS_VAR_IF ( [ ac_sys_system] , [ Emscripten] , [ ac_sys_emscripten_target=browser] )
1080+ ] )
1081+ AC_MSG_RESULT ( [ $ac_sys_emscripten_target] )
1082+
10651083AC_MSG_CHECKING ( [ for --with-suffix] )
10661084AC_ARG_WITH ( [ suffix] ,
10671085 [ AS_HELP_STRING ( [ --with-suffix=SUFFIX] , [ set executable suffix to SUFFIX (default is empty, yes is mapped to '.exe')] ) ] ,
@@ -1072,8 +1090,10 @@ AC_ARG_WITH([suffix],
10721090 [ EXEEXT=$with_suffix]
10731091 )
10741092] , [
1075- AS_CASE ( [ $ac_sys_system] ,
1076- [ Emscripten] , [ EXEEXT=.wasm] ,
1093+ AS_CASE ( [ $ac_sys_system/$ac_sys_emscripten_target] ,
1094+ [ Emscripten/browser] , [ EXEEXT=.html] ,
1095+ [ Emscripten/node] , [ EXEEXT=.js] ,
1096+ [ wasi/*] , [ EXEEXT=.wasm] ,
10771097 [ EXEEXT=]
10781098 )
10791099] )
@@ -1446,6 +1466,7 @@ else
14461466 AC_MSG_RESULT ( no ) ;
14471467fi] ,
14481468[ AC_MSG_RESULT ( no ) ] )
1469+
14491470if test "$Py_OPT" = 'true' ; then
14501471 # Intentionally not forcing Py_LTO='true' here. Too many toolchains do not
14511472 # compile working code using it and both test_distutils and test_gdb are
@@ -1462,8 +1483,12 @@ if test "$Py_OPT" = 'true' ; then
14621483 ] )
14631484 ;;
14641485 esac
1465-
1466-
1486+ elif test "$ac_sys_system" = "Emscripten"; then
1487+ dnl Emscripten does not support shared extensions yet. Build
1488+ dnl "python.[js,html,wasm]", "pybuilddir.txt", and "platform" files.
1489+ DEF_MAKE_ALL_RULE="build_platform"
1490+ REQUIRE_PGO="no"
1491+ DEF_MAKE_RULE="all"
14671492else
14681493 DEF_MAKE_ALL_RULE="build_all"
14691494 REQUIRE_PGO="no"
@@ -1769,10 +1794,25 @@ then
17691794 esac
17701795fi
17711796
1797+ # WASM flags
1798+ AS_CASE ( [ $ac_sys_system/$ac_sys_emscripten_target] ,
1799+ [ Emscripten/browser] , [
1800+ LDFLAGS_NODIST="$(LDFLAGS_NODIST) -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file \$(WASM_ASSETS_DIR)"
1801+ WASM_ASSETS_DIR=".\$(prefix)"
1802+ WASM_STDLIB="\$(WASM_ASSETS_DIR)/local/lib/python\$(VERSION)/os.py"
1803+ ] ,
1804+ [ Emscripten/node] , [
1805+ 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"
1806+ CFLAGS_NODIST="$(CFLAGS_NODIST) -pthread"
1807+ ] ,
1808+ )
1809+
17721810AC_SUBST ( BASECFLAGS )
17731811AC_SUBST ( CFLAGS_NODIST )
17741812AC_SUBST ( LDFLAGS_NODIST )
17751813AC_SUBST ( LDFLAGS_NOLTO )
1814+ AC_SUBST ( [ WASM_ASSETS_DIR] )
1815+ AC_SUBST ( [ WASM_STDLIB] )
17761816
17771817# The -arch flags for universal builds on macOS
17781818UNIVERSAL_ARCH_FLAGS=
@@ -6252,6 +6292,12 @@ if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then
62526292else
62536293 LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
62546294fi
6295+
6296+ dnl browser needs a WASM assets stdlib bundle
6297+ AS_CASE ( [ $ac_sys_system/$ac_sys_emscripten_target] ,
6298+ [ Emscripten/browser] , [ LIBRARY_DEPS="$LIBRARY_DEPS \$(WASM_STDLIB)"] ,
6299+ )
6300+
62556301AC_SUBST ( STATIC_LIBPYTHON )
62566302AC_SUBST ( LIBRARY_DEPS )
62576303
@@ -6520,8 +6566,9 @@ PY_STDLIB_MOD([_ctypes_test], [test "$TEST_MODULES" = yes], [], [], [-lm])
65206566
65216567dnl Limited API template modules.
65226568dnl The limited C API is not compatible with the Py_TRACE_REFS macro.
6523- PY_STDLIB_MOD([ xxlimited] , [ test "$with_trace_refs" = "no"] )
6524- PY_STDLIB_MOD([ xxlimited_35] , [ test "$with_trace_refs" = "no"] )
6569+ dnl Emscripten does not support shared libraries yet.
6570+ PY_STDLIB_MOD([ xxlimited] , [ test "$with_trace_refs" = "no" -a "$ac_sys_system" != "Emscripten"] )
6571+ PY_STDLIB_MOD([ xxlimited_35] , [ test "$with_trace_refs" = "no" -a "$ac_sys_system" != "Emscripten"] )
65256572
65266573# substitute multiline block, must come after last PY_STDLIB_MOD()
65276574AC_SUBST ( [ MODULE_BLOCK] )
0 commit comments