Skip to content

Commit 3ef9d3a

Browse files
committed
WASM build
1 parent 7522960 commit 3ef9d3a

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

.github/workflows/release-wasm.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17+
- name: Setup Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.11'
21+
- name: Install dependencies
22+
run: |
23+
make install_deps
24+
if [ -d .venv ]; then .venv/bin/pip install py2wasm; else pip install py2wasm; fi
25+
1726
- name: Build WASM
1827
run: |
19-
if [ -f Makefile ] && grep -q build_wasm Makefile; then
20-
make build_wasm || true
21-
cp bin/cdd-python-all.wasm . || echo -n -e '\x00asm\x01\x00\x00\x00' > cdd-python-all.wasm
22-
else
23-
echo -n -e '\x00asm\x01\x00\x00\x00' > cdd-python-all.wasm
24-
fi
28+
make build_wasm
29+
cp bin/cdd-python-all.wasm .
2530
- name: Release WASM Artifact
2631
uses: softprops/action-gh-release@v2
2732
with:

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ build:
4848
uv build --wheel --out-dir $(BIN_DIR)
4949

5050
build_wasm:
51-
@echo "Building WASM to dist/wasm"
52-
@mkdir -p dist/wasm
53-
@echo "A full CPython WASM standalone build requires Pyodide. Stubbed for now." > dist/wasm/README.txt
51+
@echo "Building WASM to bin/"
52+
@mkdir -p bin
53+
if [ -d .venv ]; then .venv/bin/python3 -m py2wasm src/openapi_client/cli.py -o bin/cdd-python-all.wasm; else py2wasm src/openapi_client/cli.py -o bin/cdd-python-all.wasm; fi
5454

5555
test:
5656
.venv/bin/python3 -m pytest tests/ || pytest tests/

WASM.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ Compiling a pure Python application to a standalone `.wasm` binary that can run
44

55
## Current Status
66

7-
**Is WASM support possible?** Yes, using Pyodide or similar tools.
8-
**Is it implemented?** Partial. A stub target `build_wasm` exists in `Makefile`, but true standalone WASM builds of this Python CLI are not fully implemented.
9-
10-
To implement this fully in the future, we could compile a custom Pyodide environment using the Emscripten SDK (`emsdk`) found in `../emsdk`, bundle `openapi-python-client` into the virtual filesystem, and output a packaged JS/WASM bundle that exposes the `cdd-python` CLI via a JavaScript wrapper.
7+
**Is WASM support possible?** Yes, using `py2wasm`.
8+
**Is it implemented?** Yes. A `build_wasm` target exists in `Makefile` which compiles the CLI to a standalone `.wasm` binary.
9+
10+
To build it manually:
11+
```bash
12+
pip install py2wasm
13+
make build_wasm
14+
```
15+
This produces `bin/cdd-python-all.wasm`.

make.bat

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ mkdir "%BIN_DIR%" 2>NUL
5959
goto :EOF
6060

6161
:build_wasm
62-
echo Building WASM to dist\wasm
63-
mkdir dist\wasm 2>NUL
64-
echo A full CPython WASM standalone build requires Pyodide. Stubbed for now. > dist\wasm\README.txt
62+
echo Building WASM to bin\
63+
mkdir bin 2>NUL
64+
if exist .venv\Scripts\python.exe (
65+
.venv\Scripts\python.exe -m py2wasm src\openapi_client\cli.py -o bin\cdd-python-all.wasm
66+
) else (
67+
py2wasm src\openapi_client\cli.py -o bin\cdd-python-all.wasm
68+
)
6569
goto :EOF
6670

6771
:test

0 commit comments

Comments
 (0)