Skip to content

Commit 544b001

Browse files
authored
gh-126691: Remove --with-emscripten-target (#126787)
This unifies the code for nodejs and the code for the browser. After this commit, the browser example doesn't work; this will be fixed in a subsequent update.
1 parent d6bcc15 commit 544b001

File tree

6 files changed

+38
-173
lines changed

6 files changed

+38
-173
lines changed

Doc/using/configure.rst

-9
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,6 @@ Options for third-party dependencies
454454
WebAssembly Options
455455
-------------------
456456

457-
.. option:: --with-emscripten-target=[browser|node]
458-
459-
Set build flavor for ``wasm32-emscripten``.
460-
461-
* ``browser`` (default): preload minimal stdlib, default MEMFS.
462-
* ``node``: NODERAWFS and pthread support.
463-
464-
.. versionadded:: 3.11
465-
466457
.. option:: --enable-wasm-dynamic-linking
467458

468459
Turn on dynamic linking support for WASM.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed the ``--with-emscripten-target`` configure flag. We unified the
2+
``node`` and ``browser`` options and the same build can now be used, independent
3+
of target runtime.

Tools/wasm/README.md

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ https://github.com/psf/webassembly for more information.
2121

2222
### Build
2323

24-
For now the build system has two target flavors. The ``Emscripten/browser``
25-
target (``--with-emscripten-target=browser``) is optimized for browsers.
26-
It comes with a reduced and preloaded stdlib without tests and threading
27-
support. The ``Emscripten/node`` target has threading enabled and can
28-
access the file system directly.
29-
3024
To cross compile to the ``wasm32-emscripten`` platform you need
3125
[the Emscripten compiler toolchain](https://emscripten.org/),
3226
a Python interpreter, and an installation of Node version 18 or newer. Emscripten

Tools/wasm/emscripten/node_pre.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// If process is undefined, we're not running in the node runtime let it go I
22
// guess?
33
if (typeof process !== "undefined") {
4-
const nodeVersion = Number(process.versions.node.split('.',1)[0]);
4+
const nodeVersion = Number(process.versions.node.split(".", 1)[0]);
55
if (nodeVersion < 18) {
6-
process.stderr.write(`Node version must be >= 18, got version ${process.version}\n`);
6+
process.stderr.write(
7+
`Node version must be >= 18, got version ${process.version}\n`,
8+
);
79
process.exit(1);
810
}
11+
Module.preRun = () => {
12+
FS.mkdirTree("/lib/");
13+
FS.mount(NODEFS, { root: __dirname + "/lib/" }, "/lib/");
14+
};
915
}

configure

+13-97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+14-59
Original file line numberDiff line numberDiff line change
@@ -1282,30 +1282,6 @@ AS_CASE([$ac_sys_system/$ac_sys_release],
12821282
]
12831283
)
12841284

1285-
AC_MSG_CHECKING([for --with-emscripten-target])
1286-
AC_ARG_WITH([emscripten-target],
1287-
[AS_HELP_STRING([--with-emscripten-target=@<:@browser|node@:>@], [Emscripten platform])],
1288-
[
1289-
AS_VAR_IF([ac_sys_system], [Emscripten], [
1290-
AS_CASE([$with_emscripten_target],
1291-
[browser], [ac_sys_emscripten_target=browser],
1292-
[node], [ac_sys_emscripten_target=node],
1293-
dnl Debug builds with source map / dwarf symbols. Py_DEBUG builds easily
1294-
dnl run out of stack space. Detached sybmols and map prohibit some
1295-
dnl optimizations and increase file size. Options are undocumented so we
1296-
dnl are free to remove them in the future.
1297-
[browser-debug], [ac_sys_emscripten_target=browser-debug],
1298-
[node-debug], [ac_sys_emscripten_target=node-debug],
1299-
[AC_MSG_ERROR([Invalid argument: --with-emscripten-target=browser|node])]
1300-
)
1301-
], [
1302-
AC_MSG_ERROR([--with-emscripten-target only applies to Emscripten])
1303-
])
1304-
], [
1305-
AS_VAR_IF([ac_sys_system], [Emscripten], [ac_sys_emscripten_target=browser])
1306-
])
1307-
AC_MSG_RESULT([$ac_sys_emscripten_target])
1308-
13091285
dnl On Emscripten dlopen() requires -s MAIN_MODULE and -fPIC. The flags
13101286
dnl disables dead code elimination and increases the size of the WASM module
13111287
dnl by about 1.5 to 2MB. MAIN_MODULE defines __wasm_mutable_globals__.
@@ -1350,10 +1326,9 @@ AC_ARG_WITH([suffix],
13501326
[EXEEXT=$with_suffix]
13511327
)
13521328
], [
1353-
AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
1354-
[Emscripten/browser*], [EXEEXT=.js],
1355-
[Emscripten/node*], [EXEEXT=.js],
1356-
[WASI/*], [EXEEXT=.wasm],
1329+
AS_CASE([$ac_sys_system],
1330+
[Emscripten], [EXEEXT=.js],
1331+
[WASI], [EXEEXT=.wasm],
13571332
[EXEEXT=]
13581333
)
13591334
])
@@ -1638,16 +1613,16 @@ AC_MSG_CHECKING([HOSTRUNNER])
16381613
AC_ARG_VAR([HOSTRUNNER], [Program to run CPython for the host platform])
16391614
if test -z "$HOSTRUNNER"
16401615
then
1641-
AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
1642-
[Emscripten/node*], [
1616+
AS_CASE([$ac_sys_system],
1617+
[Emscripten], [
16431618
AC_PATH_TOOL([NODE], [node], [node])
16441619
HOSTRUNNER="$NODE"
16451620
AS_VAR_IF([host_cpu], [wasm64], [AS_VAR_APPEND([HOSTRUNNER], [" --experimental-wasm-memory64"])])
16461621
],
16471622
dnl TODO: support other WASI runtimes
16481623
dnl wasmtime starts the process with "/" as CWD. For OOT builds add the
16491624
dnl directory containing _sysconfigdata to PYTHONPATH.
1650-
[WASI/*], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2=n --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'],
1625+
[WASI], [HOSTRUNNER='wasmtime run --wasm max-wasm-stack=16777216 --wasi preview2=n --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt):/Lib --dir $(srcdir)::/'],
16511626
[HOSTRUNNER='']
16521627
)
16531628
fi
@@ -1660,10 +1635,8 @@ if test -n "$HOSTRUNNER"; then
16601635
fi
16611636

16621637
# LIBRARY_DEPS, LINK_PYTHON_OBJS and LINK_PYTHON_DEPS variable
1663-
AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
1664-
[Emscripten/browser*], [LIBRARY_DEPS='$(PY3LIBRARY) $(WASM_STDLIB) python.html python.worker.js'],
1665-
[LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)']
1666-
)
1638+
LIBRARY_DEPS='$(PY3LIBRARY) $(EXPORTSYMS)'
1639+
16671640
LINK_PYTHON_DEPS='$(LIBRARY_DEPS)'
16681641
if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then
16691642
LIBRARY_DEPS="\$(LDLIBRARY) $LIBRARY_DEPS"
@@ -2365,24 +2338,11 @@ AS_CASE([$ac_sys_system],
23652338
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sUSE_PTHREADS"])
23662339
AS_VAR_APPEND([LINKFORSHARED], [" -sPROXY_TO_PTHREAD"])
23672340
])
2368-
2369-
AS_CASE([$ac_sys_emscripten_target],
2370-
[browser*], [
2371-
AS_VAR_IF([ac_sys_emscripten_target], [browser-debug], [wasm_debug=yes])
2372-
AS_VAR_APPEND([LINKFORSHARED], [" --preload-file=\$(WASM_ASSETS_DIR)"])
2373-
WASM_ASSETS_DIR=".\$(prefix)"
2374-
WASM_STDLIB="\$(WASM_ASSETS_DIR)/local/lib/python\$(VERSION)/os.py"
2375-
dnl separate-dwarf does not seem to work in Chrome DevTools Support.
2376-
WASM_LINKFORSHARED_DEBUG="-gsource-map --emit-symbol-map"
2377-
],
2378-
[node*], [
2379-
AS_VAR_IF([ac_sys_emscripten_target], [node-debug], [wasm_debug=yes])
2380-
AS_VAR_APPEND([LDFLAGS_NODIST], [" --pre-js=\$(srcdir)/Tools/wasm/emscripten/node_pre.js"])
2381-
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH -sNODERAWFS"])
2382-
AS_VAR_APPEND([LINKFORSHARED], [" -sEXIT_RUNTIME"])
2383-
WASM_LINKFORSHARED_DEBUG="-gseparate-dwarf --emit-symbol-map"
2384-
]
2385-
)
2341+
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH"])
2342+
dnl not completely sure whether or not we want -sEXIT_RUNTIME, keeping it for now.
2343+
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sEXIT_RUNTIME"])
2344+
AS_VAR_APPEND([LDFLAGS_NODIST], [" --pre-js=\$(srcdir)/Tools/wasm/emscripten/node_pre.js"])
2345+
WASM_LINKFORSHARED_DEBUG="-gseparate-dwarf --emit-symbol-map"
23862346
23872347
AS_VAR_IF([wasm_debug], [yes], [
23882348
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sASSERTIONS"])
@@ -7463,12 +7423,7 @@ AC_MSG_CHECKING([for --disable-test-modules])
74637423
AC_ARG_ENABLE([test-modules],
74647424
[AS_HELP_STRING([--disable-test-modules], [don't build nor install test modules])], [
74657425
AS_VAR_IF([enable_test_modules], [yes], [TEST_MODULES=yes], [TEST_MODULES=no])
7466-
], [
7467-
AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
7468-
[Emscripten/browser*], [TEST_MODULES=no],
7469-
[TEST_MODULES=yes]
7470-
)
7471-
])
7426+
], [TEST_MODULES=yes])
74727427
AC_MSG_RESULT([$TEST_MODULES])
74737428
AC_SUBST([TEST_MODULES])
74747429

0 commit comments

Comments
 (0)