@@ -340,8 +340,6 @@ def localized_vars(
340340def 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 )
@@ -354,14 +352,17 @@ def setup_android_env(
354352 )
355353 sysconfigdata = localize_sysconfigdata (python_dir , build_env , sysconfigdata_path )
356354
357- # Activate the code in _cross_venv.py.
358- android_env = build_env .copy ()
359- android_env ["CIBW_HOST_TRIPLET" ] = android_triplet (config .identifier )
360-
361355 # Get the environment variables needed to build for Android (CC, CFLAGS, etc). These are
362356 # generated by https://github.com/python/cpython/blob/main/Android/android-env.sh.
363357 env_output = call (python_dir / "android.py" , "env" , env = build_env , capture_stdout = True )
364358
359+ # Cargo target linker need to be specified after CC is set
360+ setup_rust_cross_compile (config , build_env )
361+
362+ # Activate the code in _cross_venv.py.
363+ android_env = build_env .copy ()
364+ android_env ["CIBW_HOST_TRIPLET" ] = android_triplet (config .identifier )
365+
365366 # shlex.split should produce a sequence alternating between:
366367 # * the word "export"
367368 # * a key=value string, without quotes
@@ -405,8 +406,10 @@ 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 = f"CARGO_TARGET_{ cargo_target .upper ().replace ('-' , '_' )} _LINKER"
410+ log .notice (f"Setting CARGO_BUILD_TARGET={ cargo_target } and setting { cargo_target_linker_env_name } for cross-compilation" )
409411 env ["CARGO_BUILD_TARGET" ] = cargo_target
412+ env ["cargo_target_linker_env_name" ] = os .environ .get ("CC" )
410413 else :
411414 log .warning (f"Unable to configure Rust cross-compilation for architecture { cargo_target } " )
412415
0 commit comments