Skip to content

Commit

Permalink
fix: correctly load native libraries for OSes and architectures other…
Browse files Browse the repository at this point in the history
… than Windows
  • Loading branch information
BenjaminAmos committed Jul 13, 2024
1 parent 7fc7483 commit b81bc8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/io/github/benjaminamos/tracy/Tracy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package io.github.benjaminamos.tracy;

import java.nio.file.Paths;
import java.io.File;

public final class Tracy {
private Tracy() {
Expand All @@ -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());
}
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tracy-jni/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit b81bc8d

Please sign in to comment.