Skip to content

Commit 8ab4008

Browse files
authored
Prepare to using default CPU arch, add detecting available (#201)
1 parent 10648f4 commit 8ab4008

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

_msbuild.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ResourceFile(CSourceFile):
8888
CFunction('get_current_package'),
8989
CFunction('read_alias_package'),
9090
CFunction('broadcast_settings_change'),
91+
CFunction('get_processor_architecture'),
9192
source='src/_native',
9293
RootNamespace='_native',
9394
)

_msbuild_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
CFunction('get_current_package'),
5555
CFunction('read_alias_package'),
5656
CFunction('broadcast_settings_change'),
57+
CFunction('get_processor_architecture'),
5758
source='src/_native',
5859
),
5960
DllPackage('_shellext_test',

src/_native/misc.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,25 @@ PyObject *broadcast_settings_change(PyObject *, PyObject *, PyObject *) {
233233
return Py_GetConstant(Py_CONSTANT_NONE);
234234
}
235235

236+
typedef enum {
237+
CPU_X86 = 0,
238+
CPU_X86_64 = 9,
239+
CPU_ARM = 5,
240+
CPU_ARM64 = 12,
241+
CPU_UNKNOWN = 0xffff
242+
} CpuArchitecture;
243+
244+
PyObject *get_processor_architecture(PyObject *, PyObject *, PyObject *) {
245+
SYSTEM_INFO system_info;
246+
GetNativeSystemInfo(&system_info);
247+
248+
switch (system_info.wProcessorArchitecture) {
249+
case CPU_X86: return PyUnicode_FromString("-32");
250+
case CPU_X86_64: return PyUnicode_FromString("-64");
251+
case CPU_ARM: return PyUnicode_FromString("-arm");
252+
case CPU_ARM64: return PyUnicode_FromString("-arm64");
253+
default: return PyUnicode_FromString("-64"); // x86-64
254+
}
255+
}
256+
236257
}

src/manage/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ def __init__(self, args, root=None):
447447
_set_args.add(k)
448448

449449
if not self.default_platform:
450+
from _native import get_processor_architecture
451+
LOGGER.debug("Get CPU architecture, its prefix is %s", get_processor_architecture())
452+
450453
# Currently, we always default to -64.
451454
self.default_platform = "-64"
452455

0 commit comments

Comments
 (0)