X Tutup
The Wayback Machine - https://web.archive.org/web/20211109174827/https://github.com/nodejs/node/issues/39877
Skip to content
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

Runtime information about libc version and type #39877

Open
Brooooooklyn opened this issue Aug 25, 2021 · 3 comments
Open

Runtime information about libc version and type #39877

Brooooooklyn opened this issue Aug 25, 2021 · 3 comments

Comments

Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
@Brooooooklyn
Copy link

@Brooooooklyn Brooooooklyn commented Aug 25, 2021

Is your feature request related to a problem? Please describe.

I need to dectect the libc version and type on Linux systems to determined which native addon I need to load.

The most common ways in Node.js to do such things is using the detect-libc package, which is actully invoke shell scripts and try to read messages in the stdout, not elegant at all.

The other way is using try ... catch on Linux:

try {
  return require('my-native-addon.x64-linux-gnu.node')
} catch {
  return require('my-native-addon.x64-linux-musl.node')
}

not elegant either and more complicated.

Describe the solution you'd like

I want get libc information on process.versions directly, like:

console.log(process.versions.libc)

{
  family: 'glibc',
  version: '2.24'
}

For the other systems don't need to consider about libc problem, just leave the fields as null.

@richardlau
Copy link
Member

@richardlau richardlau commented Aug 25, 2021

FWIW we do attempt to determine glibc versions (compile and runtime versions) for inclusion in a diagnostics report

node/src/node_report.cc

Lines 363 to 376 in 99a3d55

#ifndef _WIN32
// Report compiler and runtime glibc versions where possible.
const char* (*libc_version)();
*(reinterpret_cast<void**>(&libc_version)) =
dlsym(RTLD_DEFAULT, "gnu_get_libc_version");
if (libc_version != nullptr)
writer->json_keyvalue("glibcVersionRuntime", (*libc_version)());
#endif /* _WIN32 */
#ifdef __GLIBC__
buf << __GLIBC__ << "." << __GLIBC_MINOR__;
writer->json_keyvalue("glibcVersionCompiler", buf.str());
buf.str("");
#endif

    glibcVersionRuntime: '2.28',
    glibcVersionCompiler: '2.17'

Loading

@mhdawson
Copy link
Member

@mhdawson mhdawson commented Aug 26, 2021

@Brooooooklyn this seems like a small addition and reasonable to me at first glance. The best way to move forward is likely to submit a PR. Is that something you can do?

Loading

@Brooooooklyn
Copy link
Author

@Brooooooklyn Brooooooklyn commented Aug 27, 2021

@mhdawson I will try it

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
X Tutup