diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e8a676..3304f607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased ### Added +- Add `--target` command line option for specifying target triple. [#136](https://github.com/PyO3/setuptools-rust/pull/136) - Support very verbose cargo build.rs output. [#140](https://github.com/PyO3/setuptools-rust/pull/140) ### Removed diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 4175d025..83e8ecb6 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -37,6 +37,7 @@ class build_rust(RustCommand): "t", "directory for temporary files (cargo 'target' directory) ", ), + ("target", None, "Build for the target triple"), ] boolean_options = ["inplace", "debug", "release", "qbuild"] @@ -48,6 +49,7 @@ def initialize_options(self): self.qbuild = None self.build_temp = None self.plat_name = None + self.target = os.getenv("CARGO_BUILD_TARGET") def finalize_options(self): super().finalize_options() @@ -64,9 +66,9 @@ def get_target_triple(self): # If we are on a 64-bit machine, but running a 32-bit Python, then # we'll target a 32-bit Rust build. # Automatic target detection can be overridden via the CARGO_BUILD_TARGET - # environment variable. - if os.getenv("CARGO_BUILD_TARGET"): - return os.environ["CARGO_BUILD_TARGET"] + # environment variable or --target command line option + if self.target: + return self.target elif self.plat_name == "win32": return "i686-pc-windows-msvc" elif self.plat_name == "win-amd64": diff --git a/setuptools_rust/setuptools_ext.py b/setuptools_rust/setuptools_ext.py index f7ad60e6..a7936088 100644 --- a/setuptools_rust/setuptools_ext.py +++ b/setuptools_rust/setuptools_ext.py @@ -91,14 +91,23 @@ def make_distribution(self): dist.cmdclass["sdist"] = sdist_rust_extension build_ext_base_class = dist.cmdclass.get('build_ext', build_ext) + build_ext_options = build_ext_base_class.user_options.copy() + build_ext_options.append(("target", None, "Build for the target triple")) class build_ext_rust_extension(build_ext_base_class): + user_options = build_ext_options + + def initialize_options(self): + super().initialize_options() + self.target = os.getenv("CARGO_BUILD_TARGET") + def run(self): if self.distribution.rust_extensions: log.info("running build_rust") build_rust = self.get_finalized_command("build_rust") build_rust.inplace = self.inplace build_rust.plat_name = self.plat_name + build_rust.target = self.target build_rust.verbose = self.verbose build_rust.run() @@ -157,9 +166,17 @@ def finalize_options(self): if bdist_wheel is not None: bdist_wheel_base_class = dist.cmdclass.get("bdist_wheel", bdist_wheel) + bdist_wheel_options = bdist_wheel_base_class.user_options.copy() + bdist_wheel_options.append(("target", None, "Build for the target triple")) # this is for console entries class bdist_wheel_rust_extension(bdist_wheel_base_class): + user_options = bdist_wheel_options + + def initialize_options(self): + super().initialize_options() + self.target = os.getenv("CARGO_BUILD_TARGET") + def finalize_options(self): scripts = [] for ext in self.distribution.rust_extensions: