Skip to content

Commit

Permalink
feat: add Pyodide support
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com>
  • Loading branch information
3 people committed May 18, 2024
1 parent 78bca57 commit a132afd
Show file tree
Hide file tree
Showing 22 changed files with 617 additions and 48 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,38 @@ jobs:
- name: Run the emulation tests
run: |
pytest --run-emulation test/test_emulation.py
test-pyodide:
name: Test cibuildwheel building pyodide wheels
needs: lint
runs-on: ubuntu-20.04
timeout-minutes: 180
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python 3.11
with:
python-version: '3.11'


- name: Install dependencies
run: |
python -m pip install ".[test]"
- name: Generate a sample project
run: |
python -m test.test_projects test.test_0_basic.basic_project sample_proj
- name: Run a sample build (GitHub Action)
uses: ./
with:
package-dir: sample_proj
output-dir: wheelhouse
env:
CIBW_PLATFORM: pyodide

- name: Run tests with 'CIBW_PLATFORM' set to 'pyodide'
run: |
python ./bin/run_tests.py
env:
CIBW_PLATFORM: pyodide
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ What does it do?
- Works on GitHub Actions, Azure Pipelines, Travis CI, AppVeyor, CircleCI, GitLab CI, and Cirrus CI
- Bundles shared library dependencies on Linux and macOS through [auditwheel](https://github.com/pypa/auditwheel) and [delocate](https://github.com/matthew-brett/delocate)
- Runs your library's tests against the wheel-installed version of your library
- Can also build pyodide wheels for web deployment (experimental, not supported on PyPI yet) with `--platform pyodide`

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.

Expand Down
7 changes: 6 additions & 1 deletion cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cibuildwheel
import cibuildwheel.linux
import cibuildwheel.macos
import cibuildwheel.pyodide
import cibuildwheel.util
import cibuildwheel.windows
from cibuildwheel._compat.typing import assert_never
Expand Down Expand Up @@ -45,7 +46,7 @@ def main() -> None:

parser.add_argument(
"--platform",
choices=["auto", "linux", "macos", "windows"],
choices=["auto", "linux", "macos", "windows", "pyodide"],
default=None,
help="""
Platform to build for. Use this option to override the
Expand Down Expand Up @@ -176,6 +177,8 @@ def _compute_platform_only(only: str) -> PlatformName:
return "macos"
if "win_" in only or "win32" in only:
return "windows"
if "pyodide_" in only:
return "pyodide"
print(
f"Invalid --only='{only}', must be a build selector with a known platform",
file=sys.stderr,
Expand Down Expand Up @@ -246,6 +249,8 @@ def get_platform_module(platform: PlatformName) -> PlatformModule:
return cibuildwheel.windows
if platform == "macos":
return cibuildwheel.macos
if platform == "pyodide":
return cibuildwheel.pyodide
assert_never(platform)


Expand Down
8 changes: 8 additions & 0 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"pyodide": "Pyodide",
}

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

# WebAssembly
wasm32 = "wasm32"

# Allow this to be sorted
def __lt__(self, other: Architecture) -> bool:
return self.value < other.value
Expand Down Expand Up @@ -75,6 +79,9 @@ def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
def auto_archs(platform: PlatformName) -> set[Architecture]:
native_machine = platform_module.machine()

if platform == "pyodide":
return {Architecture.wasm32}

# Cross-platform support. Used for --print-build-identifiers or docker builds.
host_platform: PlatformName = (
"windows"
Expand Down Expand Up @@ -120,6 +127,7 @@ def all_archs(platform: PlatformName) -> set[Architecture]:
},
"macos": {Architecture.x86_64, Architecture.arm64, Architecture.universal2},
"windows": {Architecture.x86, Architecture.AMD64, Architecture.ARM64},
"pyodide": {Architecture.wasm32},
}
return all_archs_map[platform]

Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"macosx_x86_64": "macOS x86_64",
"macosx_universal2": "macOS Universal 2 - x86_64 and arm64",
"macosx_arm64": "macOS arm64 - Apple Silicon",
"pyodide_wasm32": "Pyodide v0.23.x",
}


Expand Down
Loading

0 comments on commit a132afd

Please sign in to comment.