Skip to content

Commit 95b4b79

Browse files
authored
Fix incorrect document regarding pyodide auditwheel (#2752)
* Fix incorrect document for pyodide * Fix incorrect document for pyodide * Fix test
1 parent f046d0a commit 95b4b79

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

docs/options.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ Default:
911911
- on macOS: `'delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}'`
912912
- on Android: There is no default command, but cibuildwheel will add `libc++` to the
913913
wheel if anything links against it. Setting a command will replace this behavior.
914+
- on Pyodide: You can use `pyodide auditwheel repair --libdir /path/to/libraries --output-dir {dest_dir} {wheel}` command to repair the wheel.
915+
Unlike other platforms, this command is not set by default as you need to explicitly
916+
specify the library directory. You might not want to use the libraries in the system
917+
directory, as they are not built for WASM and will not work.
914918
- on other platforms: `''`
915919

916920
A shell command to repair a built wheel by copying external library dependencies into the wheel tree and relinking them.
@@ -938,12 +942,6 @@ Platform-specific environment variables are also available:<br/>
938942

939943
[Delvewheel]: https://github.com/adang1345/delvewheel
940944

941-
!!! tip
942-
When using `--platform pyodide`, `pyodide build` is used to do the build,
943-
which already uses `auditwheel-emscripten` to repair the wheel, so the default
944-
repair command is empty. If there is a way to do this in two steps in the future,
945-
this could change.
946-
947945
#### Examples
948946

949947
!!! tab examples "pyproject.toml"

docs/platforms.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ If there are pre-releases available for a newer Pyodide version, the `pyodide-pr
179179

180180
Currently, it's recommended to run tests using a `python -m` entrypoint, rather than a command line entrypoint, or a shell script. This is because custom entrypoints have some issues in the Pyodide virtual environment. For example, `pytest` may not work as a command line entrypoint, but will work as a `python -m pytest` entrypoint.
181181

182+
### Repairing wheels
183+
184+
Unlike other platforms, cibuildwheel does not set a default [`repair-wheel-command`](options.md#repair-wheel-command) for Pyodide. If your package links shared libraries, you need to explicitly configure the repair command using [`pyodide auditwheel`](https://github.com/pyodide/auditwheel-emscripten):
185+
186+
```toml
187+
[tool.cibuildwheel.pyodide]
188+
repair-wheel-command = "pyodide auditwheel repair --libdir /path/to/libraries --output-dir {dest_dir} {wheel}"
189+
```
190+
191+
The `--libdir` option specifies the directory containing cross-compiled shared libraries for WASM. You should not use the system library directories (e.g. `/usr/lib`), as those libraries are not built for WebAssembly.
192+
182193

183194
## Android {: android}
184195

test/test_pyodide.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,29 @@ def test_filter():
146146
"spam-0.1.0-cp312-cp312-pyodide_2024_0_wasm32.whl",
147147
"spam-0.1.0-cp313-cp313-pyodide_2025_0_wasm32.whl",
148148
]
149-
print("actual_wheels", actual_wheels)
150-
print("expected_wheels", expected_wheels)
151149
assert set(actual_wheels) == set(expected_wheels)
150+
151+
152+
def test_pyodide_repair_wheel(tmp_path):
153+
if sys.platform == "win32":
154+
pytest.skip("pyodide-build doesn't work correctly on Windows")
155+
156+
project_dir = tmp_path / "project"
157+
basic_project.generate(project_dir)
158+
159+
actual_wheels = utils.cibuildwheel_run(
160+
project_dir,
161+
add_args=["--platform", "pyodide"],
162+
add_env={
163+
"CIBW_REPAIR_WHEEL_COMMAND_PYODIDE": (
164+
"pyodide auditwheel repair --libdir /path/to/libraries --output-dir {dest_dir} {wheel}"
165+
),
166+
},
167+
single_python=True,
168+
)
169+
170+
# check that the expected wheels are produced
171+
expected_wheels = [
172+
"spam-0.1.0-cp312-cp312-pyodide_2024_0_wasm32.whl",
173+
]
174+
assert set(actual_wheels) == set(expected_wheels)

0 commit comments

Comments
 (0)