Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Tools/wasm/config.site-wasm32-emscripten @freakboy3742 @emmatyping
Tools/wasm/emscripten @freakboy3742 @emmatyping

# WebAssembly (WASI)
Platforms/WASI @brettcannon @emmatyping @savannahostrowski
Tools/wasm/wasi-env @brettcannon @emmatyping @savannahostrowski
Tools/wasm/wasi.py @brettcannon @emmatyping @savannahostrowski
Tools/wasm/wasi @brettcannon @emmatyping @savannahostrowski
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ jobs:
- name: "Runner image version"
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
- name: "Configure build Python"
run: python3 Tools/wasm/wasi configure-build-python -- --config-cache --with-pydebug
run: python3 Platforms/WASI configure-build-python -- --config-cache --with-pydebug
- name: "Make build Python"
run: python3 Tools/wasm/wasi make-build-python
run: python3 Platforms/WASI make-build-python
- name: "Configure host"
# `--with-pydebug` inferred from configure-build-python
run: python3 Tools/wasm/wasi configure-host -- --config-cache
run: python3 Platforms/WASI configure-host -- --config-cache
- name: "Make host"
run: python3 Tools/wasm/wasi make-host
run: python3 Platforms/WASI make-host
- name: "Display build info"
run: make --directory "${CROSS_BUILD_WASI}" pythoninfo
- name: "Test"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move WASI-related files to Platforms/WASI. Along the way, leave a deprecated
Tools/wasm/wasi/__main__.py behind for backwards-compatibility.
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Move WASI-related files to Platforms/WASI. Along the way, leave a deprecated
Tools/wasm/wasi/__main__.py behind for backwards-compatibility.
Move WASI-related files to :file:`Platforms/WASI`. Along the way, leave a deprecated
:file:`Tools/wasm/wasi/__main__.py` behind for backwards-compatibility.

25 changes: 25 additions & 0 deletions Platforms/WASI/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extend = "../../.ruff.toml" # Inherit the project-wide settings

[format]
preview = true
docstring-code-format = true

[lint]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RUF100", # Ban unused `# noqa` comments
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
ignore = [
"E501", # Line too long
]
59 changes: 59 additions & 0 deletions Platforms/WASI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Python WASI (wasm32-wasi) build

**WASI support is [tier 2](https://peps.python.org/pep-0011/#tier-2).**

This directory contains configuration and helpers to facilitate cross
compilation of CPython to WebAssembly (WASM) using WASI. WASI builds
use WASM runtimes such as [wasmtime](https://wasmtime.dev/).

**NOTE**: If you are looking for general information about WebAssembly that is
not directly related to CPython, please see https://github.com/psf/webassembly.

## Build

See [the devguide on how to build and run for WASI](https://devguide.python.org/getting-started/setup-building/#wasi).

## Detecting WASI builds

### Python code

```python
import os, sys

if sys.platform == "wasi":
# Python on WASI
...

if os.name == "posix":
# WASM platforms identify as POSIX-like.
# Windows does not provide os.uname().
machine = os.uname().machine
if machine.startswith("wasm"):
# WebAssembly (wasm32, wasm64 potentially in the future)
```

```python
>>> import os, sys
>>> os.uname()
posix.uname_result(
sysname='wasi',
nodename='(none)',
release='0.0.0',
version='0.0.0',
machine='wasm32'
)
>>> os.name
'posix'
>>> sys.platform
'wasi'
```

### C code

WASI SDK defines several built-in macros. You can dump a full list of built-ins
with ``/path/to/wasi-sdk/bin/clang -dM -E - < /dev/null``.

* WebAssembly ``__wasm__`` (also ``__wasm``)
* wasm32 ``__wasm32__`` (also ``__wasm32``)
* wasm64 ``__wasm64__``
* WASI ``__wasi__``
Loading
Loading