From 7d00446ae229ccc72671024d33d84c4373878ac6 Mon Sep 17 00:00:00 2001 From: Ansh Dadwal Date: Fri, 17 May 2024 17:17:53 +0530 Subject: [PATCH] RustCompiledComponentsRecipe`: support for changing toolchain --- pythonforandroid/recipe.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index aa10434525..fcd535b0ec 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -1353,6 +1353,8 @@ class RustCompiledComponentsRecipe(PyProjectRecipe): "x86_64": "x86_64-linux-android", "x86": "i686-linux-android", } + # Rust toolchain to be used for building + toolchain = "stable" call_hostpython_via_targetpython = False @@ -1365,6 +1367,7 @@ def get_recipe_env(self, arch, **kwargs): build_target.upper().replace("-", "_") ) env["CARGO_BUILD_TARGET"] = build_target + env["TARGET"] = build_target env[cargo_linker_name] = join( self.ctx.ndk.llvm_prebuilt_dir, "bin", @@ -1386,10 +1389,6 @@ def get_recipe_env(self, arch, **kwargs): realpython_dir, "android-build", "build", "lib.linux-*-{}/".format(self.python_major_minor_version), ))[0]) - - info_main("Ensuring rust build toolchain") - shprint(sh.rustup, "target", "add", build_target) - # Add host python to PATH env["PATH"] = ("{hostpython_dir}:{old_path}").format( hostpython_dir=Recipe.get_recipe( @@ -1399,10 +1398,16 @@ def get_recipe_env(self, arch, **kwargs): ) return env + def ensure_rust_toolchain(self, arch): + info_main("Ensuring rust build toolchain : {}".format(self.toolchain)) + shprint(sh.rustup, "toolchain", "install", self.toolchain) + shprint(sh.rustup, "target", "add", "--toolchain", self.toolchain, self.RUST_ARCH_CODES[arch.arch]) + shprint(sh.rustup, "default", self.toolchain) + def check_host_deps(self): if not hasattr(sh, "rustup"): error( - "`rustup` was not found on host system." + "\n`rustup` was not found on host system." "Please install it using :" "\n`curl https://sh.rustup.rs -sSf | sh`\n" ) @@ -1410,6 +1415,7 @@ def check_host_deps(self): def build_arch(self, arch): self.check_host_deps() + self.ensure_rust_toolchain(arch) super().build_arch(arch)