diff --git a/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java b/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java index ab9604217..5a9dcb35d 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java +++ b/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java @@ -7,6 +7,7 @@ import java.util.function.BooleanSupplier; public class NativeConstraints { private static final boolean NATIVES_ENABLED = !Boolean.getBoolean("velocity.natives-disabled"); private static final boolean IS_AMD64; + private static final boolean IS_AARCH64; private static final boolean CAN_GET_MEMORYADDRESS; static { @@ -21,15 +22,23 @@ public class NativeConstraints { // HotSpot on Intel macOS prefers x86_64, but OpenJ9 on macOS and HotSpot/OpenJ9 elsewhere // give amd64. IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64"); + IS_AARCH64 = osArch.equals("aarch64"); } - static final BooleanSupplier LINUX = () -> { - return NATIVES_ENABLED - && CAN_GET_MEMORYADDRESS + static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS; + + static final BooleanSupplier LINUX_X86_64 = () -> { + return NATIVE_BASE.getAsBoolean() && System.getProperty("os.name", "").equalsIgnoreCase("Linux") && IS_AMD64; }; + static final BooleanSupplier LINUX_AARCH64 = () -> { + return NATIVE_BASE.getAsBoolean() + && System.getProperty("os.name", "").equalsIgnoreCase("Linux") + && IS_AARCH64; + }; + static final BooleanSupplier JAVA_11 = () -> { return Double.parseDouble(System.getProperty("java.specification.version")) >= 11; }; diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index 4a9d428df..120ec1ee7 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -62,11 +62,11 @@ public class Natives { public static final NativeCodeLoader compress = new NativeCodeLoader<>( ImmutableList.of( - new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64, copyAndLoadNative("/linux_x86_64/velocity-compress.so"), "libdeflate (Linux x86_64)", LibdeflateVelocityCompressor.FACTORY), - new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64, copyAndLoadNative("/linux_aarch64/velocity-compress.so"), "libdeflate (Linux aarch64)", LibdeflateVelocityCompressor.FACTORY), @@ -79,10 +79,10 @@ public class Natives { public static final NativeCodeLoader cipher = new NativeCodeLoader<>( ImmutableList.of( - new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64, copyAndLoadNative("/linux_x86_64/velocity-cipher.so"), "mbed TLS (Linux x86_64)", NativeVelocityCipher.FACTORY), - new NativeCodeLoader.Variant<>(NativeConstraints.LINUX, + new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64, copyAndLoadNative("/linux_aarch64/velocity-cipher.so"), "mbed TLS (Linux aarch64)", NativeVelocityCipher.FACTORY), new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {