Skip to content

Commit

Permalink
RustCompiledComponentsRecipe`: support for changing toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos committed May 17, 2024
1 parent 6bf7513 commit de3ff48
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -1399,17 +1398,24 @@ 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"
)
exit(1)

def build_arch(self, arch):
self.check_host_deps()
self.ensure_rust_toolchain(arch)
super().build_arch(arch)


Expand Down

0 comments on commit de3ff48

Please sign in to comment.