Skip to content

Commit

Permalink
Added support for Bionic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Oct 13, 2021
1 parent 6d0a77b commit 944cb1d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 43 deletions.
41 changes: 22 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ all: releasejar

RUST_SOURCE_FILES := $(shell find lib/src -type f)

# Release - Linux x86_64
lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-xenial-builder release
# Release - Linux x86_64 Xenial
lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-xenial.so: ${RUST_SOURCE_FILES}
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-amd64-xenial-builder release
mv lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-xenial.so

# Release - Linux x86_64 Focal
lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-focal.so: ${RUST_SOURCE_FILES}
docker run -v "${CURDIR}/lib/:/code" docker-registry.k8s.array21.dev/rust-amd64-focal-builder release
mv lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-focal.so

# Release - Linux x86_64 Bionic
lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-bionic.so: ${RUST_SOURCE_FILES}
docker run -v "${CURDIR}/lib/:/code" docker-registry.k8s.array21.dev/rust-amd64-bionic-builder release
mv lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-bionic.so

# Release - Linux aarch64
lib/target/aarch64-unknown-linux-gnu/release/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-aarch64-builder release
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-aarch64-focal-builder release

# Release - Linux armhf
lib/target/arm-unknown-linux-gnueabihf/release/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-armhf-builder release
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-armhf-focal-builder release

# Release - Windows x86_64
lib/target/x86_64-pc-windows-gnu/release/libskinfixer.dll: ${RUST_SOURCE_FILES}
Expand All @@ -26,23 +34,19 @@ lib/target/x86_64-pc-windows-gnu/release/libskinfixer.dll: ${RUST_SOURCE_FILES}

# Release - Darwin x86_64
lib/target/x86_64-apple-darwin/release/libskinfixer.dylib: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-macos-builder release
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-amd64-darwin-builder release

# Debug - Linux x86_64
lib/target/x86_64-unknown-linux-gnu/debug/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-xenial-builder
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-amd64-focal-builder

# Debug - Linux aarch64
lib/target/aarch64-unknown-linux-gnu/debug/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-aarch64-builder
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-aarch64-focal-builder

# Debug - Linux armhf
lib/target/arm-unknown-linux-gnueabihf/debug/libskinfixer.so: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-armhf-builder
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-armhf-focal-builder

# Debug - Windows x86_64
lib/target/x86_64-pc-windows-gnu/debug/libskinfixer.dll: ${RUST_SOURCE_FILES}
Expand All @@ -52,15 +56,14 @@ lib/target/x86_64-pc-windows-gnu/debug/libskinfixer.dll: ${RUST_SOURCE_FILES}

# Debug - Darwin x86_64
lib/target/x86_64-apple-darwin/debug/libskinfixer.dylib: ${RUST_SOURCE_FILES}
cd lib; \
docker run -v "${PWD}/lib/:/code/" docker-registry.k8s.array21.dev/rust-macos-builder
docker run -v "${CURDIR}/lib/:/code/" docker-registry.k8s.array21.dev/rust-amd64-darwin-builder

testjar: lib/target/x86_64-unknown-linux-gnu/debug/libskinfixer.so lib/target/aarch64-unknown-linux-gnu/debug/libskinfixer.so lib/target/arm-unknown-linux-gnueabihf/debug/libskinfixer.so lib/target/x86_64-pc-windows-gnu/debug/libskinfixer.dll lib/target/x86_64-apple-darwin/debug/libskinfixer.dylib
chmod +x gradlew;
rm -rf ./build/resources
./gradlew testjar

releasejar: lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so lib/target/aarch64-unknown-linux-gnu/release/libskinfixer.so lib/target/arm-unknown-linux-gnueabihf/release/libskinfixer.so lib/target/x86_64-pc-windows-gnu/release/libskinfixer.dll lib/target/x86_64-apple-darwin/release/libskinfixer.dylib
releasejar: lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-focal.so lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-bionic.so lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-xenial.so lib/target/aarch64-unknown-linux-gnu/release/libskinfixer.so lib/target/arm-unknown-linux-gnueabihf/release/libskinfixer.so lib/target/x86_64-pc-windows-gnu/release/libskinfixer.dll lib/target/x86_64-apple-darwin/release/libskinfixer.dylib
chmod +x gradlew
rm -rf ./build/resources
./gradlew releasejar
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ allprojects {
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'

implementation 'com.github.TheDutchMC:HttpLib:1.1'
implementation 'com.github.TheDutchMC:HttpLib:1.1'
implementation 'dev.array21:classvalidator:1.0.0'
implementation 'dev.array21:pluginstatlib:1.0.5'

Expand Down Expand Up @@ -82,6 +82,7 @@ task copyDependenciesDebug() {

task copyDependenciesRelease() {
dependsOn('copyLinuxLibraryReleaseX86Focal')
dependsOn('copyLinuxLibraryReleaseX86Bionic')
dependsOn('copyLinuxLibraryReleaseX86Xenial')

dependsOn('copyLinuxLibraryReleaseAarch64')
Expand All @@ -94,10 +95,16 @@ task copyDependenciesRelease() {

// Linux X86 Focal - Release
task copyLinuxLibraryReleaseX86Focal(type: Copy) {
from "$rootDir/lib/target/x86_64-unknown-linux-gnu/release/libskinfixer.so"
from "$rootDir/lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-focal.so"
into "$buildDir/resources/main/x86_64/linux"
}

// Linux X86 Bionic - Release
task copyLinuxLibraryReleaseX86Bionic(type: Copy) {
from "$rootDir/lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-bionic.so"
into "$buildDir/resources/main/x86_64/linux"
}

// Linux X86 Xenial - Release
task copyLinuxLibraryReleaseX86Xenial(type: Copy) {
from "$rootDir/lib/target/x86_64-unknown-linux-gnu/release/libskinfixer-xenial.so"
Expand Down Expand Up @@ -157,4 +164,4 @@ task copyDarwinLibraryDebugX86(type: Copy) {
task copyWindowsLibraryRelease(type: Copy) {
from "$rootDir/lib/target/x86_64-pc-windows-gnu/release/libskinfixer.dll"
into "$buildDir/resources/main/x86_64/windows"
}
}
56 changes: 35 additions & 21 deletions src/main/java/dev/array21/skinfixer/storage/LibWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dev.array21.skinfixer.config.ConfigManifest;
import dev.array21.skinfixer.config.SqlSettings;
import dev.array21.skinfixer.util.Pair;
import dev.array21.skinfixer.util.Utils;

public class LibWrapper {

Expand All @@ -25,7 +26,7 @@ public class LibWrapper {
String osName = System.getProperty("os.name").toLowerCase();
if(osName.contains("linux")) {
switch(System.getProperty("os.arch")) {
case "amd64": libName = "/x86_64/linux/libskinfixer.so"; break;
case "amd64": libName = "/x86_64/linux/libskinfixer-focal.so"; break;
case "arm": libName = "/armhf/linux/libskinfixer.so"; break;
case "aarch64": libName = "/aarch64/linux/libskinfixer.so"; break;
default:
Expand Down Expand Up @@ -65,28 +66,19 @@ public class LibWrapper {
System.load(libTmpFile.getAbsolutePath());
} catch(UnsatisfiedLinkError e) {
if(osName.contains("linux")) {
SkinFixer.logWarn("Failed to load library: " + e.getMessage());
SkinFixer.logWarn("Attempting to load library linked against an older version of GLIBC (Compiled on Ubuntu Xenial)");

libTmpFile.delete();
tmpDir.delete();
SkinFixer.logWarn("Failed to load libskinfixer Focal. Trying Bionic.");

Pair<File, File> pairedFileXenial = saveLib("/x86_64/linux/libskinfixer-xenial.so");
if(pairedFileXenial == null) {
break saveLib;
}

File tmpFolderXenial = pairedFileXenial.getA();
File libTmpFileXenial = pairedFileXenial.getB();

try {
System.load(libTmpFileXenial.getAbsolutePath());
} catch(UnsatisfiedLinkError e1) {
libTmpFileXenial.delete();
tmpFolderXenial.delete();
String loadBionicError = tryLoadAmd64Linux("bionic");
if(loadBionicError != null) {
SkinFixer.logWarn(loadBionicError);
SkinFixer.logWarn("Failed to load libskinfixer Bionic. Trying Xenial.");

SkinFixer.logWarn("Failed to load library linked to older version of GLIBC (Compiled on Ubuntu Xenial): " + e1.getMessage());
printLibDebugHelp();
String loadXenialError = tryLoadAmd64Linux("xenial");
if(loadXenialError != null) {
SkinFixer.logWarn(loadXenialError);
SkinFixer.logWarn("Failed to load libskinfixer Focal.");
printLibDebugHelp();
}
}
} else {
SkinFixer.logWarn("Failed to load library: " + e.getMessage());
Expand All @@ -98,10 +90,32 @@ public class LibWrapper {
}
}

SkinFixer.logInfo("libskinfixer loaded.");
LIB_LOADED = true;
}
}

private static String tryLoadAmd64Linux(String distro) {
String name = String.format("/x86_64/linux/libskinfixer-%s.so", distro);
Pair<File, File> pairedFile = saveLib(name);
if(pairedFile == null) {
return String.format("Failed to save library libskinfixer-%.so", distro);
}

File tmpFolder = pairedFile.getA();
File libTmpFile = pairedFile.getB();

try {
System.load(libTmpFile.getAbsolutePath());
} catch(UnsatisfiedLinkError e) {
libTmpFile.delete();
tmpFolder.delete();
return String.format("Failed to load library libskinfixer-%.so: %s", distro, Utils.getStackTrace(e));
}

return null;
}

private static void printLibDebugHelp() {
SkinFixer.logWarn("Check that all required dependencies are installed.");
SkinFixer.logWarn("You should make sure that you are using GLIBC >=2.23.");
Expand Down

0 comments on commit 944cb1d

Please sign in to comment.