Skip to content

Commit

Permalink
Merge pull request #99 from TopiSenpai/musl-support
Browse files Browse the repository at this point in the history
musl support
  • Loading branch information
Walkyst authored Jun 4, 2023
2 parents 45b5dd1 + bacb93e commit 63d53ca
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 63d53ca

Please sign in to comment.