|
7 | 7 | import shutil |
8 | 8 | import subprocess |
9 | 9 | import sysconfig |
10 | | -from collections.abc import Iterable, Iterator |
| 10 | +from collections.abc import Iterable, Iterator, MutableMapping |
11 | 11 | from dataclasses import dataclass |
12 | 12 | from os.path import relpath |
13 | 13 | from pathlib import Path |
@@ -340,6 +340,8 @@ def localized_vars( |
340 | 340 | def setup_android_env( |
341 | 341 | config: PythonConfiguration, python_dir: Path, venv_dir: Path, build_env: dict[str, str] |
342 | 342 | ) -> dict[str, str]: |
| 343 | + setup_rust_cross_compile(config, build_env) |
| 344 | + |
343 | 345 | site_packages = next(venv_dir.glob("lib/python*/site-packages")) |
344 | 346 | for suffix in ["pth", "py"]: |
345 | 347 | shutil.copy(resources.PATH / f"_cross_venv.{suffix}", site_packages) |
@@ -390,6 +392,25 @@ def setup_android_env( |
390 | 392 | return android_env |
391 | 393 |
|
392 | 394 |
|
| 395 | +def setup_rust_cross_compile( |
| 396 | + python_configuration: PythonConfiguration, |
| 397 | + env: MutableMapping[str, str], |
| 398 | +) -> None: |
| 399 | + cargo_target = android_triplet(python_configuration.identifier) |
| 400 | + call("rustup", "target", "add", cargo_target) |
| 401 | + |
| 402 | + # CARGO_BUILD_TARGET is the variable used by Cargo and setuptools_rust |
| 403 | + if env.get("CARGO_BUILD_TARGET"): |
| 404 | + if env["CARGO_BUILD_TARGET"] != cargo_target: |
| 405 | + log.notice("Not overriding CARGO_BUILD_TARGET as it has already been set") |
| 406 | + # No message if it was set to what we were planning to set it to |
| 407 | + elif cargo_target: |
| 408 | + log.notice(f"Setting CARGO_BUILD_TARGET={cargo_target} for cross-compilation") |
| 409 | + env["CARGO_BUILD_TARGET"] = cargo_target |
| 410 | + else: |
| 411 | + log.warning(f"Unable to configure Rust cross-compilation for architecture {cargo_target}") |
| 412 | + |
| 413 | + |
393 | 414 | def before_build(state: BuildState) -> None: |
394 | 415 | if state.options.before_build: |
395 | 416 | log.step("Running before_build...") |
|
0 commit comments