Skip to content

Commit

Permalink
fix: musl libc detection (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger authored May 25, 2024
1 parent d9ca2b7 commit 220517b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
58 changes: 9 additions & 49 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { syntaxTree } from "./commands/syntaxTree";
import { selectAndDownload, updateToLatest } from "./downloader";
import { Session } from "./session";
import { StatusBar } from "./statusBar";
import { setContextValue } from "./utils";
import { isMusl, setContextValue } from "./utils";

let client: LanguageClient;

Expand Down Expand Up @@ -267,50 +267,6 @@ export async function activate(context: ExtensionContext) {
await client.start();
}

type Architecture = "x64" | "arm64";

type PlatformTriplets = {
[P in NodeJS.Platform]?: {
[A in Architecture]: {
triplet: string;
package: string;
};
};
};

const PLATFORMS: PlatformTriplets = {
win32: {
x64: {
triplet: "x86_64-pc-windows-msvc",
package: "@biomejs/cli-win32-x64",
},
arm64: {
triplet: "aarch64-pc-windows-msvc",
package: "@biomejs/cli-win32-arm64",
},
},
darwin: {
x64: {
triplet: "x86_64-apple-darwin",
package: "@biomejs/cli-darwin-x64",
},
arm64: {
triplet: "aarch64-apple-darwin",
package: "@biomejs/cli-darwin-arm64",
},
},
linux: {
x64: {
triplet: "x86_64-unknown-linux-gnu",
package: "@biomejs/cli-linux-x64",
},
arm64: {
triplet: "aarch64-unknown-linux-gnu",
package: "@biomejs/cli-linux-arm64",
},
},
};

async function getServerPath(
context: ExtensionContext,
outputChannel: OutputChannel,
Expand Down Expand Up @@ -439,6 +395,8 @@ async function getWorkspaceRelativePath(path: string) {
async function getWorkspaceDependency(
outputChannel: OutputChannel,
): Promise<string | undefined> {
const wantsMuslBuild = isMusl();

for (const workspaceFolder of workspace.workspaceFolders ?? []) {
// Check for Yarn PnP and try resolving the Biome binary without a node_modules
// folder first.
Expand All @@ -463,9 +421,9 @@ async function getWorkspaceDependency(
throw new Error("No @biomejs/biome dependency configured");
}
return pnpApi.resolveRequest(
`@biomejs/cli-${process.platform}-${process.arch}/biome${
process.platform === "win32" ? ".exe" : ""
}`,
`@biomejs/cli-${process.platform}-${process.arch}${
wantsMuslBuild ? "-musl" : ""
}/biome${process.platform === "win32" ? ".exe" : ""}`,
pkgPath,
);
} catch (err) {
Expand All @@ -487,7 +445,9 @@ async function getWorkspaceDependency(
);
const binaryPackage = dirname(
requireFromBiome.resolve(
`@biomejs/cli-${process.platform}-${process.arch}/package.json`,
`@biomejs/cli-${process.platform}-${process.arch}${
wantsMuslBuild ? "-musl" : ""
}/package.json`,
),
);

Expand Down
24 changes: 24 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from "node:child_process";
import { type TextDocument, type TextEditor, commands } from "vscode";

const SUPPORTED_LANGUAGES = new Set(["javascript", "typescript"]);
Expand All @@ -24,3 +25,26 @@ export function isBiomeDocument(document: TextDocument) {
export function isBiomeEditor(editor: TextEditor): editor is BiomeEditor {
return isBiomeDocument(editor.document);
}

/**
* Determines if the current system is using musl libc
*
* On Linux, the output of the `ldd --version` command will contain the string `musl`
* if the system is using musl libc.
*
* On non-Linux systems, the function will return false.
*
* @returns boolean
*/
export function isMusl() {
if (process.platform !== "linux") {
return false;
}

try {
const output = spawnSync("ldd", ["--version"], { encoding: "utf8" });
return output.stdout.includes("musl");
} catch {
return false;
}
}

0 comments on commit 220517b

Please sign in to comment.