Skip to content

Commit 22fe90b

Browse files
committed
feat(android): set the Cargo target linker
1 parent 32dcc38 commit 22fe90b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cibuildwheel/platforms/android.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,6 @@ def localized_vars(
340340
def setup_android_env(
341341
config: PythonConfiguration, python_dir: Path, venv_dir: Path, build_env: dict[str, str]
342342
) -> dict[str, str]:
343-
setup_rust_cross_compile(config, build_env)
344-
345343
site_packages = next(venv_dir.glob("lib/python*/site-packages"))
346344
for suffix in ["pth", "py"]:
347345
shutil.copy(resources.PATH / f"_cross_venv.{suffix}", site_packages)
@@ -384,6 +382,9 @@ def setup_android_env(
384382
for key in ["CFLAGS", "CXXFLAGS"]:
385383
android_env[key] += " " + opt
386384

385+
# Cargo target linker need to be specified after CC is set
386+
setup_rust_cross_compile(config, android_env)
387+
387388
# Format the environment so it can be pasted into a shell when debugging.
388389
for key, value in sorted(android_env.items()):
389390
if os.environ.get(key) != value:
@@ -405,8 +406,15 @@ def setup_rust_cross_compile(
405406
log.notice("Not overriding CARGO_BUILD_TARGET as it has already been set")
406407
# No message if it was set to what we were planning to set it to
407408
elif cargo_target:
408-
log.notice(f"Setting CARGO_BUILD_TARGET={cargo_target} for cross-compilation")
409+
cargo_target_linker_env_name = (
410+
f"CARGO_TARGET_{cargo_target.upper().replace('-', '_')}_LINKER"
411+
)
412+
log.notice(
413+
f"Setting CARGO_BUILD_TARGET={cargo_target} and {cargo_target_linker_env_name} for cross-compilation"
414+
)
409415
env["CARGO_BUILD_TARGET"] = cargo_target
416+
# CC has already been set by calling android.py (it calls android-env.sh)
417+
env[f"{cargo_target_linker_env_name}"] = env["CC"]
410418
else:
411419
log.warning(f"Unable to configure Rust cross-compilation for architecture {cargo_target}")
412420

0 commit comments

Comments
 (0)