Skip to content

Commit a132afd

Browse files
henryiiihoodmanemayeut
committed
feat: add Pyodide support
Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Hood Chatham <[email protected]> Co-authored-by: Matthieu Darbois <[email protected]>
1 parent 78bca57 commit a132afd

22 files changed

+617
-48
lines changed

.github/workflows/test.yml

+35
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,38 @@ jobs:
148148
- name: Run the emulation tests
149149
run: |
150150
pytest --run-emulation test/test_emulation.py
151+
152+
test-pyodide:
153+
name: Test cibuildwheel building pyodide wheels
154+
needs: lint
155+
runs-on: ubuntu-20.04
156+
timeout-minutes: 180
157+
steps:
158+
- uses: actions/checkout@v3
159+
- uses: actions/setup-python@v4
160+
name: Install Python 3.11
161+
with:
162+
python-version: '3.11'
163+
164+
165+
- name: Install dependencies
166+
run: |
167+
python -m pip install ".[test]"
168+
169+
- name: Generate a sample project
170+
run: |
171+
python -m test.test_projects test.test_0_basic.basic_project sample_proj
172+
173+
- name: Run a sample build (GitHub Action)
174+
uses: ./
175+
with:
176+
package-dir: sample_proj
177+
output-dir: wheelhouse
178+
env:
179+
CIBW_PLATFORM: pyodide
180+
181+
- name: Run tests with 'CIBW_PLATFORM' set to 'pyodide'
182+
run: |
183+
python ./bin/run_tests.py
184+
env:
185+
CIBW_PLATFORM: pyodide

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ What does it do?
4545
- Works on GitHub Actions, Azure Pipelines, Travis CI, AppVeyor, CircleCI, GitLab CI, and Cirrus CI
4646
- Bundles shared library dependencies on Linux and macOS through [auditwheel](https://github.com/pypa/auditwheel) and [delocate](https://github.com/matthew-brett/delocate)
4747
- Runs your library's tests against the wheel-installed version of your library
48+
- Can also build pyodide wheels for web deployment (experimental, not supported on PyPI yet) with `--platform pyodide`
4849

4950
See the [cibuildwheel 1 documentation](https://cibuildwheel.pypa.io/en/1.x/) if you need to build unsupported versions of Python, such as Python 2.
5051

cibuildwheel/__main__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import cibuildwheel
1616
import cibuildwheel.linux
1717
import cibuildwheel.macos
18+
import cibuildwheel.pyodide
1819
import cibuildwheel.util
1920
import cibuildwheel.windows
2021
from cibuildwheel._compat.typing import assert_never
@@ -45,7 +46,7 @@ def main() -> None:
4546

4647
parser.add_argument(
4748
"--platform",
48-
choices=["auto", "linux", "macos", "windows"],
49+
choices=["auto", "linux", "macos", "windows", "pyodide"],
4950
default=None,
5051
help="""
5152
Platform to build for. Use this option to override the
@@ -176,6 +177,8 @@ def _compute_platform_only(only: str) -> PlatformName:
176177
return "macos"
177178
if "win_" in only or "win32" in only:
178179
return "windows"
180+
if "pyodide_" in only:
181+
return "pyodide"
179182
print(
180183
f"Invalid --only='{only}', must be a build selector with a known platform",
181184
file=sys.stderr,
@@ -246,6 +249,8 @@ def get_platform_module(platform: PlatformName) -> PlatformModule:
246249
return cibuildwheel.windows
247250
if platform == "macos":
248251
return cibuildwheel.macos
252+
if platform == "pyodide":
253+
return cibuildwheel.pyodide
249254
assert_never(platform)
250255

251256

cibuildwheel/architecture.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"linux": "Linux",
1616
"macos": "macOS",
1717
"windows": "Windows",
18+
"pyodide": "Pyodide",
1819
}
1920

2021
ARCH_SYNONYMS: Final[list[dict[PlatformName, str | None]]] = [
@@ -46,6 +47,9 @@ class Architecture(Enum):
4647
AMD64 = "AMD64"
4748
ARM64 = "ARM64"
4849

50+
# WebAssembly
51+
wasm32 = "wasm32"
52+
4953
# Allow this to be sorted
5054
def __lt__(self, other: Architecture) -> bool:
5155
return self.value < other.value
@@ -75,6 +79,9 @@ def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
7579
def auto_archs(platform: PlatformName) -> set[Architecture]:
7680
native_machine = platform_module.machine()
7781

82+
if platform == "pyodide":
83+
return {Architecture.wasm32}
84+
7885
# Cross-platform support. Used for --print-build-identifiers or docker builds.
7986
host_platform: PlatformName = (
8087
"windows"
@@ -120,6 +127,7 @@ def all_archs(platform: PlatformName) -> set[Architecture]:
120127
},
121128
"macos": {Architecture.x86_64, Architecture.arm64, Architecture.universal2},
122129
"windows": {Architecture.x86, Architecture.AMD64, Architecture.ARM64},
130+
"pyodide": {Architecture.wasm32},
123131
}
124132
return all_archs_map[platform]
125133

cibuildwheel/logger.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"macosx_x86_64": "macOS x86_64",
3535
"macosx_universal2": "macOS Universal 2 - x86_64 and arm64",
3636
"macosx_arm64": "macOS arm64 - Apple Silicon",
37+
"pyodide_wasm32": "Pyodide v0.23.x",
3738
}
3839

3940

0 commit comments

Comments
 (0)