Skip to content

Fix libc detection on various platforms #6840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .yarn/versions/1f924e2c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
releases:
"@yarnpkg/core": patch
"@yarnpkg/cli": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-jsr"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
9 changes: 5 additions & 4 deletions packages/yarnpkg-core/sources/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export const openUrl = typeof openUrlBinary !== `undefined`
const LDD_PATH = `/usr/bin/ldd` as PortablePath;

function getLibc() {
// Darwin and Windows have their own standard libraries, and the getReport() call is costly.
// It also seems that Node randomly crashes with no output under some circumstances when running a getReport() on Windows.
if (process.platform === `darwin` || process.platform === `win32`)
// As of 2025, linux is the only possible process.platform value that does not imply the libc for Node's purposes.
// Technically mingw32 (a way to build and run software using glibc on Windows) exists and even has a node.js port, but no one in
// the broader node.js ecosystem seems to care about it. There have been issues in the past running getReport() on Windows.
if (process.platform !== `linux`)
return null;

let header: Buffer | undefined;
Expand All @@ -39,7 +40,7 @@ function getLibc() {
// Since the getReport can be prohibitely expensive (it also queries DNS which, if misconfigured, can take a long time to timeout),
// we first check if the ldd binary is glibc or musl, and only then run the getReport() if we can't determine the libc variant.
if (typeof header !== `undefined`) {
if (header && (header.includes(`GLIBC`) || header.includes(`libc`)))
if (header && (header.includes(`GLIBC`) || header.includes(`GNU libc`) || header.includes(`GNU C Library`)))
return `glibc`;
if (header && header.includes(`musl`)) {
return `musl`;
Expand Down