File tree Expand file tree Collapse file tree 12 files changed +667
-597
lines changed
Expand file tree Collapse file tree 12 files changed +667
-597
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,7 @@ Tools/wasm/config.site-wasm32-emscripten @freakboy3742 @emmatyping
176176Tools /wasm /emscripten @ freakboy3742 @ emmatyping
177177
178178# WebAssembly (WASI)
179+ platforms / WASI @ brettcannon @ emmatyping @ savannahostrowski
179180Tools /wasm /wasi-env @ brettcannon @ emmatyping @ savannahostrowski
180181Tools /wasm /wasi.py @ brettcannon @ emmatyping @ savannahostrowski
181182Tools /wasm /wasi @ brettcannon @ emmatyping @ savannahostrowski
Original file line number Diff line number Diff line change @@ -47,14 +47,14 @@ jobs:
4747 - name : " Runner image version"
4848 run : echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
4949 - name : " Configure build Python"
50- run : python3 Tools/wasm/wasi configure-build-python -- --config-cache --with-pydebug
50+ run : python3 Platforms/WASI configure-build-python -- --config-cache --with-pydebug
5151 - name : " Make build Python"
52- run : python3 Tools/wasm/wasi make-build-python
52+ run : python3 Platforms/WASI make-build-python
5353 - name : " Configure host"
5454 # `--with-pydebug` inferred from configure-build-python
55- run : python3 Tools/wasm/wasi configure-host -- --config-cache
55+ run : python3 Platforms/WASI configure-host -- --config-cache
5656 - name : " Make host"
57- run : python3 Tools/wasm/wasi make-host
57+ run : python3 Platforms/WASI make-host
5858 - name : " Display build info"
5959 run : make --directory "${CROSS_BUILD_WASI}" pythoninfo
6060 - name : " Test"
Original file line number Diff line number Diff line change 1+ Move WASI-related files to Platforms/WASI. Along the way, leave a deprecated
2+ Tools/wasm/wasi/__main__.py behind for backwards-compatibility.
Original file line number Diff line number Diff line change 1+ extend = " ../../.ruff.toml" # Inherit the project-wide settings
2+
3+ [format ]
4+ preview = true
5+ docstring-code-format = true
6+
7+ [lint ]
8+ select = [
9+ " C4" , # flake8-comprehensions
10+ " E" , # pycodestyle
11+ " F" , # pyflakes
12+ " I" , # isort
13+ " ISC" , # flake8-implicit-str-concat
14+ " LOG" , # flake8-logging
15+ " PGH" , # pygrep-hooks
16+ " PT" , # flake8-pytest-style
17+ " PYI" , # flake8-pyi
18+ " RUF100" , # Ban unused `# noqa` comments
19+ " UP" , # pyupgrade
20+ " W" , # pycodestyle
21+ " YTT" , # flake8-2020
22+ ]
23+ ignore = [
24+ " E501" , # Line too long
25+ ]
Original file line number Diff line number Diff line change 1+ # Python WASI (wasm32-wasi) build
2+
3+ ** WASI support is [ tier 2] ( https://peps.python.org/pep-0011/#tier-2 ) .**
4+
5+ This directory contains configuration and helpers to facilitate cross
6+ compilation of CPython to WebAssembly (WASM) using WASI. WASI builds
7+ use WASM runtimes such as [ wasmtime] ( https://wasmtime.dev/ ) .
8+
9+ ** NOTE** : If you are looking for general information about WebAssembly that is
10+ not directly related to CPython, please see https://github.com/psf/webassembly .
11+
12+ ## Build
13+
14+ See [ the devguide on how to build and run for WASI] ( https://devguide.python.org/getting-started/setup-building/#wasi ) .
15+
16+ ## Detecting WASI builds
17+
18+ ### Python code
19+
20+ ``` python
21+ import os, sys
22+
23+ if sys.platform == " wasi" :
24+ # Python on WASI
25+ ...
26+
27+ if os.name == " posix" :
28+ # WASM platforms identify as POSIX-like.
29+ # Windows does not provide os.uname().
30+ machine = os.uname().machine
31+ if machine.startswith(" wasm" ):
32+ # WebAssembly (wasm32, wasm64 potentially in the future)
33+ ```
34+
35+ ``` python
36+ >> > import os, sys
37+ >> > os.uname()
38+ posix.uname_result(
39+ sysname = ' wasi' ,
40+ nodename = ' (none)' ,
41+ release = ' 0.0.0' ,
42+ version = ' 0.0.0' ,
43+ machine = ' wasm32'
44+ )
45+ >> > os.name
46+ ' posix'
47+ >> > sys.platform
48+ ' wasi'
49+ ```
50+
51+ ### C code
52+
53+ WASI SDK defines several built-in macros. You can dump a full list of built-ins
54+ with `` /path/to/wasi-sdk/bin/clang -dM -E - < /dev/null `` .
55+
56+ * WebAssembly `` __wasm__ `` (also `` __wasm `` )
57+ * wasm32 `` __wasm32__ `` (also `` __wasm32 `` )
58+ * wasm64 `` __wasm64__ ``
59+ * WASI `` __wasi__ ``
You can’t perform that action at this time.
0 commit comments