Skip to content

Commit c4867e5

Browse files
committed
debug
1 parent 5f77065 commit c4867e5

3 files changed

Lines changed: 41 additions & 49 deletions

File tree

‎.github/workflows/debug.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ jobs:
5252

5353
- run: python -m pip install .
5454

55-
- run: python -c 'import sysconfig; print(sysconfig.get_platform())'
56-
- run: python -c 'import platform; print(platform.machine())'
57-
- run: python -c 'import mesonpy._windows as w; print(w.platform()); print(w.pp())'
55+
- run: python -c 'import mesonpy._windows as w; w.detect()'

‎mesonpy/__init__.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ def _showwarning(message: Union[Warning, str], category: Type[Warning], filename
233233
_log(f'{style.WARNING}meson-python: warning:{style.RESET} {message}')
234234

235235

236+
def _windows_interpreter_arch() -> str:
237+
"""Return the Windows architecture for which the Python interpreter has been compiled."""
238+
match sysconfig.get_platform():
239+
case 'win32':
240+
return 'x86'
241+
case 'win-amd64':
242+
return 'amd64'
243+
case 'win-arm64':
244+
return 'arm64'
245+
raise ValueError
246+
247+
236248
class _clicounter:
237249
def __init__(self, total: int) -> None:
238250
self._total = total
@@ -826,6 +838,13 @@ def __init__(self,
826838
self._meson_cross_file.write_text(cross_file_data, encoding='utf-8')
827839
self._meson_args['setup'].extend(('--cross-file', os.fspath(self._meson_cross_file)))
828840

841+
elif sys.platform == 'win32':
842+
arch = _windows_interpreter_arch()
843+
nativearch = platform.machine().lower()
844+
845+
if arch != nativearch:
846+
pass
847+
829848
# write the native file
830849
native_file_data = textwrap.dedent(f'''
831850
[binaries]

‎mesonpy/_windows.py‎

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,21 @@
1-
import ctypes
2-
from ctypes import wintypes
3-
4-
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
5-
6-
IsWow64Process2 = kernel32.IsWow64Process2
7-
IsWow64Process2.argtypes = [
8-
wintypes.HANDLE,
9-
ctypes.POINTER(wintypes.USHORT),
10-
ctypes.POINTER(wintypes.USHORT),
11-
]
12-
IsWow64Process2.restype = wintypes.BOOL
13-
14-
IMAGE_FILE_MACHINE_UNKNOWN = 0x0000
15-
IMAGE_FILE_MACHINE_AMD64 = 0x8664
16-
IMAGE_FILE_MACHINE_ARM64 = 0xAA64
17-
IMAGE_FILE_MACHINE_I386 = 0x014c
18-
19-
MACHINE = {
20-
IMAGE_FILE_MACHINE_UNKNOWN: 'unknown', # native, no WOW64
21-
IMAGE_FILE_MACHINE_AMD64: 'amd64',
22-
IMAGE_FILE_MACHINE_ARM64: 'arm64',
23-
IMAGE_FILE_MACHINE_I386: 'x86',
24-
}
25-
26-
def platform():
27-
handle = kernel32.GetCurrentProcess()
28-
29-
process = wintypes.USHORT()
30-
native = wintypes.USHORT()
31-
32-
r = IsWow64Process2(handle, ctypes.byref(process), ctypes.byref(native))
33-
if not r:
34-
raise ctypes.WinError(ctypes.get_last_error())
35-
36-
return native.value, process.value, MACHINE[native.value], MACHINE[process.value]
37-
38-
39-
def pp():
40-
import subprocess
41-
42-
result = subprocess.run(
43-
["powershell", "-NoProfile", "-Command", "(Get-CimInstance Win32_Processor).Architecture"],
44-
capture_output=True, text=True, check=True)
45-
46-
return result
1+
import platform
2+
import sysconfig
3+
4+
5+
def _windows_interpreter_arch() -> str:
6+
"""Return the Windows architecture for which the Python interpreter has been compiled."""
7+
match sysconfig.get_platform():
8+
case 'win32':
9+
return 'x86'
10+
case 'win-amd64':
11+
return 'amd64'
12+
case 'win-arm64':
13+
return 'arm64'
14+
raise ValueError
15+
16+
17+
def detect():
18+
arch = _windows_interpreter_arch()
19+
nativearch = platform.machine().lower()
20+
cross = arch != nativearch
21+
print(f'arch={arch} native={nativearch} cross={cross}')

0 commit comments

Comments
 (0)