diff --git a/native/build-support/build-all-linux-natives.sh b/native/build-support/build-all-linux-natives.sh new file mode 100755 index 000000000..32397f591 --- /dev/null +++ b/native/build-support/build-all-linux-natives.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +# make sure we're in the correct directory - the top-level `native` directory +cd "$(dirname "$0")/.." || exit 1 + +ARCHS=(x86_64 aarch64) +BASE_DOCKERFILE_VARIANTS=(ubuntu-focal ubuntu-jammy) + +for variant in "${BASE_DOCKERFILE_VARIANTS[@]}"; do + docker_platforms="" + for arch in "${ARCHS[@]}"; do + docker_platforms="$docker_platforms --platform linux/${arch}" + done + + echo "Building base build image for $variant..." + docker build -t velocity-native-build:$variant $docker_platforms -f build-support/$variant.Dockerfile . +done + +for arch in "${ARCHS[@]}"; do + for variant in "${BASE_DOCKERFILE_VARIANTS[@]}"; do + echo "Building native crypto for $arch on $variant..." + + docker run --rm -v "$(pwd)":/app --platform linux/${arch} velocity-native-build:$variant /bin/bash -c "cd /app && ./build-support/compile-linux-crypto.sh" + done + + # Use only the oldest variant for the compression library + variant=${BASE_DOCKERFILE_VARIANTS[0]} + echo "Building native compression for $arch on $variant..." + docker run --rm -v "$(pwd)":/app --platform linux/${arch} velocity-native-build:$variant /bin/bash -c "cd /app && ./build-support/compile-linux-compress.sh" +done \ No newline at end of file diff --git a/native/compile-linux.sh b/native/build-support/compile-linux-compress.sh similarity index 70% rename from native/compile-linux.sh rename to native/build-support/compile-linux-compress.sh index bf2c336c6..b03ca37cf 100755 --- a/native/compile-linux.sh +++ b/native/build-support/compile-linux-compress.sh @@ -8,18 +8,16 @@ fi if [ ! -d libdeflate ]; then echo "Cloning libdeflate..." - git clone https://github.com/ebiggers/libdeflate.git + git clone --branch v1.21 --single-branch https://github.com/ebiggers/libdeflate.git fi echo "Compiling libdeflate..." cd libdeflate || exit -cmake -B build && cmake --build build --target libdeflate_static +rm -rf build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -B build && cmake --build build --target libdeflate_static cd .. CFLAGS="-O2 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared -Wl,-z,noexecstack -Wall -Werror -fomit-frame-pointer" ARCH=$(uname -m) mkdir -p src/main/resources/linux_$ARCH $CC $CFLAGS -Ilibdeflate src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ - libdeflate/build/libdeflate.a -o src/main/resources/linux_$ARCH/velocity-compress.so -$CC $CFLAGS -shared src/main/c/jni_util.c src/main/c/jni_cipher_openssl.c \ - -o src/main/resources/linux_$ARCH/velocity-cipher.so -lcrypto \ No newline at end of file + libdeflate/build/libdeflate.a -o src/main/resources/linux_$ARCH/velocity-compress.so \ No newline at end of file diff --git a/native/build-support/compile-linux-crypto.sh b/native/build-support/compile-linux-crypto.sh new file mode 100755 index 000000000..221656647 --- /dev/null +++ b/native/build-support/compile-linux-crypto.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +openssl_version=$(openssl version | awk '{print $2}') + +# Extract the major and minor version numbers +major_version=$(echo "$openssl_version" | cut -d. -f1) +minor_version=$(echo "$openssl_version" | cut -d. -f2) + +# Determine the appropriate file name based on the version +if [ "$major_version" -eq 1 ] && [ "$minor_version" -eq 1 ]; then + filename="velocity-cipher-ossl11x.so" +elif [ "$major_version" -eq 3 ]; then + filename="velocity-cipher-ossl30x.so" +else + echo "Unsupported OpenSSL version: $openssl_version" + exit 1 +fi + +if [ ! "$CC" ]; then + export CC=gcc +fi + +output_file="velocity-cipher.so" +if [ -n "$OPENSSL_VERSION" ]; then + output_file="velocity-cipher-ossl${OPENSSL_VERSION}.so" +fi + +CFLAGS="-O2 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared -Wl,-z,noexecstack -Wall -Werror -fomit-frame-pointer" +ARCH=$(uname -m) +mkdir -p src/main/resources/linux_$ARCH +$CC $CFLAGS -shared src/main/c/jni_util.c src/main/c/jni_cipher_openssl.c \ + -o src/main/resources/linux_$ARCH/$filename -lcrypto \ No newline at end of file diff --git a/native/compile-macos.sh b/native/build-support/compile-macos.sh similarity index 89% rename from native/compile-macos.sh rename to native/build-support/compile-macos.sh index 732c1a164..7120cbe5f 100755 --- a/native/compile-macos.sh +++ b/native/build-support/compile-macos.sh @@ -6,7 +6,7 @@ fi if [ ! -d libdeflate ]; then echo "Cloning libdeflate..." - git clone https://github.com/ebiggers/libdeflate.git + git clone --branch v1.21 --single-branch https://github.com/ebiggers/libdeflate.git fi echo "Compiling libdeflate..." diff --git a/native/build-support/ubuntu-focal.Dockerfile b/native/build-support/ubuntu-focal.Dockerfile new file mode 100644 index 000000000..058a14f49 --- /dev/null +++ b/native/build-support/ubuntu-focal.Dockerfile @@ -0,0 +1,20 @@ +# Use the official Eclipse Temurin 17.0.12_7-jdk-focal image as the base image. +# We compile for Ubuntu Focal Fossa (20.04 LTS) as it is still supported until 2025, and the crypto +# native is specific to a given OpenSSL version. +FROM eclipse-temurin:17.0.12_7-jdk-focal + +# Install required dependencies +RUN apt-get update && apt-get install -y \ + libssl-dev \ + curl \ + git \ + unzip \ + build-essential \ + cmake \ + openssl \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean + +# Create a non-root user +RUN useradd -m -s /bin/bash -u 1000 -U user +USER user \ No newline at end of file diff --git a/native/build-support/ubuntu-jammy.Dockerfile b/native/build-support/ubuntu-jammy.Dockerfile new file mode 100644 index 000000000..f2224a107 --- /dev/null +++ b/native/build-support/ubuntu-jammy.Dockerfile @@ -0,0 +1,19 @@ +# Use the official Eclipse Temurin 17.0.12_7-jdk-jammy image as the base image. +# We compile for Ubuntu Jammy Jellyfish (22.04 LTS) as it supports OpenSSL 3.0. +FROM eclipse-temurin:17.0.12_7-jdk-jammy + +# Install required dependencies +RUN apt-get update && apt-get install -y \ + libssl-dev \ + curl \ + git \ + unzip \ + build-essential \ + cmake \ + openssl \ + && rm -rf /var/lib/apt/lists/* \ + && apt-get clean + +# Create a non-root user +RUN useradd -m -s /bin/bash -u 1000 -U user +USER user \ No newline at end of file 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 6dd204abe..1c1e26cea 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -103,21 +103,21 @@ public class Natives { copyAndLoadNative("/linux_x86_64/velocity-cipher.so"), // Any local version "OpenSSL local (Linux x86_64)", NativeVelocityCipher.FACTORY), new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64, - copyAndLoadNative("/linux_x86_64/velocity-cipher-ossl30x.so"), // Debian "Bookworm" - "OpenSSL 3.0.x (Linux x86_64)", NativeVelocityCipher.FACTORY), + copyAndLoadNative("/linux_x86_64/velocity-cipher-ossl30x.so"), // Ubuntu 22.04 + "OpenSSL 3.x.x (Linux x86_64)", NativeVelocityCipher.FACTORY), new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_X86_64, - copyAndLoadNative("/linux_x86_64/velocity-cipher-ossl11x.so"), // Debian 9 + 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_AARCH64, copyAndLoadNative("/linux_aarch64/velocity-cipher.so"), - "OpenSSL (Linux aarch64)", NativeVelocityCipher.FACTORY), // Any local version + "OpenSSL local (Linux aarch64)", NativeVelocityCipher.FACTORY), // Any local version new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64, copyAndLoadNative("/linux_aarch64/velocity-cipher-ossl30x.so"), - "OpenSSL (Linux aarch64)", NativeVelocityCipher.FACTORY), // Fedora 36 + "OpenSSL 3.x.x (Linux aarch64)", NativeVelocityCipher.FACTORY), // Ubuntu 22.04 new NativeCodeLoader.Variant<>(NativeConstraints.LINUX_AARCH64, copyAndLoadNative("/linux_aarch64/velocity-cipher-ossl11x.so"), - "OpenSSL 1.1.x (Linux aarch64)", NativeVelocityCipher.FACTORY), // Debian 11 + "OpenSSL 1.1.x (Linux aarch64)", NativeVelocityCipher.FACTORY), // Ubuntu 20.04 new NativeCodeLoader.Variant<>(NativeConstraints.MACOS_AARCH64, copyAndLoadNative("/macos_arm64/velocity-cipher.dylib"), diff --git a/native/src/main/resources/linux_aarch64/velocity-cipher-ossl11x.so b/native/src/main/resources/linux_aarch64/velocity-cipher-ossl11x.so index aa0a489e9..d79e34a2c 100755 Binary files a/native/src/main/resources/linux_aarch64/velocity-cipher-ossl11x.so and b/native/src/main/resources/linux_aarch64/velocity-cipher-ossl11x.so differ diff --git a/native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x.so b/native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x.so index c86f1024f..814b22a60 100755 Binary files a/native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x.so and b/native/src/main/resources/linux_aarch64/velocity-cipher-ossl30x.so differ diff --git a/native/src/main/resources/linux_aarch64/velocity-compress.so b/native/src/main/resources/linux_aarch64/velocity-compress.so index 2f600e189..33c11ffb2 100755 Binary files a/native/src/main/resources/linux_aarch64/velocity-compress.so and b/native/src/main/resources/linux_aarch64/velocity-compress.so differ diff --git a/native/src/main/resources/linux_x86_64/velocity-cipher-ossl11x.so b/native/src/main/resources/linux_x86_64/velocity-cipher-ossl11x.so index 179b1c9e6..1b2e11721 100755 Binary files a/native/src/main/resources/linux_x86_64/velocity-cipher-ossl11x.so and b/native/src/main/resources/linux_x86_64/velocity-cipher-ossl11x.so differ diff --git a/native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x.so b/native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x.so index cb88a8d4d..259b1b3f0 100755 Binary files a/native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x.so and b/native/src/main/resources/linux_x86_64/velocity-cipher-ossl30x.so differ diff --git a/native/src/main/resources/linux_x86_64/velocity-compress.so b/native/src/main/resources/linux_x86_64/velocity-compress.so index cda376fa2..68ad4c73b 100755 Binary files a/native/src/main/resources/linux_x86_64/velocity-compress.so and b/native/src/main/resources/linux_x86_64/velocity-compress.so differ diff --git a/native/src/main/resources/macos_arm64/velocity-cipher.dylib b/native/src/main/resources/macos_arm64/velocity-cipher.dylib index 1640b3850..552a6fd47 100755 Binary files a/native/src/main/resources/macos_arm64/velocity-cipher.dylib and b/native/src/main/resources/macos_arm64/velocity-cipher.dylib differ diff --git a/native/src/main/resources/macos_arm64/velocity-compress.dylib b/native/src/main/resources/macos_arm64/velocity-compress.dylib deleted file mode 100755 index 333c62e6e..000000000 Binary files a/native/src/main/resources/macos_arm64/velocity-compress.dylib and /dev/null differ