diff --git a/common/src/main/java/com/sedmelluq/lava/common/natives/architecture/DefaultOperatingSystemTypes.java b/common/src/main/java/com/sedmelluq/lava/common/natives/architecture/DefaultOperatingSystemTypes.java index 59b7e1e51..11aded6b7 100644 --- a/common/src/main/java/com/sedmelluq/lava/common/natives/architecture/DefaultOperatingSystemTypes.java +++ b/common/src/main/java/com/sedmelluq/lava/common/natives/architecture/DefaultOperatingSystemTypes.java @@ -1,11 +1,25 @@ package com.sedmelluq.lava.common.natives.architecture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Paths; + public enum DefaultOperatingSystemTypes implements OperatingSystemType { LINUX("linux", "lib", ".so"), + LINUX_MUSL("linux-musl", "lib", ".so"), WINDOWS("win", "", ".dll"), DARWIN("darwin", "lib", ".dylib"), SOLARIS("solaris", "lib", ".so"); + private static final Logger log = LoggerFactory.getLogger(DefaultOperatingSystemTypes.class); + private static volatile Boolean cachedMusl; + private final String identifier; private final String libraryFilePrefix; private final String libraryFileSuffix; @@ -34,16 +48,40 @@ public String libraryFileSuffix() { public static OperatingSystemType detect() { String osFullName = System.getProperty("os.name"); - if (osFullName.startsWith("Windows")) { + if(osFullName.startsWith("Windows")) { return WINDOWS; - } else if (osFullName.startsWith("Mac OS X")) { + } else if(osFullName.startsWith("Mac OS X")) { return DARWIN; - } else if (osFullName.startsWith("Solaris")) { + } else if(osFullName.startsWith("Solaris")) { return SOLARIS; - } else if (osFullName.toLowerCase().startsWith("linux")) { - return LINUX; + } else if(osFullName.toLowerCase().startsWith("linux")) { + return checkMusl() ? LINUX_MUSL : LINUX; } else { throw new IllegalArgumentException("Unknown operating system: " + osFullName); } } + + private static boolean checkMusl() { + Boolean b = cachedMusl; + if(b == null) { + synchronized(DefaultOperatingSystemTypes.class) { + boolean check = false; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("/proc/self/maps"))))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("-musl-")) { + check = true; + break; + } + } + } catch(IOException fail) { + log.error("Failed to detect libc type, assuming glibc", fail); + check = false; + } + log.debug("is musl: {}", check); + b = cachedMusl = check; + } + } + return b; + } } diff --git a/main/build.gradle.kts b/main/build.gradle.kts index 26bb05bcc..9478d380d 100644 --- a/main/build.gradle.kts +++ b/main/build.gradle.kts @@ -9,7 +9,7 @@ version = "1.4.1-original" dependencies { api("com.sedmelluq:lava-common:1.1.2") - implementation("com.github.walkyst:lavaplayer-natives-fork:1.0.1") + implementation("com.github.walkyst:lavaplayer-natives-fork:1.0.2") implementation("com.github.walkyst.JAADec-fork:jaadec-ext-aac:0.1.3") implementation("org.mozilla:rhino-engine:1.7.14") api("org.slf4j:slf4j-api:1.7.25")