Skip to content

Commit 2a23f90

Browse files
alexdavidhewitt
andauthored
Attempt to correctly handle 32-bit Python on 64-bit windows (#77)
* Attempt to correctly handle 32-bit Python on 64-bit windows * Update setuptools_rust/build.py Co-authored-by: David Hewitt <[email protected]>
1 parent 7342249 commit 2a23f90

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fix building for 32-bit Python on 64-bit Windows. #[77](https://github.com/PyO3/setuptools-rust/pull/77)
6+
37
## 0.11.0 (2020-08-06)
48

59
- Remove python 2 support. #[53](https://github.com/PyO3/setuptools-rust/pull/53)

setuptools_rust/build.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import shutil
6+
import platform
67
import sys
78
import subprocess
89
from distutils.cmd import Command
@@ -49,6 +50,7 @@ def initialize_options(self):
4950
self.release = None
5051
self.qbuild = None
5152
self.build_temp = None
53+
self.plat_name = None
5254

5355
def finalize_options(self):
5456
self.extensions = [
@@ -84,6 +86,15 @@ def build_extension(self, ext):
8486
}
8587
)
8688

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+
8798
# Find where to put the temporary build files created by `cargo`
8899
metadata_command = [
89100
"cargo",
@@ -119,6 +130,7 @@ def build_extension(self, ext):
119130
args = (
120131
["cargo", "build", "--manifest-path", ext.path]
121132
+ feature_args
133+
+ target_args
122134
+ list(ext.args or [])
123135
)
124136
if not debug_build:
@@ -132,6 +144,7 @@ def build_extension(self, ext):
132144
args = (
133145
["cargo", "rustc", "--lib", "--manifest-path", ext.path]
134146
+ feature_args
147+
+ target_args
135148
+ list(ext.args or [])
136149
)
137150
if not debug_build:
@@ -187,7 +200,7 @@ def build_extension(self, ext):
187200
suffix = "release"
188201

189202
# location of cargo compiled files
190-
artifactsdir = os.path.join(target_dir, suffix)
203+
artifactsdir = os.path.join(target_dir, target_triple or "", suffix)
191204
dylib_paths = []
192205

193206
if executable:

setuptools_rust/setuptools_ext.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def run(self):
2020
log.info("running build_rust")
2121
build_rust = self.get_finalized_command("build_rust")
2222
build_rust.inplace = self.inplace
23+
build_rust.plat_name = self.plat_name
2324
build_rust.run()
2425

2526
build_ext_base_class.run(self)

0 commit comments

Comments
 (0)