Switch rustup_wrapper to Rust implementation

For better Windows portability
This commit is contained in:
topjohnwu 2024-05-09 02:19:07 -07:00
parent 3f2264f2c7
commit f61827cbec
6 changed files with 10 additions and 44 deletions

View File

@ -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)

View File

@ -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)

BIN
tools/rustup_wrapper/.gitignore vendored Normal file

Binary file not shown.

BIN
tools/rustup_wrapper/Cargo.lock generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.