3
3
import json
4
4
import os
5
5
import shutil
6
+ import platform
6
7
import sys
7
8
import subprocess
8
9
from distutils .cmd import Command
@@ -49,6 +50,7 @@ def initialize_options(self):
49
50
self .release = None
50
51
self .qbuild = None
51
52
self .build_temp = None
53
+ self .plat_name = None
52
54
53
55
def finalize_options (self ):
54
56
self .extensions = [
@@ -84,6 +86,15 @@ def build_extension(self, ext):
84
86
}
85
87
)
86
88
89
+ # If we are on a 64-bit machine, but running a 32-bit Python, then
90
+ # we'll target a 32-bit Rust build.
91
+ # TODO: include --target for all platforms so env vars can't break the build
92
+ target_triple = None
93
+ target_args = []
94
+ if platform .machine () == "AMD64" and self .plat_name == "win32" :
95
+ target_triple = "i686-pc-windows-msvc"
96
+ target_args = ["--target" , target_triple ]
97
+
87
98
# Find where to put the temporary build files created by `cargo`
88
99
metadata_command = [
89
100
"cargo" ,
@@ -119,6 +130,7 @@ def build_extension(self, ext):
119
130
args = (
120
131
["cargo" , "build" , "--manifest-path" , ext .path ]
121
132
+ feature_args
133
+ + target_args
122
134
+ list (ext .args or [])
123
135
)
124
136
if not debug_build :
@@ -132,6 +144,7 @@ def build_extension(self, ext):
132
144
args = (
133
145
["cargo" , "rustc" , "--lib" , "--manifest-path" , ext .path ]
134
146
+ feature_args
147
+ + target_args
135
148
+ list (ext .args or [])
136
149
)
137
150
if not debug_build :
@@ -187,7 +200,7 @@ def build_extension(self, ext):
187
200
suffix = "release"
188
201
189
202
# location of cargo compiled files
190
- artifactsdir = os .path .join (target_dir , suffix )
203
+ artifactsdir = os .path .join (target_dir , target_triple or "" , suffix )
191
204
dylib_paths = []
192
205
193
206
if executable :
0 commit comments