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

Commit 41b5937

Browse files
Xanewokjdemilledt
andcommitted
Handle rustup toolchain shorthands
This includes different ABIs, e.g. `stable-msvc` but also architecture such as `nightly-x86_64-gnu`. Co-authored-by: Julian DeMille <julian.demille@demilletech.net>
1 parent c6b3b72 commit 41b5937

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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)