diff --git a/build.py b/build.py index fcc21182c..8c5cca80c 100755 --- a/build.py +++ b/build.py @@ -638,10 +638,16 @@ def setup_rustup(args): for src in cargo_bin.iterdir(): tgt = wrapper_dir / src.name tgt.symlink_to(src) - # Replace rustup with python script - wrapper = wrapper_dir / "rustup" - wrapper.unlink() - cp(Path("scripts", "rustup_wrapper.py"), wrapper) + + # Build rustup_wrapper + wrapper_src = Path("tools", "rustup_wrapper") + cargo_toml = wrapper_src / "Cargo.toml" + execv([cargo, "build", "--release", f"--manifest-path={cargo_toml}"]) + + # Replace rustup with wrapper + wrapper = wrapper_dir / (f"rustup{EXE_EXT}") + wrapper.unlink(missing_ok=True) + cp(wrapper_src / "target" / "release" / (f"rustup_wrapper{EXE_EXT}"), wrapper) wrapper.chmod(0o755) diff --git a/scripts/rustup_wrapper.py b/scripts/rustup_wrapper.py deleted file mode 100755 index ef9a1303a..000000000 --- a/scripts/rustup_wrapper.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python3 -import subprocess -import sys -import os -from pathlib import Path - -################################ -# Why do we need this wrapper? -################################ -# -# The command `rustup component list` does not work with custom toolchains: -# > error: toolchain 'magisk' does not support components -# -# However, this command is used by several IDEs to determine available -# components that can be used, such as clippy, rustfmt etc. -# In this script, we simply redirect the output when using the nightly -# channel if any `component` command failed. - -if "CARGO_HOME" in os.environ: - cargo_home = Path(os.environ["CARGO_HOME"]) -else: - cargo_home = Path.home() / ".cargo" - -rustup = cargo_home / "bin" / "rustup" - -if "component" in sys.argv: - proc = subprocess.run( - [rustup, *sys.argv[1:]], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - if proc.returncode != 0: - # Remove any channel overrides - if sys.argv[1].startswith("+"): - sys.argv.pop(1) - # Return the nightly channel results - sys.exit(subprocess.run([rustup, "+nightly", *sys.argv[1:]]).returncode) - -# Passthrough -sys.exit(subprocess.run([rustup, *sys.argv[1:]]).returncode) diff --git a/tools/rustup_wrapper/.gitignore b/tools/rustup_wrapper/.gitignore new file mode 100644 index 000000000..2f7896d1d Binary files /dev/null and b/tools/rustup_wrapper/.gitignore differ diff --git a/tools/rustup_wrapper/Cargo.lock b/tools/rustup_wrapper/Cargo.lock new file mode 100644 index 000000000..98169f355 Binary files /dev/null and b/tools/rustup_wrapper/Cargo.lock differ diff --git a/tools/rustup_wrapper/Cargo.toml b/tools/rustup_wrapper/Cargo.toml new file mode 100644 index 000000000..b8f5e6045 Binary files /dev/null and b/tools/rustup_wrapper/Cargo.toml differ diff --git a/tools/rustup_wrapper/src/main.rs b/tools/rustup_wrapper/src/main.rs new file mode 100644 index 000000000..6cd9ec49e Binary files /dev/null and b/tools/rustup_wrapper/src/main.rs differ