Skip to content

Commit b81bc8d

Browse files
committed
fix: correctly load native libraries for OSes and architectures other than Windows
1 parent 7fc7483 commit b81bc8d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/main/java/io/github/benjaminamos/tracy/Tracy.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package io.github.benjaminamos.tracy;
55

6-
import java.nio.file.Paths;
6+
import java.io.File;
77

88
public final class Tracy {
99
private Tracy() {
@@ -12,9 +12,17 @@ private Tracy() {
1212
static {
1313
String libraryPath = System.getProperty("org.terasology.librarypath");
1414
if (libraryPath == null) {
15-
System.loadLibrary("tracy-jni");
15+
System.loadLibrary("tracy-jni-" + System.getProperty("os.arch"));
1616
} else {
17-
System.load(Paths.get(libraryPath + "/tracy-jni.dll").toAbsolutePath().toString());
17+
File libraryDirectory = new File(libraryPath);
18+
if (libraryDirectory.exists() && libraryDirectory.isDirectory()) {
19+
String architecture = System.getProperty("os.arch");
20+
for (File file : libraryDirectory.listFiles()) {
21+
if (file.getName().startsWith("tracy-jni-" + architecture) || file.getName().startsWith("libtracy-jni" + architecture)) {
22+
System.load(file.getPath());
23+
}
24+
}
25+
}
1826
}
1927
}
2028

tracy-jni/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
version = "1.0.0"
1111

1212
library {
13+
baseName = "tracy-jni-" + System.getProperty("os.arch")
1314
source.from(file("src"))
1415
privateHeaders.from(
1516
file("src"), file("tracy/public"),

0 commit comments

Comments
 (0)