Skip to content

Commit a39ce75

Browse files
committed
win arm whl fix
1 parent 06e63d9 commit a39ce75

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

setup.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,56 @@
22
import sys
33
from setuptools import setup, find_packages
44
from setuptools.dist import Distribution
5+
from setuptools.command.bdist_wheel import bdist_wheel
56

67
# Custom distribution to force platform-specific wheel
78
class BinaryDistribution(Distribution):
89
def has_ext_modules(self):
910
return True
1011

12+
# Custom bdist_wheel command to override platform tag
13+
class CustomBdistWheel(bdist_wheel):
14+
def finalize_options(self):
15+
# Call the original finalize_options first to initialize self.bdist_dir
16+
bdist_wheel.finalize_options(self)
17+
18+
# Override the platform tag with our custom one based on ARCHITECTURE env var
19+
if sys.platform.startswith('win'):
20+
# Strip quotes if present
21+
arch = os.environ.get('ARCHITECTURE', 'x64')
22+
if isinstance(arch, str):
23+
arch = arch.strip('"\'')
24+
25+
print(f"Architecture from environment: '{arch}'")
26+
27+
if arch in ['x86', 'win32']:
28+
self.plat_name = "win32"
29+
platform_dir = "win32"
30+
elif arch == 'arm64':
31+
self.plat_name = "win_arm64"
32+
platform_dir = "win_arm64"
33+
else: # Default to x64/amd64
34+
self.plat_name = "win_amd64"
35+
platform_dir = "win_amd64"
36+
37+
# Override the plat_name for the wheel
38+
print(f"Setting wheel platform tag to: {self.plat_name}")
39+
40+
# Force platform-specific paths if bdist_dir is already set
41+
if self.bdist_dir and "win-amd64" in self.bdist_dir:
42+
self.bdist_dir = self.bdist_dir.replace("win-amd64", f"win-{platform_dir}")
43+
print(f"Using build directory: {self.bdist_dir}")
44+
1145
# Find all packages in the current directory
1246
packages = find_packages()
1347

1448
# Determine the architecture and platform tag for the wheel
1549
if sys.platform.startswith('win'):
1650
# Get architecture from environment variable or default to x64
1751
arch = os.environ.get('ARCHITECTURE', 'x64')
52+
# Strip quotes if present
53+
if isinstance(arch, str):
54+
arch = arch.strip('"\'')
1855

1956
# Normalize architecture values
2057
if arch in ['x86', 'win32']:
@@ -68,4 +105,8 @@ def has_ext_modules(self):
68105
'libs/*/vcredist/*', 'libs/*/vcredist/**/*', # Exclude vcredist directories, added here since `'libs/*' is already included`
69106
],
70107
},
108+
# Register custom commands
109+
cmdclass={
110+
'bdist_wheel': CustomBdistWheel,
111+
},
71112
)

0 commit comments

Comments
 (0)