Skip to content

Commit 23a8fc5

Browse files
committed
Try to detect musl distros in the Code extension
1 parent de67469 commit 23a8fc5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

editors/code/src/main.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { PersistentState } from './persistent_state';
1212
import { fetchRelease, download } from './net';
1313
import { activateTaskProvider } from './tasks';
1414
import { setContextValue } from './util';
15-
import { exec } from 'child_process';
15+
import { exec, spawnSync } from 'child_process';
1616

1717
let ctx: Ctx | undefined;
1818

@@ -297,7 +297,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
297297
"arm64 linux": "aarch64-unknown-linux-gnu",
298298
"arm64 darwin": "aarch64-apple-darwin",
299299
};
300-
const platform = platforms[`${process.arch} ${process.platform}`];
300+
let platform = platforms[`${process.arch} ${process.platform}`];
301301
if (platform === undefined) {
302302
await vscode.window.showErrorMessage(
303303
"Unfortunately we don't ship binaries for your platform yet. " +
@@ -309,6 +309,9 @@ async function getServer(config: Config, state: PersistentState): Promise<string
309309
);
310310
return undefined;
311311
}
312+
if (platform === "x86_64-unknown-linux-gnu" && isMusl()) {
313+
platform = "x86_64-unknown-linux-musl";
314+
}
312315
const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : "";
313316
const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`);
314317
const exists = await fs.stat(dest).then(() => true, () => false);
@@ -365,6 +368,13 @@ async function isNixOs(): Promise<boolean> {
365368
}
366369
}
367370

371+
function isMusl(): boolean {
372+
// We can detect Alpine by checking `/etc/os-release` but not Void Linux musl.
373+
// Instead, we run `ldd` since it advertises the libc which it belongs to.
374+
const res = spawnSync("ldd", ["--version"]);
375+
return res.stderr != null && res.stderr.indexOf("musl libc") >= 0;
376+
}
377+
368378
async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
369379
while (true) {
370380
try {

0 commit comments

Comments
 (0)