| 217 | |
| 218 | |
| 219 | def detect_target_arch(): |
| 220 | candidates = [ |
| 221 | os.environ.get('TARGET_ARCH'), |
| 222 | os.environ.get('npm_config_arch'), |
| 223 | os.environ.get('VSCMD_ARG_TGT_ARCH'), |
| 224 | os.environ.get('Platform'), |
| 225 | os.environ.get('PROCESSOR_ARCHITECTURE'), |
| 226 | platform.machine(), |
| 227 | ] |
| 228 | |
| 229 | aliases = { |
| 230 | 'amd64': 'x64', |
| 231 | 'x86_64': 'x64', |
| 232 | 'x64': 'x64', |
| 233 | 'win32': 'x64', |
| 234 | 'i386': 'ia32', |
| 235 | 'i686': 'ia32', |
| 236 | 'ia32': 'ia32', |
| 237 | 'x86': 'ia32', |
| 238 | 'arm64': 'arm64', |
| 239 | 'aarch64': 'arm64', |
| 240 | 'arm': 'arm', |
| 241 | 'riscv64': 'riscv64', |
| 242 | 'loong64': 'loong64', |
| 243 | 'ppc64': 'ppc64', |
| 244 | 'mips': 'mips', |
| 245 | 'mipsel': 'mipsel', |
| 246 | 'mips64el': 'mips64el', |
| 247 | } |
| 248 | |
| 249 | for candidate in candidates: |
| 250 | if not candidate: |
| 251 | continue |
| 252 | normalized = aliases.get(candidate.lower()) |
| 253 | if normalized is not None: |
| 254 | return normalized |
| 255 | |
| 256 | raise ValueError('Unable to determine target architecture for libffi headers') |
| 257 | |
| 258 | |
| 259 | def main(argv=None): |