From 5f740af1e36bcb81184b24e28d477e0db3a9363a Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Tue, 18 Apr 2023 10:36:53 +0200 Subject: [PATCH 1/4] add support to detect musl --- .../DefaultOperatingSystemTypes.java | 48 +++++++++++++++++-- main/build.gradle.kts | 2 +- 2 files changed, 44 insertions(+), 6 deletions(-) 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..7f401c55a 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,22 @@ package com.sedmelluq.lava.common.natives.architecture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + 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 +45,43 @@ 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; + try { + Process p = new ProcessBuilder("ldd", "--version") + .start(); + log.debug("Exit code: {}", p.waitFor()); + String line = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine(); + log.debug("First line of stdout: {}", line); + if(line == null) { + line = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine(); + log.debug("First line of stderr: {}", line); + } + check = line != null && line.toLowerCase().startsWith("musl"); + } catch(IOException | InterruptedException 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 3b45a5538..ee095d34f 100644 --- a/main/build.gradle.kts +++ b/main/build.gradle.kts @@ -9,7 +9,7 @@ version = "1.4.0-original" dependencies { api("com.sedmelluq:lava-common:1.1.2") - implementation("com.github.walkyst:lavaplayer-natives-fork:1.0.1") + implementation("com.github.topisenpai:lavaplayer-natives-fork:aeebbbc724") 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") From cf59bd75ed96ff0e3ffaf16b388735b5105e6f96 Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Mon, 8 May 2023 23:30:03 +0200 Subject: [PATCH 2/4] use full musl lavaplayer-natives-fork --- main/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/build.gradle.kts b/main/build.gradle.kts index 3f582f004..da0ba1a3e 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.topisenpai:lavaplayer-natives-fork:aeebbbc724") + implementation("com.github.topisenpai:lavaplayer-natives-fork:a4b538444f") 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") From af338b379f601ea74152943cd7a27efe402d3eb3 Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Tue, 9 May 2023 09:21:28 +0200 Subject: [PATCH 3/4] use other way to see if system is musl --- .../DefaultOperatingSystemTypes.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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 7f401c55a..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 @@ -4,8 +4,11 @@ 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"), @@ -62,19 +65,16 @@ private static boolean checkMusl() { Boolean b = cachedMusl; if(b == null) { synchronized(DefaultOperatingSystemTypes.class) { - boolean check; - try { - Process p = new ProcessBuilder("ldd", "--version") - .start(); - log.debug("Exit code: {}", p.waitFor()); - String line = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine(); - log.debug("First line of stdout: {}", line); - if(line == null) { - line = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine(); - log.debug("First line of stderr: {}", line); + 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; + } } - check = line != null && line.toLowerCase().startsWith("musl"); - } catch(IOException | InterruptedException fail) { + } catch(IOException fail) { log.error("Failed to detect libc type, assuming glibc", fail); check = false; } From bacb93ec0a0cbe4ca4f4122206fb52ed463f5c6f Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Sun, 4 Jun 2023 18:16:20 +0200 Subject: [PATCH 4/4] update lavaplayer natives dependencies --- main/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/build.gradle.kts b/main/build.gradle.kts index da0ba1a3e..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.topisenpai:lavaplayer-natives-fork:a4b538444f") + 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")