Skip to content

Commit 8d75eb7

Browse files
Apply Pyodide-specific patches to our Emscripten toolchain installation (#2800)
Co-authored-by: Joe Rickerby <joerick@mac.com>
1 parent 8d2b08b commit 8d75eb7

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

cibuildwheel/platforms/pyodide.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,28 @@ def ensure_node(major_version: str) -> Path:
9494
return path
9595

9696

97-
def install_emscripten(tmp: Path, version: str) -> Path:
98-
url = f"https://github.com/emscripten-core/emsdk/archive/refs/tags/{version}.zip"
99-
installation_path = CIBW_CACHE_PATH / f"emsdk-{version}"
100-
emsdk_path = installation_path / f"emsdk-{version}/emsdk"
101-
emcc_path = installation_path / f"emsdk-{version}/upstream/emscripten/emcc"
102-
with FileLock(f"{installation_path}.lock"):
103-
if installation_path.exists():
97+
def install_emscripten(
98+
env: dict[str, str], version: str, xbuildenv_cache_path: Path, pyodide_version: str
99+
) -> Path:
100+
"""Install Emscripten via pyodide-build, which also applies Pyodide-specific patches."""
101+
emcc_path = (
102+
xbuildenv_cache_path / pyodide_version / "emsdk" / "upstream" / "emscripten" / "emcc"
103+
)
104+
with FileLock(CIBW_CACHE_PATH / "emscripten.lock"):
105+
if emcc_path.exists():
104106
return emcc_path
105-
emsdk_zip = tmp / "emsdk.zip"
106-
download(url, emsdk_zip)
107-
installation_path.mkdir()
108-
extract_zip(emsdk_zip, installation_path)
109-
call(emsdk_path, "install", version)
110-
call(emsdk_path, "activate", version)
111-
107+
call(
108+
"pyodide",
109+
"xbuildenv",
110+
"install-emscripten",
111+
"--version",
112+
version,
113+
"--path",
114+
str(xbuildenv_cache_path),
115+
env=env,
116+
cwd=CIBW_CACHE_PATH,
117+
)
118+
assert emcc_path.exists()
112119
return emcc_path
113120

114121

@@ -180,12 +187,8 @@ def validate_pyodide_build_version(
180187
raise errors.FatalError(msg)
181188

182189

183-
def install_xbuildenv(env: dict[str, str], pyodide_build_version: str, pyodide_version: str) -> str:
190+
def install_xbuildenv(env: dict[str, str], xbuildenv_cache_path: Path, pyodide_version: str) -> str:
184191
"""Install a particular Pyodide xbuildenv version and set a path to the Pyodide root."""
185-
# Since pyodide-build was unvendored from Pyodide v0.27.0, the versions of
186-
# pyodide-build are uncoupled from the versions of Pyodide. So, we specify
187-
# both the pyodide-build version and the Pyodide version in the temp path.
188-
xbuildenv_cache_path = CIBW_CACHE_PATH / f"pyodide-build-{pyodide_build_version}"
189192
pyodide_root = xbuildenv_cache_path / pyodide_version / "xbuildenv" / "pyodide-root"
190193

191194
with FileLock(CIBW_CACHE_PATH / "xbuildenv.lock"):
@@ -303,15 +306,19 @@ def setup_python(
303306
pyodide_build_version=pyodide_build_version,
304307
)
305308

309+
xbuildenv_cache_path = CIBW_CACHE_PATH / f"pyodide-build-{pyodide_build_version}"
310+
311+
log.step(f"Installing Pyodide xbuildenv version: {pyodide_version} ...")
312+
env["PYODIDE_ROOT"] = install_xbuildenv(env, xbuildenv_cache_path, pyodide_version)
313+
306314
emscripten_version = xbuildenv_info["emscripten"]
307-
log.step(f"Installing Emscripten version: {emscripten_version} ...")
308-
emcc_path = install_emscripten(tmp, emscripten_version)
315+
log.step(
316+
f"Installing Emscripten {emscripten_version} and applying Pyodide-specific patches ..."
317+
)
318+
emcc_path = install_emscripten(env, emscripten_version, xbuildenv_cache_path, pyodide_version)
309319

310320
env["PATH"] = os.pathsep.join([str(emcc_path.parent), env["PATH"]])
311321

312-
log.step(f"Installing Pyodide xbuildenv version: {pyodide_version} ...")
313-
env["PYODIDE_ROOT"] = install_xbuildenv(env, pyodide_build_version, pyodide_version)
314-
315322
return env
316323

317324

0 commit comments

Comments
 (0)