2021-12-18 22:54:02 +08:00
|
|
|
# Python WebAssembly (WASM) build
|
|
|
|
|
2024-03-07 10:38:00 +08:00
|
|
|
**WASI support is [tier 2](https://peps.python.org/pep-0011/#tier-2).**
|
|
|
|
**Emscripten is NOT officially supported as of Python 3.13.**
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2021-12-18 22:54:02 +08:00
|
|
|
This directory contains configuration and helpers to facilitate cross
|
2022-09-11 15:51:23 +08:00
|
|
|
compilation of CPython to WebAssembly (WASM). Python supports Emscripten
|
|
|
|
(*wasm32-emscripten*) and WASI (*wasm32-wasi*) targets. Emscripten builds
|
|
|
|
run in modern browsers and JavaScript runtimes like *Node.js*. WASI builds
|
|
|
|
use WASM runtimes such as *wasmtime*.
|
|
|
|
|
|
|
|
Users and developers are encouraged to use the script
|
|
|
|
`Tools/wasm/wasm_build.py`. The tool automates the build process and provides
|
2023-06-03 06:15:41 +08:00
|
|
|
assistance with installation of SDKs, running tests, etc.
|
2021-12-18 22:54:02 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
**NOTE**: If you are looking for information that is not directly related to
|
|
|
|
building CPython for WebAssembly (or the resulting build), please see
|
|
|
|
https://github.com/psf/webassembly for more information.
|
|
|
|
|
|
|
|
## wasm32-emscripten
|
|
|
|
|
|
|
|
### Build
|
2021-12-18 22:54:02 +08:00
|
|
|
|
2022-04-23 15:52:16 +08:00
|
|
|
For now the build system has two target flavors. The ``Emscripten/browser``
|
|
|
|
target (``--with-emscripten-target=browser``) is optimized for browsers.
|
|
|
|
It comes with a reduced and preloaded stdlib without tests and threading
|
|
|
|
support. The ``Emscripten/node`` target has threading enabled and can
|
|
|
|
access the file system directly.
|
|
|
|
|
2022-04-10 15:29:51 +08:00
|
|
|
Cross compiling to the wasm32-emscripten platform needs the
|
|
|
|
[Emscripten](https://emscripten.org/) SDK and a build Python interpreter.
|
2022-09-11 15:51:23 +08:00
|
|
|
Emscripten 3.1.19 or newer are recommended. All commands below are relative
|
2022-04-10 15:29:51 +08:00
|
|
|
to a repository checkout.
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Toolchain
|
|
|
|
|
|
|
|
##### Container image
|
|
|
|
|
2022-04-10 15:29:51 +08:00
|
|
|
Christian Heimes maintains a container image with Emscripten SDK, Python
|
|
|
|
build dependencies, WASI-SDK, wasmtime, and several additional tools.
|
|
|
|
|
2022-07-25 15:42:50 +08:00
|
|
|
From within your local CPython repo clone, run one of the following commands:
|
|
|
|
|
2022-04-10 15:29:51 +08:00
|
|
|
```
|
|
|
|
# Fedora, RHEL, CentOS
|
2022-07-25 15:42:50 +08:00
|
|
|
podman run --rm -ti -v $(pwd):/python-wasm/cpython:Z -w /python-wasm/cpython quay.io/tiran/cpythonbuild:emsdk3
|
2022-04-10 15:29:51 +08:00
|
|
|
|
|
|
|
# other
|
2022-07-25 15:42:50 +08:00
|
|
|
docker run --rm -ti -v $(pwd):/python-wasm/cpython -w /python-wasm/cpython quay.io/tiran/cpythonbuild:emsdk3
|
2022-04-10 15:29:51 +08:00
|
|
|
```
|
2021-12-18 22:54:02 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
##### Manually
|
|
|
|
|
|
|
|
###### Install [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html)
|
|
|
|
|
|
|
|
**NOTE**: Follow the on-screen instructions how to add the SDK to ``PATH``.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
git clone https://github.com/emscripten-core/emsdk.git /opt/emsdk
|
|
|
|
/opt/emsdk/emsdk install latest
|
|
|
|
/opt/emsdk/emsdk activate latest
|
|
|
|
```
|
|
|
|
|
|
|
|
###### Optionally: enable ccache for EMSDK
|
|
|
|
|
|
|
|
The ``EM_COMPILER_WRAPPER`` must be set after the EMSDK environment is
|
|
|
|
sourced. Otherwise the source script removes the environment variable.
|
|
|
|
|
|
|
|
```
|
|
|
|
. /opt/emsdk/emsdk_env.sh
|
|
|
|
EM_COMPILER_WRAPPER=ccache
|
|
|
|
```
|
|
|
|
|
|
|
|
###### Optionally: pre-build and cache static libraries
|
|
|
|
|
|
|
|
Emscripten SDK provides static builds of core libraries without PIC
|
|
|
|
(position-independent code). Python builds with ``dlopen`` support require
|
|
|
|
PIC. To populate the build cache, run:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
. /opt/emsdk/emsdk_env.sh
|
|
|
|
embuilder build zlib bzip2 MINIMAL_PIC
|
2023-09-27 04:22:00 +08:00
|
|
|
embuilder --pic build zlib bzip2 MINIMAL_PIC
|
2023-06-03 06:15:41 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2024-02-04 08:16:30 +08:00
|
|
|
### Compile and build Python interpreter
|
2021-12-18 22:54:02 +08:00
|
|
|
|
2022-08-14 03:56:08 +08:00
|
|
|
From within the container, run the following command:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
./Tools/wasm/wasm_build.py build
|
|
|
|
```
|
|
|
|
|
|
|
|
The command is roughly equivalent to:
|
2022-07-25 15:42:50 +08:00
|
|
|
|
2021-12-18 22:54:02 +08:00
|
|
|
```shell
|
|
|
|
mkdir -p builddir/build
|
|
|
|
pushd builddir/build
|
|
|
|
../../configure -C
|
|
|
|
make -j$(nproc)
|
|
|
|
popd
|
|
|
|
```
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Cross-compile to wasm32-emscripten for browser
|
2021-12-18 22:54:02 +08:00
|
|
|
|
|
|
|
```shell
|
2022-08-14 03:56:08 +08:00
|
|
|
./Tools/wasm/wasm_build.py emscripten-browser
|
2021-12-18 22:54:02 +08:00
|
|
|
```
|
|
|
|
|
2022-08-14 03:56:08 +08:00
|
|
|
The command is roughly equivalent to:
|
2022-01-12 23:08:19 +08:00
|
|
|
|
2021-12-18 22:54:02 +08:00
|
|
|
```shell
|
2022-02-06 03:52:01 +08:00
|
|
|
mkdir -p builddir/emscripten-browser
|
|
|
|
pushd builddir/emscripten-browser
|
2021-12-18 22:54:02 +08:00
|
|
|
|
|
|
|
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \
|
|
|
|
emconfigure ../../configure -C \
|
|
|
|
--host=wasm32-unknown-emscripten \
|
|
|
|
--build=$(../../config.guess) \
|
2022-01-12 23:08:19 +08:00
|
|
|
--with-emscripten-target=browser \
|
|
|
|
--with-build-python=$(pwd)/../build/python
|
|
|
|
|
|
|
|
emmake make -j$(nproc)
|
2022-02-06 03:52:01 +08:00
|
|
|
popd
|
|
|
|
```
|
|
|
|
|
|
|
|
Serve `python.html` with a local webserver and open the file in a browser.
|
2022-07-26 17:12:42 +08:00
|
|
|
Python comes with a minimal web server script that sets necessary HTTP
|
|
|
|
headers like COOP, COEP, and mimetypes. Run the script outside the container
|
|
|
|
and from the root of the CPython checkout.
|
2022-02-06 03:52:01 +08:00
|
|
|
|
|
|
|
```shell
|
2022-04-05 17:21:11 +08:00
|
|
|
./Tools/wasm/wasm_webserver.py
|
2022-01-12 23:08:19 +08:00
|
|
|
```
|
|
|
|
|
2022-04-05 17:21:11 +08:00
|
|
|
and open http://localhost:8000/builddir/emscripten-browser/python.html . This
|
|
|
|
directory structure enables the *C/C++ DevTools Support (DWARF)* to load C
|
|
|
|
and header files with debug builds.
|
|
|
|
|
2022-07-26 17:12:42 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Cross compile to wasm32-emscripten for node
|
2022-01-12 23:08:19 +08:00
|
|
|
|
2022-04-23 15:52:16 +08:00
|
|
|
```shell
|
2023-09-14 06:28:08 +08:00
|
|
|
./Tools/wasm/wasm_build.py emscripten-node-dl
|
2022-08-14 03:56:08 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
The command is roughly equivalent to:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
mkdir -p builddir/emscripten-node-dl
|
|
|
|
pushd builddir/emscripten-node-dl
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-01-12 23:08:19 +08:00
|
|
|
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \
|
|
|
|
emconfigure ../../configure -C \
|
|
|
|
--host=wasm32-unknown-emscripten \
|
|
|
|
--build=$(../../config.guess) \
|
|
|
|
--with-emscripten-target=node \
|
2022-08-14 03:56:08 +08:00
|
|
|
--enable-wasm-dynamic-linking \
|
2021-12-18 22:54:02 +08:00
|
|
|
--with-build-python=$(pwd)/../build/python
|
|
|
|
|
2022-01-12 23:08:19 +08:00
|
|
|
emmake make -j$(nproc)
|
2022-02-06 03:52:01 +08:00
|
|
|
popd
|
2021-12-18 22:54:02 +08:00
|
|
|
```
|
|
|
|
|
2022-04-23 15:52:16 +08:00
|
|
|
```shell
|
2022-08-14 03:56:08 +08:00
|
|
|
node --experimental-wasm-threads --experimental-wasm-bulk-memory --experimental-wasm-bigint builddir/emscripten-node-dl/python.js
|
2021-12-18 22:54:02 +08:00
|
|
|
```
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-06-24 23:03:42 +08:00
|
|
|
(``--experimental-wasm-bigint`` is not needed with recent NodeJS versions)
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
### Limitations and issues
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-04-05 17:21:11 +08:00
|
|
|
Emscripten before 3.1.8 has known bugs that can cause memory corruption and
|
|
|
|
resource leaks. 3.1.8 contains several fixes for bugs in date and time
|
|
|
|
functions.
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Network stack
|
2022-04-05 17:21:11 +08:00
|
|
|
|
|
|
|
- Python's socket module does not work with Emscripten's emulated POSIX
|
|
|
|
sockets yet. Network modules like ``asyncio``, ``urllib``, ``selectors``,
|
|
|
|
etc. are not available.
|
2022-04-05 01:31:31 +08:00
|
|
|
- Only ``AF_INET`` and ``AF_INET6`` with ``SOCK_STREAM`` (TCP) or
|
|
|
|
``SOCK_DGRAM`` (UDP) are available. ``AF_UNIX`` is not supported.
|
|
|
|
- ``socketpair`` does not work.
|
2022-02-06 03:52:01 +08:00
|
|
|
- Blocking sockets are not available and non-blocking sockets don't work
|
|
|
|
correctly, e.g. ``socket.accept`` crashes the runtime. ``gethostbyname``
|
|
|
|
does not resolve to a real IP address. IPv6 is not available.
|
|
|
|
- The ``select`` module is limited. ``select.select()`` crashes the runtime
|
|
|
|
due to lack of exectfd support.
|
2022-04-05 17:21:11 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### processes, signals
|
2022-04-05 17:21:11 +08:00
|
|
|
|
|
|
|
- Processes are not supported. System calls like fork, popen, and subprocess
|
|
|
|
fail with ``ENOSYS`` or ``ENOSUP``.
|
2022-02-06 03:52:01 +08:00
|
|
|
- Signal support is limited. ``signal.alarm``, ``itimer``, ``sigaction``
|
|
|
|
are not available or do not work correctly. ``SIGTERM`` exits the runtime.
|
2022-04-05 17:21:11 +08:00
|
|
|
- Keyboard interrupt (CTRL+C) handling is not implemented yet.
|
|
|
|
- Resource-related functions like ``os.nice`` and most functions of the
|
|
|
|
``resource`` module are not available.
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### threading
|
2022-04-23 20:59:33 +08:00
|
|
|
|
|
|
|
- Threading is disabled by default. The ``configure`` option
|
|
|
|
``--enable-wasm-pthreads`` adds compiler flag ``-pthread`` and
|
2022-11-04 02:27:27 +08:00
|
|
|
linker flags ``-sUSE_PTHREADS -sPROXY_TO_PTHREAD``.
|
2022-04-23 20:59:33 +08:00
|
|
|
- pthread support requires WASM threads and SharedArrayBuffer (bulk memory).
|
|
|
|
The Node.JS runtime keeps a pool of web workers around. Each web worker
|
|
|
|
uses several file descriptors (eventfd, epoll, pipe).
|
|
|
|
- It's not advised to enable threading when building for browsers or with
|
|
|
|
dynamic linking support; there are performance and stability issues.
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### file system
|
2022-04-05 17:21:11 +08:00
|
|
|
|
2022-02-06 03:52:01 +08:00
|
|
|
- Most user, group, and permission related function and modules are not
|
|
|
|
supported or don't work as expected, e.g.``pwd`` module, ``grp`` module,
|
2023-01-18 08:06:38 +08:00
|
|
|
``os.setgroups``, ``os.chown``, and so on. ``lchown`` and ``lchmod`` are
|
2022-04-05 01:31:31 +08:00
|
|
|
not available.
|
|
|
|
- ``umask`` is a no-op.
|
|
|
|
- hard links (``os.link``) are not supported.
|
2022-02-06 03:52:01 +08:00
|
|
|
- Offset and iovec I/O functions (e.g. ``os.pread``, ``os.preadv``) are not
|
|
|
|
available.
|
|
|
|
- ``os.mknod`` and ``os.mkfifo``
|
|
|
|
[don't work](https://github.com/emscripten-core/emscripten/issues/16158)
|
|
|
|
and are disabled.
|
|
|
|
- Large file support crashes the runtime and is disabled.
|
|
|
|
- ``mmap`` module is unstable. flush (``msync``) can crash the runtime.
|
2022-04-05 17:21:11 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Misc
|
2022-04-05 17:21:11 +08:00
|
|
|
|
|
|
|
- Heap memory and stack size are limited. Recursion or extensive memory
|
|
|
|
consumption can crash Python.
|
|
|
|
- Most stdlib modules with a dependency on external libraries are missing,
|
2022-07-27 14:18:34 +08:00
|
|
|
e.g. ``ctypes``, ``readline``, ``ssl``, and more.
|
2022-04-05 17:21:11 +08:00
|
|
|
- Shared extension modules are not implemented yet. All extension modules
|
2022-04-23 15:52:16 +08:00
|
|
|
are statically linked into the main binary. The experimental configure
|
|
|
|
option ``--enable-wasm-dynamic-linking`` enables dynamic extensions
|
|
|
|
supports. It's currently known to crash in combination with threading.
|
2022-04-05 01:31:31 +08:00
|
|
|
- glibc extensions for date and time formatting are not available.
|
2022-02-06 03:52:01 +08:00
|
|
|
- ``locales`` module is affected by musl libc issues,
|
2023-01-18 08:06:38 +08:00
|
|
|
[gh-90548](https://github.com/python/cpython/issues/90548).
|
2022-02-06 03:52:01 +08:00
|
|
|
- Python's object allocator ``obmalloc`` is disabled by default.
|
|
|
|
- ``ensurepip`` is not available.
|
2022-06-24 18:40:43 +08:00
|
|
|
- Some ``ctypes`` features like ``c_longlong`` and ``c_longdouble`` may need
|
|
|
|
NodeJS option ``--experimental-wasm-bigint``.
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### In the browser
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-04-05 17:21:11 +08:00
|
|
|
- The interactive shell does not handle copy 'n paste and unicode support
|
|
|
|
well.
|
2022-02-06 03:52:01 +08:00
|
|
|
- The bundled stdlib is limited. Network-related modules,
|
2022-11-04 02:27:27 +08:00
|
|
|
multiprocessing, dbm, tests and similar modules
|
2022-02-06 03:52:01 +08:00
|
|
|
are not shipped. All other modules are bundled as pre-compiled
|
|
|
|
``pyc`` files.
|
2022-04-05 17:21:11 +08:00
|
|
|
- In-memory file system (MEMFS) is not persistent and limited.
|
2022-04-23 15:52:16 +08:00
|
|
|
- Test modules are disabled by default. Use ``--enable-test-modules`` build
|
|
|
|
test modules like ``_testcapi``.
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
### wasm32-emscripten in node
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-04-23 20:59:33 +08:00
|
|
|
Node builds use ``NODERAWFS``.
|
2022-02-06 03:52:01 +08:00
|
|
|
|
2022-04-23 20:59:33 +08:00
|
|
|
- Node RawFS allows direct access to the host file system without need to
|
|
|
|
perform ``FS.mount()`` call.
|
2022-04-10 15:29:51 +08:00
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
### wasm64-emscripten
|
2022-08-14 03:56:08 +08:00
|
|
|
|
|
|
|
- wasm64 requires recent NodeJS and ``--experimental-wasm-memory64``.
|
|
|
|
- ``EM_JS`` functions must return ``BigInt()``.
|
|
|
|
- ``Py_BuildValue()`` format strings must match size of types. Confusing 32
|
|
|
|
and 64 bits types leads to memory corruption, see
|
|
|
|
[gh-95876](https://github.com/python/cpython/issues/95876) and
|
|
|
|
[gh-95878](https://github.com/python/cpython/issues/95878).
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
### Hosting Python WASM builds
|
2022-04-10 15:29:51 +08:00
|
|
|
|
|
|
|
The simple REPL terminal uses SharedArrayBuffer. For security reasons
|
|
|
|
browsers only provide the feature in secure environents with cross-origin
|
|
|
|
isolation. The webserver must send cross-origin headers and correct MIME types
|
|
|
|
for the JavaScript and WASM files. Otherwise the terminal will fail to load
|
|
|
|
with an error message like ``Browsers disable shared array buffer``.
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
#### Apache HTTP .htaccess
|
2022-04-10 15:29:51 +08:00
|
|
|
|
|
|
|
Place a ``.htaccess`` file in the same directory as ``python.wasm``.
|
|
|
|
|
|
|
|
```
|
|
|
|
# .htaccess
|
|
|
|
Header set Cross-Origin-Opener-Policy same-origin
|
|
|
|
Header set Cross-Origin-Embedder-Policy require-corp
|
|
|
|
|
|
|
|
AddType application/javascript js
|
|
|
|
AddType application/wasm wasm
|
|
|
|
|
|
|
|
<IfModule mod_deflate.c>
|
|
|
|
AddOutputFilterByType DEFLATE text/html application/javascript application/wasm
|
|
|
|
</IfModule>
|
|
|
|
```
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
## WASI (wasm32-wasi)
|
2022-04-23 15:52:16 +08:00
|
|
|
|
2024-03-07 10:38:00 +08:00
|
|
|
See [the devguide on how to build and run for WASI](https://devguide.python.org/getting-started/setup-building/#wasi).
|
2023-06-03 06:15:41 +08:00
|
|
|
|
2023-12-01 05:01:07 +08:00
|
|
|
## Detecting WebAssembly builds
|
2023-06-03 06:15:41 +08:00
|
|
|
|
|
|
|
### Python code
|
2022-04-10 15:29:51 +08:00
|
|
|
|
2022-04-23 15:52:16 +08:00
|
|
|
```python
|
2022-04-10 15:29:51 +08:00
|
|
|
import os, sys
|
|
|
|
|
|
|
|
if sys.platform == "emscripten":
|
|
|
|
# Python on Emscripten
|
2023-11-30 08:18:25 +08:00
|
|
|
...
|
2022-04-10 15:29:51 +08:00
|
|
|
if sys.platform == "wasi":
|
|
|
|
# Python on WASI
|
2023-11-30 08:18:25 +08:00
|
|
|
...
|
2022-04-10 15:29:51 +08:00
|
|
|
|
|
|
|
if os.name == "posix":
|
|
|
|
# WASM platforms identify as POSIX-like.
|
|
|
|
# Windows does not provide os.uname().
|
|
|
|
machine = os.uname().machine
|
|
|
|
if machine.startswith("wasm"):
|
2023-11-30 08:18:25 +08:00
|
|
|
# WebAssembly (wasm32, wasm64 potentially in the future)
|
2022-04-23 15:52:16 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
```python
|
|
|
|
>>> import os, sys
|
|
|
|
>>> os.uname()
|
2022-09-11 15:51:23 +08:00
|
|
|
posix.uname_result(
|
|
|
|
sysname='Emscripten',
|
|
|
|
nodename='emscripten',
|
|
|
|
release='3.1.19',
|
|
|
|
version='#1',
|
|
|
|
machine='wasm32'
|
|
|
|
)
|
2022-04-23 15:52:16 +08:00
|
|
|
>>> os.name
|
|
|
|
'posix'
|
|
|
|
>>> sys.platform
|
|
|
|
'emscripten'
|
|
|
|
>>> sys._emscripten_info
|
|
|
|
sys._emscripten_info(
|
2022-09-11 15:51:23 +08:00
|
|
|
emscripten_version=(3, 1, 10),
|
|
|
|
runtime='Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0',
|
2022-04-23 15:52:16 +08:00
|
|
|
pthreads=False,
|
|
|
|
shared_memory=False
|
|
|
|
)
|
2022-09-11 15:51:23 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
```python
|
2022-04-23 15:52:16 +08:00
|
|
|
>>> sys._emscripten_info
|
2022-09-11 15:51:23 +08:00
|
|
|
sys._emscripten_info(
|
|
|
|
emscripten_version=(3, 1, 19),
|
|
|
|
runtime='Node.js v14.18.2',
|
|
|
|
pthreads=True,
|
|
|
|
shared_memory=True
|
|
|
|
)
|
2022-04-23 15:52:16 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
```python
|
|
|
|
>>> import os, sys
|
|
|
|
>>> os.uname()
|
2022-09-11 15:51:23 +08:00
|
|
|
posix.uname_result(
|
|
|
|
sysname='wasi',
|
|
|
|
nodename='(none)',
|
|
|
|
release='0.0.0',
|
|
|
|
version='0.0.0',
|
|
|
|
machine='wasm32'
|
|
|
|
)
|
2022-04-23 15:52:16 +08:00
|
|
|
>>> os.name
|
|
|
|
'posix'
|
|
|
|
>>> sys.platform
|
|
|
|
'wasi'
|
2022-04-10 15:29:51 +08:00
|
|
|
```
|
|
|
|
|
2023-06-03 06:15:41 +08:00
|
|
|
### C code
|
2022-04-10 15:29:51 +08:00
|
|
|
|
|
|
|
Emscripten SDK and WASI SDK define several built-in macros. You can dump a
|
|
|
|
full list of built-ins with ``emcc -dM -E - < /dev/null`` and
|
|
|
|
``/path/to/wasi-sdk/bin/clang -dM -E - < /dev/null``.
|
|
|
|
|
|
|
|
* WebAssembly ``__wasm__`` (also ``__wasm``)
|
|
|
|
* wasm32 ``__wasm32__`` (also ``__wasm32``)
|
|
|
|
* wasm64 ``__wasm64__``
|
|
|
|
* Emscripten ``__EMSCRIPTEN__`` (also ``EMSCRIPTEN``)
|
|
|
|
* Emscripten version ``__EMSCRIPTEN_major__``, ``__EMSCRIPTEN_minor__``, ``__EMSCRIPTEN_tiny__``
|
|
|
|
* WASI ``__wasi__``
|