Skip to content

Commit 6a68049

Browse files
emmatypingwesleywright
authored andcommitted
Fix sys.platform when cross-compiling with emscripten (#14888)
This is a workaround for correctly detecting the platform when building mypy with mypyc on the Emscripten platform. This fixes mypyc/mypy_mypyc-wheels#62. `pyodide build` overrides `sysconfig` for the host based on the target (confirmed on the pyodide matrix, [see also where the code is actually changed](https://github.com/pyodide/pyodide/blob/e835bf05ff4aa463024aaeb9689ae70ea5771314/pyodide-build/pyodide_build/pypabuild.py#L43-L50)). This should only change things when checking/building for the emscripten platform. There isn't really a cleaner workaround that I can think of unfortunately, the main issue is cross compiling is tricky with setuptools.
1 parent 3d9661c commit 6a68049

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mypy/options.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pprint
44
import re
55
import sys
6+
import sysconfig
67
from typing import Any, Callable, Dict, Mapping, Pattern
78
from typing_extensions import Final
89

@@ -86,7 +87,15 @@ def __init__(self) -> None:
8687
# The executable used to search for PEP 561 packages. If this is None,
8788
# then mypy does not search for PEP 561 packages.
8889
self.python_executable: str | None = sys.executable
89-
self.platform = sys.platform
90+
91+
# When cross compiling to emscripten, we need to rely on MACHDEP because
92+
# sys.platform is the host build platform, not emscripten.
93+
MACHDEP = sysconfig.get_config_var("MACHDEP")
94+
if MACHDEP == "emscripten":
95+
self.platform = MACHDEP
96+
else:
97+
self.platform = sys.platform
98+
9099
self.custom_typing_module: str | None = None
91100
self.custom_typeshed_dir: str | None = None
92101
# The abspath() version of the above, we compute it once as an optimization.

0 commit comments

Comments
 (0)