From b81bc8d6863e30de661d675743f484091085b8c1 Mon Sep 17 00:00:00 2001 From: Benjamin Amos Date: Sat, 13 Jul 2024 17:32:27 +0100 Subject: [PATCH] fix: correctly load native libraries for OSes and architectures other than Windows --- .../java/io/github/benjaminamos/tracy/Tracy.java | 14 +++++++++++--- tracy-jni/build.gradle.kts | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/benjaminamos/tracy/Tracy.java b/src/main/java/io/github/benjaminamos/tracy/Tracy.java index 6febd0b..32ba9e7 100644 --- a/src/main/java/io/github/benjaminamos/tracy/Tracy.java +++ b/src/main/java/io/github/benjaminamos/tracy/Tracy.java @@ -3,7 +3,7 @@ package io.github.benjaminamos.tracy; -import java.nio.file.Paths; +import java.io.File; public final class Tracy { private Tracy() { @@ -12,9 +12,17 @@ private Tracy() { static { String libraryPath = System.getProperty("org.terasology.librarypath"); if (libraryPath == null) { - System.loadLibrary("tracy-jni"); + System.loadLibrary("tracy-jni-" + System.getProperty("os.arch")); } else { - System.load(Paths.get(libraryPath + "/tracy-jni.dll").toAbsolutePath().toString()); + File libraryDirectory = new File(libraryPath); + if (libraryDirectory.exists() && libraryDirectory.isDirectory()) { + String architecture = System.getProperty("os.arch"); + for (File file : libraryDirectory.listFiles()) { + if (file.getName().startsWith("tracy-jni-" + architecture) || file.getName().startsWith("libtracy-jni" + architecture)) { + System.load(file.getPath()); + } + } + } } } diff --git a/tracy-jni/build.gradle.kts b/tracy-jni/build.gradle.kts index c2cb695..d36b208 100644 --- a/tracy-jni/build.gradle.kts +++ b/tracy-jni/build.gradle.kts @@ -10,6 +10,7 @@ plugins { version = "1.0.0" library { + baseName = "tracy-jni-" + System.getProperty("os.arch") source.from(file("src")) privateHeaders.from( file("src"), file("tracy/public"),