From f61827cbecf2d50b22a5128d990480f0efb821ac Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 9 May 2024 02:19:07 -0700 Subject: [PATCH] Switch rustup_wrapper to Rust implementation For better Windows portability --- build.py | 14 +++++++---- scripts/rustup_wrapper.py | 40 ------------------------------- tools/rustup_wrapper/.gitignore | Bin 0 -> 8 bytes tools/rustup_wrapper/Cargo.lock | Bin 0 -> 2693 bytes tools/rustup_wrapper/Cargo.toml | Bin 0 -> 196 bytes tools/rustup_wrapper/src/main.rs | Bin 0 -> 1360 bytes 6 files changed, 10 insertions(+), 44 deletions(-) delete mode 100755 scripts/rustup_wrapper.py create mode 100644 tools/rustup_wrapper/.gitignore create mode 100644 tools/rustup_wrapper/Cargo.lock create mode 100644 tools/rustup_wrapper/Cargo.toml create mode 100644 tools/rustup_wrapper/src/main.rs 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 0000000000000000000000000000000000000000..2f7896d1d1365eafb0da03d9fe456fac81408487 GIT binary patch literal 8 PcmXR(EJ{x;(dPmH4psue literal 0 HcmV?d00001 diff --git a/tools/rustup_wrapper/Cargo.lock b/tools/rustup_wrapper/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..98169f35539ea367d666df6219666c0abaaea38a GIT binary patch literal 2693 zcmcguO>ZMN488kT47|rSj=o4y1qu}CsrTN3Ado1^9;`h!JmX~Z?@Ooo+QhrQBzuw} z(Uczf-s61f{$2HB*ZQ?|y5_^Q-Q=m~yk6gTe=TK@eV(Lt<-Yqn@0Z)f>`V90bPOG~ zx(t&HRgc?t-)-`6$m>pOKlQ_MF}s!h*l&mK&(67Em;JOllm%}$m;1vwU99u4yyW8($3?%r z==Cw*<}+Rie;p5-<0ay&^$<$K5}gMwAsdLu4sB{RNVR0iH>6aoE5=|pBGJ1f(pt(e zpH0(1Jo?c$;=Nm`C-b} z_r58dJ0|?l$~kgHpn1&163Mn)i7AVvmVHY_>jP2P7I0jA6%#2rV}pa5viJ2Qz9$5e zl1ZkYRPSxzJGk1J4~2`(MC)@vfD}xs&Nzuiv5L-e~G-!#Sl_kNe>=eqXo{;99i})W~@1)vtCLCW=?=MBm|`FBDmZNo&odB zpHBxu+5i(hH;WZ~RKXbG6r4H-tMgiPXkuWjp;lE@0GCp9$j2rojOtt`2gFlXo`5`X z_4C2R7IZo|my9==fYbs@fTZtM_e&9ia;jNjGy-BOX0O!JAMA7y9bo6d{2G4M;@OpU zoPZSy0u`NX0llLjxmibwk5hJ-li_G%i7iH3n}Q4!OFM()#YEl=H*kxOcIP0$1#A&Z z)wyGmlt2_An^wK37%*p*OR7ib_TE@agnFVzZNbKRt|>22ei6q&=|vLAamC0Uu-2L& z8c(Pr2VDVFJrSt(8&TCSk%DAg@jfu5bIO11;h(OTA{?SXQ70?f8c}LtCGC&8mQ~qP ave~AXOK|#Wpk~JpD} literal 0 HcmV?d00001 diff --git a/tools/rustup_wrapper/Cargo.toml b/tools/rustup_wrapper/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..b8f5e6045637c4ba06412cbf0abb30c6e4f438cc GIT binary patch literal 196 zcmXYrK?=e!6h!y`6rZ>@sRcKJr*J7nLNaYb+a&y?inq5_ncaH>Gxu!WWCwH1a&9vyDD0`T+X@ BK}Y}q literal 0 HcmV?d00001 diff --git a/tools/rustup_wrapper/src/main.rs b/tools/rustup_wrapper/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..6cd9ec49e71d5f326da09914cbc8758a8df4b347 GIT binary patch literal 1360 zcmah}O>f&U488kTa5*$~n>pK6ZPP^z?VF*Gz-P*R5rk=oktd-qeW_?g&TNI*_eq|r{nLba? z->?kM;YYKD+QJ6GAl48Y6=36~bLel#|AtWn7x~s8R0$T$eHUWq_}y89CW2NW&Z!9o zFgC)*`bXHP*g!>*wuNY|t{SOK5L|2q=)Lvg_#MWrT&eIlJ{Ad`bJoXWmoPy2VmG)( zKS@mXpokPHS;Jxrf!$KW-KWoiT0o5veX9(DTuY_pLL;L%z^9-_QX^?#fqj(;gsy5p z2B@@hZaV>{ylf+2tV&M4GpT*3ymE2E>IT(1y#oUkBiJswjs$7YP+?_O{a2$_ zP1M^SL?ews4QdI}Y+-%?HD`Rh1+XN{SeM!PG|QF-T9Pp@;QcJ^kg`I2#n9<^l@~L3 z%79E`>=DzDu8G%vWAfsr{B0?Hv`}VL49{trqvG5abAX zQHDq5@{dJXS*?j_PN{t^lc3a6k=_(Wg!1R`3<0jMVRT?NDh8B$q#?@KQ4riF#zGj} zU62g*}f-jWR zPcpNcjpc4>%vD?ekHxVbCr}_W$wwE%D(ux~C)=Rp&kw&!>g{8A;B(5y7vtBxIeI7; z@|WrlLmI})VQf1sGq_`QaHz^kZsD+ok20 iPT@XXh?9X&&f9L)^o9R9_cZDkjA-xrMLF%3?Xo|p)RPMU literal 0 HcmV?d00001