From 59febc16d16db2f61b4258966eb6418872f94fd9 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Mon, 1 Aug 2022 20:11:47 +0100 Subject: [PATCH] Add setup_rust_cross_compile --- cibuildwheel/windows.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 1a0b71cd..8044fa1d 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -161,6 +161,7 @@ def setup_setuptools_cross_compile( # interpreter, and has no logic to construct it. Currently, CPython's # extensions follow our identifiers, but if they ever diverge in the # future, we will need to store new data + log.info("Setting SETUPTOOLS_EXT_SUFFIX=.%s.pyd for cross-compilation", python_configuration.identifier) env["SETUPTOOLS_EXT_SUFFIX"] = f".{python_configuration.identifier}.pyd" # Cross-compilation requires fixes that only exist in setuptools's copy of @@ -171,6 +172,35 @@ def setup_setuptools_cross_compile( env["SETUPTOOLS_USE_DISTUTILS"] = "local" +def setup_rust_cross_compile( + python_configuration: PythonConfiguration, + python_libs_base: Path, + env: Dict[str, str], +) -> None: + # Assume that MSVC will be used, because we already know that we are + # cross-compiling. MinGW users can set CARGO_BUILD_TARGET themselves + # and we will respect the existing value. + cargo_target = { + "64": "x86_64-pc-windows-msvc", + "32": "i686-pc-windows-msvc", + "ARM64": "aarch64-pc-windows-msvc", + }.get(python_configuration.arch) + + # CARGO_BUILD_TARGET is the variable used by Cargo and setuptools_rust + if env.get("CARGO_BUILD_TARGET"): + if env["CARGO_BUILD_TARGET"] != cargo_target: + log.warning("Not overriding CARGO_BUILD_TARGET as it has already been set") + # No message if it was set to what we were planning to set it to + elif cargo_target: + log.info("Setting CARGO_BUILD_TARGET=%s for cross-compilation", cargo_target) + env["CARGO_BUILD_TARGET"] = cargo_target + else: + log.warning( + "Unable to configure Rust cross-compilation for architecture '%s'", + python_configuration.arch + ) + + def setup_python( tmp: Path, python_configuration: PythonConfiguration, @@ -299,6 +329,7 @@ def setup_python( if python_libs_base: # Set up the environment for various backends to enable cross-compilation setup_setuptools_cross_compile(python_configuration, python_libs_base, env) + setup_rust_cross_compile(python_configuration, python_libs_base, env) return env