Also provide musl libc builds of Velocity natives
Reference: PaperMC/Paper#11367
This commit is contained in:
@@ -19,6 +19,7 @@ package com.velocitypowered.natives.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,8 @@ public class NativeConstraints {
|
||||
private static final boolean IS_AMD64;
|
||||
private static final boolean IS_AARCH64;
|
||||
private static final boolean CAN_GET_MEMORYADDRESS;
|
||||
private static final boolean IS_LINUX;
|
||||
private static final boolean IS_MUSL_LIBC;
|
||||
|
||||
static {
|
||||
ByteBuf test = Unpooled.directBuffer();
|
||||
@@ -41,17 +44,44 @@ public class NativeConstraints {
|
||||
String osArch = System.getProperty("os.arch", "");
|
||||
IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
|
||||
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
||||
|
||||
IS_LINUX = System.getProperty("os.name", "").equalsIgnoreCase("Linux");
|
||||
|
||||
// Determine if we're using musl libc by invoking `ldd --version`.
|
||||
if (IS_LINUX) {
|
||||
boolean isMusl;
|
||||
try {
|
||||
Process process = new ProcessBuilder("ldd", "--version")
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
process.waitFor();
|
||||
try (var reader = process.getInputStream()) {
|
||||
byte[] outputRaw = reader.readAllBytes();
|
||||
String output = new String(outputRaw, StandardCharsets.UTF_8);
|
||||
isMusl = output.contains("musl");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
isMusl = false;
|
||||
}
|
||||
IS_MUSL_LIBC = isMusl;
|
||||
} else {
|
||||
IS_MUSL_LIBC = false;
|
||||
}
|
||||
}
|
||||
|
||||
static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS;
|
||||
|
||||
static final BooleanSupplier LINUX_X86_64 = () -> NATIVE_BASE.getAsBoolean()
|
||||
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
|
||||
&& IS_AMD64;
|
||||
&& IS_LINUX && IS_AMD64 && !IS_MUSL_LIBC;
|
||||
|
||||
static final BooleanSupplier LINUX_X86_64_MUSL = () -> NATIVE_BASE.getAsBoolean()
|
||||
&& IS_LINUX && IS_AMD64 && IS_MUSL_LIBC;
|
||||
|
||||
static final BooleanSupplier LINUX_AARCH64 = () -> NATIVE_BASE.getAsBoolean()
|
||||
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
|
||||
&& IS_AARCH64;
|
||||
&& IS_LINUX && IS_AARCH64 && !IS_MUSL_LIBC;
|
||||
|
||||
static final BooleanSupplier LINUX_AARCH64_MUSL = () -> NATIVE_BASE.getAsBoolean()
|
||||
&& IS_LINUX && IS_AARCH64 && IS_MUSL_LIBC;
|
||||
|
||||
static final BooleanSupplier MACOS_AARCH64 = () -> NATIVE_BASE.getAsBoolean()
|
||||
&& System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X")
|
||||
|
@@ -83,11 +83,21 @@ public class Natives {
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64,
|
||||
copyAndLoadNative("/linux_x86_64/velocity-compress.so"),
|
||||
"libdeflate (Linux x86_64)",
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Debian 10
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Ubuntu 20.04
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64_MUSL,
|
||||
copyAndLoadNative("/linux_x86_64/velocity-compress-musl.so"),
|
||||
"libdeflate (Linux x86_64, musl)",
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Alpine 3.18
|
||||
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64,
|
||||
copyAndLoadNative("/linux_aarch64/velocity-compress.so"),
|
||||
"libdeflate (Linux aarch64)",
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Fedora 36
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Ubuntu 20.04
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64_MUSL,
|
||||
copyAndLoadNative("/linux_aarch64/velocity-compress-musl.so"),
|
||||
"libdeflate (Linux aarch64, musl)",
|
||||
LibdeflateVelocityCompressor.FACTORY), // compiled with Alpine 3.18
|
||||
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS_AARCH64,
|
||||
copyAndLoadNative("/macos_arm64/velocity-compress.dylib"),
|
||||
"libdeflate (macOS ARM64 / Apple Silicon)",
|
||||
@@ -108,6 +118,9 @@ public class Natives {
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64,
|
||||
copyAndLoadNative("/linux_x86_64/velocity-cipher-ossl11x.so"), // Ubuntu 20.04
|
||||
"OpenSSL 1.1.x (Linux x86_64)", NativeVelocityCipher.FACTORY),
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64_MUSL,
|
||||
copyAndLoadNative("/linux_x86_64/velocity-cipher-ossl30x-musl.so"), // Alpine 3.18
|
||||
"OpenSSL 3.x.x (Linux x86_64, musl)", NativeVelocityCipher.FACTORY),
|
||||
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64,
|
||||
copyAndLoadNative("/linux_aarch64/velocity-cipher.so"),
|
||||
@@ -118,6 +131,9 @@ public class Natives {
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64,
|
||||
copyAndLoadNative("/linux_aarch64/velocity-cipher-ossl11x.so"),
|
||||
"OpenSSL 1.1.x (Linux aarch64)", NativeVelocityCipher.FACTORY), // Ubuntu 20.04
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64_MUSL,
|
||||
copyAndLoadNative("/linux_aarch64/velocity-cipher-ossl30x-musl.so"),
|
||||
"OpenSSL 1.1.x (Linux aarch64, musl)", NativeVelocityCipher.FACTORY), // Alpine 3.18
|
||||
|
||||
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS_AARCH64,
|
||||
copyAndLoadNative("/macos_arm64/velocity-cipher.dylib"),
|
||||
|
BIN
native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x-musl.so
Executable file
BIN
native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x-musl.so
Executable file
Binary file not shown.
BIN
native/src/main/resources/linux_aarch64/velocity-compress-musl.so
Executable file
BIN
native/src/main/resources/linux_aarch64/velocity-compress-musl.so
Executable file
Binary file not shown.
BIN
native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x-musl.so
Executable file
BIN
native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x-musl.so
Executable file
Binary file not shown.
BIN
native/src/main/resources/linux_x86_64/velocity-compress-musl.so
Executable file
BIN
native/src/main/resources/linux_x86_64/velocity-compress-musl.so
Executable file
Binary file not shown.
Reference in New Issue
Block a user