Skip to content

Commit f6ff544

Browse files
authored
Merge branch 'main' into py-limited-api
2 parents f6b4f51 + 956e41c commit f6ff544

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## Unreleased
44
### Added
5+
- Add `--target` command line option for specifying target triple. [#136](https://github.com/PyO3/setuptools-rust/pull/136)
56
- Add new default `"auto"` setting for `RustExtension.py_limited_api`. [#137](https://github.com/PyO3/setuptools-rust/pull/137)
7+
- Support very verbose cargo build.rs output. [#140](https://github.com/PyO3/setuptools-rust/pull/140)
68

79
### Removed
810
- Remove `test_rust` command. (`python setup.py test` is deprecated.) [#129](https://github.com/PyO3/setuptools-rust/pull/129)

setuptools_rust/build.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class build_rust(RustCommand):
3939
"t",
4040
"directory for temporary files (cargo 'target' directory) ",
4141
),
42+
("target", None, "Build for the target triple"),
4243
]
4344
boolean_options = ["inplace", "debug", "release", "qbuild"]
4445

@@ -50,6 +51,7 @@ def initialize_options(self):
5051
self.qbuild = None
5152
self.build_temp = None
5253
self.plat_name = None
54+
self.target = os.getenv("CARGO_BUILD_TARGET")
5355

5456
def finalize_options(self):
5557
super().finalize_options()
@@ -66,9 +68,9 @@ def get_target_triple(self):
6668
# If we are on a 64-bit machine, but running a 32-bit Python, then
6769
# we'll target a 32-bit Rust build.
6870
# Automatic target detection can be overridden via the CARGO_BUILD_TARGET
69-
# environment variable.
70-
if os.getenv("CARGO_BUILD_TARGET"):
71-
return os.environ["CARGO_BUILD_TARGET"]
71+
# environment variable or --target command line option
72+
if self.target:
73+
return self.target
7274
elif self.plat_name == "win32":
7375
return "i686-pc-windows-msvc"
7476
elif self.plat_name == "win-amd64":
@@ -166,7 +168,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
166168
if quiet:
167169
args.append("-q")
168170
elif self.verbose:
169-
args.append("--verbose")
171+
# cargo only have -vv
172+
verbose_level = 'v' * min(self.verbose, 2)
173+
args.append(f"-{verbose_level}")
170174

171175
else:
172176
args = (
@@ -180,7 +184,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
180184
if quiet:
181185
args.append("-q")
182186
elif self.verbose:
183-
args.append("--verbose")
187+
# cargo only have -vv
188+
verbose_level = 'v' * min(self.verbose, 2)
189+
args.append(f"-{verbose_level}")
184190

185191
args.extend(["--", "--crate-type", "cdylib"])
186192
args.extend(ext.rustc_flags or [])

setuptools_rust/setuptools_ext.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,24 @@ def make_distribution(self):
9191
dist.cmdclass["sdist"] = sdist_rust_extension
9292

9393
build_ext_base_class = dist.cmdclass.get('build_ext', build_ext)
94+
build_ext_options = build_ext_base_class.user_options.copy()
95+
build_ext_options.append(("target", None, "Build for the target triple"))
9496

9597
class build_ext_rust_extension(build_ext_base_class):
98+
user_options = build_ext_options
99+
100+
def initialize_options(self):
101+
super().initialize_options()
102+
self.target = os.getenv("CARGO_BUILD_TARGET")
103+
96104
def run(self):
97105
if self.distribution.rust_extensions:
98106
log.info("running build_rust")
99107
build_rust = self.get_finalized_command("build_rust")
100108
build_rust.inplace = self.inplace
101109
build_rust.plat_name = self.plat_name
110+
build_rust.target = self.target
111+
build_rust.verbose = self.verbose
102112
build_rust.run()
103113

104114
build_ext_base_class.run(self)
@@ -156,9 +166,17 @@ def finalize_options(self):
156166

157167
if bdist_wheel is not None:
158168
bdist_wheel_base_class = dist.cmdclass.get("bdist_wheel", bdist_wheel)
169+
bdist_wheel_options = bdist_wheel_base_class.user_options.copy()
170+
bdist_wheel_options.append(("target", None, "Build for the target triple"))
159171

160172
# this is for console entries
161173
class bdist_wheel_rust_extension(bdist_wheel_base_class):
174+
user_options = bdist_wheel_options
175+
176+
def initialize_options(self):
177+
super().initialize_options()
178+
self.target = os.getenv("CARGO_BUILD_TARGET")
179+
162180
def finalize_options(self):
163181
scripts = []
164182
for ext in self.distribution.rust_extensions:

0 commit comments

Comments
 (0)