|
2 | 2 | import sys |
3 | 3 | from setuptools import setup, find_packages |
4 | 4 | from setuptools.dist import Distribution |
| 5 | +from setuptools.command.bdist_wheel import bdist_wheel |
5 | 6 |
|
6 | 7 | # Custom distribution to force platform-specific wheel |
7 | 8 | class BinaryDistribution(Distribution): |
8 | 9 | def has_ext_modules(self): |
9 | 10 | return True |
10 | 11 |
|
| 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 | + |
11 | 45 | # Find all packages in the current directory |
12 | 46 | packages = find_packages() |
13 | 47 |
|
14 | 48 | # Determine the architecture and platform tag for the wheel |
15 | 49 | if sys.platform.startswith('win'): |
16 | 50 | # Get architecture from environment variable or default to x64 |
17 | 51 | arch = os.environ.get('ARCHITECTURE', 'x64') |
| 52 | + # Strip quotes if present |
| 53 | + if isinstance(arch, str): |
| 54 | + arch = arch.strip('"\'') |
18 | 55 |
|
19 | 56 | # Normalize architecture values |
20 | 57 | if arch in ['x86', 'win32']: |
@@ -68,4 +105,8 @@ def has_ext_modules(self): |
68 | 105 | 'libs/*/vcredist/*', 'libs/*/vcredist/**/*', # Exclude vcredist directories, added here since `'libs/*' is already included` |
69 | 106 | ], |
70 | 107 | }, |
| 108 | + # Register custom commands |
| 109 | + cmdclass={ |
| 110 | + 'bdist_wheel': CustomBdistWheel, |
| 111 | + }, |
71 | 112 | ) |
0 commit comments