Robust libc detection for Linux platforms.
Uses multiple methods in order of reliability to detect whether the system uses glibc or musl libc. This is critical for selecting the correct ERTS build for cross-platform compatibility.
The detector uses these methods in order:
ldd --version - Most reliable for runtime detection
Dynamic loader check - Most reliable for cross-compile
/etc/os-release - Fallback for known distributions
/proc/self/maps - Advanced fallback
iex> Batamanta.ERTS.LibcDetector.detect() :gnu
iex> Batamanta.ERTS.LibcDetector.detect() :musl
Summary
Functions
Returns a human-readable description of the detected libc.
Detects the libc type of the current system.
Detects libc by running ldd --version.
Detects libc by checking for dynamic loader files.
Detects libc by reading /etc/os-release.
Detects libc by reading /proc/self/maps.
Validates that the detected libc matches an expected target.
Types
Functions
Returns a human-readable description of the detected libc.
@spec detect() :: :gnu | :musl
Detects the libc type of the current system.
Returns :gnu for glibc-based systems (Debian, Ubuntu, Arch, Fedora, etc.)
or :musl for musl-based systems (Alpine, Void Linux, etc.).
Always returns either :gnu or :musl - never :unknown (uses fallback).
iex> Batamanta.ERTS.LibcDetector.detect()
:gnu
@spec detect_by_ldd() :: libc_type()
Detects libc by running ldd --version.
This is the most reliable method for runtime detection on the current system.
@spec detect_by_loader() :: libc_type()
Detects libc by checking for dynamic loader files.
This method works even when ldd is not available, making it suitable
for cross-compilation scenarios.
@spec detect_by_os_release() :: libc_type()
Detects libc by reading /etc/os-release.
This method works for known distributions but may fail for custom builds.
@spec detect_by_proc_maps() :: libc_type()
Detects libc by reading /proc/self/maps.
Advanced method that checks which libc is loaded in memory.
Validates that the detected libc matches an expected target.
Returns :ok if they match, or an error tuple with details.