Go through rustup proxy if possible

This commit is contained in:
topjohnwu
2026-03-11 00:43:18 -07:00
parent e8a58776f1
commit 6bb48df712

View File

@@ -239,15 +239,19 @@ def build_cpp_src(targets: set[str]):
def run_cargo(cmds: list[str]):
ensure_paths()
env = os.environ.copy()
env["PATH"] = f"{rust_sysroot / "bin"}{os.pathsep}{env["PATH"]}"
env["CARGO_BUILD_RUSTFLAGS"] = f"-Z threads={min(8, cpu_count)}"
# Cargo calls executables in $RUSTROOT/lib/rustlib/$TRIPLE/bin, we need
# to make sure the runtime linker also search $RUSTROOT/lib for libraries.
# This is only required on Unix, as Windows search dlls from PATH.
if os_name == "darwin":
env["DYLD_FALLBACK_LIBRARY_PATH"] = str(rust_sysroot / "lib")
elif os_name == "linux":
env["LD_LIBRARY_PATH"] = str(rust_sysroot / "lib")
if shutil.which("rustup"):
# Go through rustup proxies by default if available
env["RUSTUP_TOOLCHAIN"] = str(rust_sysroot)
else:
env["PATH"] = f"{rust_sysroot / "bin"}{os.pathsep}{env["PATH"]}"
# Cargo calls executables in $RUSTROOT/lib/rustlib/$TRIPLE/bin, we need
# to make sure the runtime linker also search $RUSTROOT/lib for libraries.
# This is only required on Unix, as Windows search dlls from PATH.
if os_name == "darwin":
env["DYLD_FALLBACK_LIBRARY_PATH"] = str(rust_sysroot / "lib")
elif os_name == "linux":
env["LD_LIBRARY_PATH"] = str(rust_sysroot / "lib")
return execv(["cargo", *cmds], env)