Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 1d2087c

Browse files
authored
Merge pull request #788 from Xanewok/respect-abi-toolchain-suffix
Handle rustup toolchain shorthands
2 parents c6b3b72 + 29658d2 commit 1d2087c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Unreleased
22

3+
* Accept rustup toolchain shorthands in `rust-client.channel`, e.g. `stable-gnu` or `nightly-x86_64-msvc`
34
* Remove deprecated `rust-client.useWsl` setting (use the official
45
[Remote - WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) extension instead)
56

src/rustup.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@ export async function checkForRls(config: RustupConfig) {
8181
}
8282
}
8383

84-
async function hasToolchain(config: RustupConfig): Promise<boolean> {
84+
async function hasToolchain({ channel, path }: RustupConfig): Promise<boolean> {
85+
// In addition to a regular channel name, also handle shorthands e.g.
86+
// `stable-msvc` or `stable-x86_64-msvc` but not `stable-x86_64-pc-msvc`.
87+
const abiSuffix = ['-gnu', '-msvc'].find(abi => channel.endsWith(abi));
88+
const [prefix, suffix] =
89+
abiSuffix && channel.split('-').length <= 3
90+
? [channel.substr(0, channel.length - abiSuffix.length), abiSuffix]
91+
: [channel, undefined];
92+
// Skip middle target triple components such as vendor as necessary, since
93+
// `rustup` output lists toolchains with a full target triple inside
94+
const matcher = new RegExp([prefix, suffix && `.*${suffix}`].join(''));
8595
try {
86-
const { stdout } = await exec(`${config.path} toolchain list`);
87-
return stdout.includes(config.channel);
96+
const { stdout } = await exec(`${path} toolchain list`);
97+
return matcher.test(stdout);
8898
} catch (e) {
8999
console.log(e);
90100
window.showErrorMessage(

0 commit comments

Comments
 (0)