Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[photon-targeting] Fix JNI loading #1563

Merged
merged 13 commits into from
Nov 13, 2024
1 change: 1 addition & 0 deletions photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ model {
}
if(project.hasProperty('includePhotonTargeting')) {
lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared'
lib project: ':photon-targeting', library: 'photontargetingJNI', linkage: 'shared'
}
}

Expand Down
13 changes: 0 additions & 13 deletions photon-lib/src/generate/photonlib.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@
"linuxx86-64",
"osxuniversal"
]
},
{
"groupId": "org.photonvision",
"artifactId": "photontargeting-jni",
"version": "${photon_version}",
"skipInvalidPlatforms": true,
"isJar": true,
"validPlatforms": [
"windowsx86-64",
"linuxathena",
"linuxx86-64",
"osxuniversal"
Gold856 marked this conversation as resolved.
Show resolved Hide resolved
]
}
],
"cppDependencies": [
Expand Down
2 changes: 2 additions & 0 deletions photon-targeting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ model {
}

binaries.all {
lib library: nativeName, linkage: 'shared'
lib library: "${nativeName}JNI", linkage: 'shared'
it.tasks.withType(CppCompile) {
it.dependsOn generateProto
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.photonvision.jni;

import edu.wpi.first.util.RuntimeDetector;
import edu.wpi.first.util.RuntimeLoader;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -30,7 +29,8 @@ public class PhotonTargetingJniLoader {
public static boolean isWorking = false;

public static boolean load() throws IOException, UnsatisfiedLinkError {
if (isWorking) return true;
if (isWorking)
return true;
isWorking = load_();
return isWorking;
}
Expand All @@ -42,10 +42,11 @@ public static boolean load_() throws IOException, UnsatisfiedLinkError {
var clazz = PhotonTargetingJniLoader.class;

for (var libraryName : List.of("photontargeting", "photontargetingJNI")) {
if (RuntimeDetector.isAthena()) {
System.out.println("Detected rio - loading directly");
try {
RuntimeLoader.loadLibrary(libraryName);
continue;
return true;
} catch (Exception e) {
System.out.println("Direct library load failed; falling back to extraction");
}

var nativeLibName = System.mapLibraryName(libraryName);
Expand Down
5 changes: 4 additions & 1 deletion shared/javacpp/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ addTaskToCopyAllOutputs(cppHeadersZip)

model {
publishing {
def cppTaskList = createComponentZipTasks($.components, [nativeName], zipBaseName, Zip, project, includeStandardZipFormat)
def cppTaskList = createComponentZipTasks($.components, [
nativeName,
"${nativeName}JNI"
], zipBaseName, Zip, project, includeStandardZipFormat)

// From https://github.com/wpilibsuite/allwpilib/blob/1c220ebc607daa8da7d983b8f17bc40323633cb2/shared/jni/publish.gradle#L80C9-L100C11
def jniTaskList = createComponentZipTasks($.components, ["${nativeName}JNI"], jniBaseName, Jar, project, { task, value ->
Expand Down
Loading