diff --git a/native/compile-native-arm.sh b/native/compile-native-arm.sh new file mode 100755 index 00000000..f3e2fd59 --- /dev/null +++ b/native/compile-native-arm.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -eu + +CWD=$(pwd) + +echo "Compiling mbedtls" +(cd mbedtls && CFLAGS="-fPIC -I$CWD/src/main/c -DMBEDTLS_USER_CONFIG_FILE=''" make CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar no_test) + +echo "Compiling zlib" +(cd zlib && CFLAGS="-fPIC -DNO_GZIP" CC=aarch64-linux-gnu-gcc CHOST=arm64 ./configure --target="aarch64" --static && make CFLAGS="-fPIC -march=armv8-a+crc" CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar) + +CC="aarch64-linux-gnu-gcc" +CFLAGS="-c -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/" +LDFLAGS="-shared" + +echo "Compiling bungee" +$CC $CFLAGS -o shared.o src/main/c/shared.c +$CC $CFLAGS -Imbedtls/include -o NativeCipherImpl.o src/main/c/NativeCipherImpl.c +$CC $CFLAGS -Izlib -o NativeCompressImpl.o src/main/c/NativeCompressImpl.c + +echo "Linking native-cipher-arm.so" +$CC $LDFLAGS -o src/main/resources/native-cipher-arm.so shared.o NativeCipherImpl.o mbedtls/library/libmbedcrypto.a + +echo "Linking native-compress-arm.so" +$CC $LDFLAGS -o src/main/resources/native-compress-arm.so shared.o NativeCompressImpl.o zlib/libz.a + +echo "Cleaning up" +rm shared.o NativeCipherImpl.o NativeCompressImpl.o diff --git a/native/src/main/c/NativeCompressImpl.c b/native/src/main/c/NativeCompressImpl.c index b6b27682..dee50c6a 100644 --- a/native/src/main/c/NativeCompressImpl.c +++ b/native/src/main/c/NativeCompressImpl.c @@ -3,7 +3,9 @@ #include #include "shared.h" +#if !defined(__aarch64__) #include "cpuid_helper.h" +#endif #include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h" typedef unsigned char byte; @@ -28,7 +30,11 @@ jint throwException(JNIEnv *env, const char* message, int err) { } JNIEXPORT jboolean JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_checkSupported(JNIEnv* env, jobject obj) { - return (jboolean) checkCompressionNativesSupport(); + #if !defined(__aarch64__) + return (jboolean) checkCompressionNativesSupport(); + #else + return JNI_TRUE; + #endif } void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_reset(JNIEnv* env, jobject obj, jlong ctx, jboolean compress) { diff --git a/native/src/main/java/net/md_5/bungee/jni/NativeCode.java b/native/src/main/java/net/md_5/bungee/jni/NativeCode.java index be4d5b0b..4426823c 100644 --- a/native/src/main/java/net/md_5/bungee/jni/NativeCode.java +++ b/native/src/main/java/net/md_5/bungee/jni/NativeCode.java @@ -43,6 +43,7 @@ public final class NativeCode { if ( enableNativeFlag && !loaded && isSupported() ) { + String name = this.name + ( isAarch64() ? "-arm" : "" ); String fullName = "bungeecord-" + name; try @@ -94,6 +95,16 @@ public final class NativeCode public static boolean isSupported() { - return "Linux".equals( System.getProperty( "os.name" ) ) && "amd64".equals( System.getProperty( "os.arch" ) ); + return "Linux".equals( System.getProperty( "os.name" ) ) && ( isAmd64() || isAarch64() ); + } + + private static boolean isAmd64() + { + return "amd64".equals( System.getProperty( "os.arch" ) ); + } + + private static boolean isAarch64() + { + return "aarch64".equals( System.getProperty( "os.arch" ) ); } } diff --git a/native/src/main/resources/native-cipher-arm.so b/native/src/main/resources/native-cipher-arm.so new file mode 100755 index 00000000..512c82b4 Binary files /dev/null and b/native/src/main/resources/native-cipher-arm.so differ diff --git a/native/src/main/resources/native-compress-arm.so b/native/src/main/resources/native-compress-arm.so new file mode 100755 index 00000000..abbc6913 Binary files /dev/null and b/native/src/main/resources/native-compress-arm.so differ