[photon-targeting] Fix JNI loading (#1563)

This commit is contained in:
Gold856
2024-11-13 10:37:51 -05:00
committed by GitHub
parent 744e522aea
commit c7ed37789e
7 changed files with 67 additions and 23 deletions

View File

@@ -39,8 +39,20 @@ jobs:
name: built-client
path: photon-client/dist/
build-examples:
name: "Build Examples"
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
architecture: x64
- os: macos-14
architecture: aarch64
- os: ubuntu-22.04
name: "Photonlib - Build Examples - ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -60,19 +72,19 @@ jobs:
- name: Publish photonlib to maven local
run: |
chmod +x gradlew
./gradlew publishtomavenlocal -x check
./gradlew photon-targeting:publishtomavenlocal photon-lib:publishtomavenlocal -x check
- name: Build Java examples
working-directory: photonlib-java-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build -x check
./gradlew build
- name: Build C++ examples
working-directory: photonlib-cpp-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build -x check
./gradlew build
build-gradle:
name: "Gradle Build"
runs-on: ubuntu-22.04
@@ -585,7 +597,7 @@ jobs:
dispatch:
name: dispatch
needs: [build-photonlib-vendorjson]
needs: [build-photonlib-vendorjson, release]
runs-on: ubuntu-22.04
steps:
- uses: peter-evans/repository-dispatch@v3

View File

@@ -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'
}
}

View File

@@ -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"
]
}
],
"cppDependencies": [

View File

@@ -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
}

View File

@@ -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;
@@ -42,10 +41,11 @@ public class PhotonTargetingJniLoader {
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;
} catch (Exception e) {
System.out.println("Direct library load failed; falling back to extraction");
}
var nativeLibName = System.mapLibraryName(libraryName);

View File

@@ -0,0 +1,39 @@
/*
* MIT License
*
* Copyright (c) PhotonVision
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package frc.robot;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.photonvision.timesync.TimeSyncSingleton;
public class JniLoadTest {
@Test
public void smoketest() {
if (!TimeSyncSingleton.load()) {
fail("Could not load TimeSync JNI????????");
}
}
}

View File

@@ -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 ->