@@ -1353,6 +1353,8 @@ class RustCompiledComponentsRecipe(PyProjectRecipe):
13531353 "x86_64" : "x86_64-linux-android" ,
13541354 "x86" : "i686-linux-android" ,
13551355 }
1356+ # Rust toolchain to be used for building
1357+ toolchain = "stable"
13561358
13571359 call_hostpython_via_targetpython = False
13581360
@@ -1365,6 +1367,7 @@ def get_recipe_env(self, arch, **kwargs):
13651367 build_target .upper ().replace ("-" , "_" )
13661368 )
13671369 env ["CARGO_BUILD_TARGET" ] = build_target
1370+ env ["TARGET" ] = build_target
13681371 env [cargo_linker_name ] = join (
13691372 self .ctx .ndk .llvm_prebuilt_dir ,
13701373 "bin" ,
@@ -1386,10 +1389,6 @@ def get_recipe_env(self, arch, **kwargs):
13861389 realpython_dir , "android-build" , "build" ,
13871390 "lib.linux-*-{}/" .format (self .python_major_minor_version ),
13881391 ))[0 ])
1389-
1390- info_main ("Ensuring rust build toolchain" )
1391- shprint (sh .rustup , "target" , "add" , build_target )
1392-
13931392 # Add host python to PATH
13941393 env ["PATH" ] = ("{hostpython_dir}:{old_path}" ).format (
13951394 hostpython_dir = Recipe .get_recipe (
@@ -1399,17 +1398,24 @@ def get_recipe_env(self, arch, **kwargs):
13991398 )
14001399 return env
14011400
1401+ def ensure_rust_toolchain (self , arch ):
1402+ info_main ("Ensuring rust build toolchain : {}" .format (self .toolchain ))
1403+ shprint (sh .rustup , "toolchain" , "install" , self .toolchain )
1404+ shprint (sh .rustup , "target" , "add" , "--toolchain" , self .toolchain , self .RUST_ARCH_CODES [arch .arch ])
1405+ shprint (sh .rustup , "default" , self .toolchain )
1406+
14021407 def check_host_deps (self ):
14031408 if not hasattr (sh , "rustup" ):
14041409 error (
1405- "`rustup` was not found on host system."
1410+ "\n `rustup` was not found on host system."
14061411 "Please install it using :"
14071412 "\n `curl https://sh.rustup.rs -sSf | sh`\n "
14081413 )
14091414 exit (1 )
14101415
14111416 def build_arch (self , arch ):
14121417 self .check_host_deps ()
1418+ self .ensure_rust_toolchain (arch )
14131419 super ().build_arch (arch )
14141420
14151421
0 commit comments