(toolchain: str, envdir: str)
| 81 | |
| 82 | |
| 83 | def install_rust_with_toolchain(toolchain: str, envdir: str) -> None: |
| 84 | with tempfile.TemporaryDirectory() as rustup_dir: |
| 85 | with envcontext((('CARGO_HOME', envdir), ('RUSTUP_HOME', rustup_dir))): |
| 86 | # acquire `rustup` if not present |
| 87 | if parse_shebang.find_executable('rustup') is None: |
| 88 | # We did not detect rustup and need to download it first. |
| 89 | if sys.platform == 'win32': # pragma: win32 cover |
| 90 | url = 'https://win.rustup.rs/x86_64' |
| 91 | else: # pragma: win32 no cover |
| 92 | url = 'https://sh.rustup.rs' |
| 93 | |
| 94 | resp = urllib.request.urlopen(url) |
| 95 | |
| 96 | rustup_init = os.path.join(rustup_dir, win_exe('rustup-init')) |
| 97 | with open(rustup_init, 'wb') as f: |
| 98 | shutil.copyfileobj(resp, f) |
| 99 | make_executable(rustup_init) |
| 100 | |
| 101 | # install rustup into `$CARGO_HOME/bin` |
| 102 | cmd_output_b( |
| 103 | rustup_init, '-y', '--quiet', '--no-modify-path', |
| 104 | '--default-toolchain', 'none', |
| 105 | ) |
| 106 | |
| 107 | cmd_output_b( |
| 108 | 'rustup', 'toolchain', 'install', '--no-self-update', |
| 109 | toolchain, |
| 110 | ) |
| 111 | |
| 112 | |
| 113 | def install_environment( |
no test coverage detected