Skip to content

Commit

Permalink
Only link to stuff I need
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Sep 22, 2024
1 parent c4baefb commit 1c4cdb3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@
import edu.wpi.first.apriltag.jni.AprilTagJNI;
import edu.wpi.first.cscore.CameraServerCvJNI;
import edu.wpi.first.cscore.CameraServerJNI;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.JNIWrapper;
import edu.wpi.first.math.WPIMathJNI;
import edu.wpi.first.net.WPINetJNI;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.NetworkTablesJNI;
import edu.wpi.first.util.CombinedRuntimeLoader;
import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.wpilibj.Timer;
import java.io.IOException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.opencv.core.Core;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.jni.PhotonTargetingJniLoader;
import org.photonvision.jni.TimeSyncServer;
import org.photonvision.targeting.PhotonPipelineResult;

class PhotonCameraTest {
Expand Down
57 changes: 31 additions & 26 deletions photon-targeting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java"

apply plugin: 'edu.wpi.first.GradleJni'

// explicitly specify the opencv libraries linked to by nativeUtils.useRequiredLibrary(it, "opencv_shared")
def OPENCV_LIBRARIES_TO_EXCLUDE = [
"**/libopencv_core.so.*",
"**/libopencv_stitching.so.*",
"**/libopencv_dnn.so.*",
"**/libopencv_photo.so.*",
"**/libopencv_video.so.*",
"**/libopencv_flann.so.*",
"**/libopencv_ml.so.*",
"**/libopencv_calib3d.so.*",
"**/libopencv_imgproc.so.*",
"**/libopencv_objdetect.so.*",
"**/libopencv_videoio.so.*",
"**/libopencv_highgui.so.*",
"**/libopencv_aruco.so.*",
"**/libopencv_gapi.so.*",
"**/libopencv_features2d.so.*",
"**/libopencv_imgcodecs.so.*",
]
nativeUtils.nativeDependencyContainer.getByName("opencv_shared").extraSharedExcludes.addAll(OPENCV_LIBRARIES_TO_EXCLUDE)
println nativeUtils.nativeDependencyContainer.getByName("opencv_shared").extraSharedExcludes.get()

// Folder whose contents will be included in the final jar
def outputsFolder = file("$buildDir/extra_resources")

Expand Down Expand Up @@ -63,9 +85,11 @@ model {
}
}

nativeUtils.useRequiredLibrary(it, "wpilib_shared")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
nativeUtils.useRequiredLibrary(it, "wpiutil_shared")
nativeUtils.useRequiredLibrary(it, "wpimath_shared")
nativeUtils.useRequiredLibrary(it, "wpinet_shared")
nativeUtils.useRequiredLibrary(it, "wpilibc_shared")
nativeUtils.useRequiredLibrary(it, "ntcore_shared")
}
"${nativeName}JNI"(JniNativeLibrarySpec) {

Expand All @@ -88,8 +112,9 @@ model {
lib library: nativeName, linkage: 'shared'
}

nativeUtils.useRequiredLibrary(it, "opencv_shared")
nativeUtils.useRequiredLibrary(it, "wpilib_shared")
nativeUtils.useRequiredLibrary(it, "wpiutil_shared")
nativeUtils.useRequiredLibrary(it, "wpinet_shared")
nativeUtils.useRequiredLibrary(it, "ntcore_shared")
}

all {
Expand All @@ -112,7 +137,6 @@ model {
}
}
}

}
testSuites {
"${nativeName}Test"(GoogleTestTestSuiteSpec) {
Expand Down Expand Up @@ -140,25 +164,9 @@ model {
}
}

nativeUtils.useRequiredLibrary(it, "cscore_shared")
nativeUtils.useRequiredLibrary(it, "cameraserver_shared")
nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared")
nativeUtils.useRequiredLibrary(it, "googletest_static")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
}
}

binaries {
withType(NativeBinarySpec).all {
if (it.toolChain instanceof VisualCpp) {
// TODO
}

if (it.toolChain instanceof GccCompatibleToolChain) {
// Ends up appending this flag, not prepending
it.linker.args '-Wl,--as-needed'
}
}
}

Expand Down Expand Up @@ -220,11 +228,8 @@ def nativeTasks = wpilibTools.createExtractionTasks {

nativeTasks.addToSourceSetResources(sourceSets.test)

nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("apriltag")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("hal")
nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv("frc" + wpi.frcYear.get(), wpi.versions.opencvVersion.get())
4 changes: 0 additions & 4 deletions photon-targeting/src/main/native/jni/TimeSyncClientJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include <cstdio>
#include <string>

#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>

#include "net/TimeSyncClientServer.h"

using namespace wpi;
Expand Down
4 changes: 0 additions & 4 deletions photon-targeting/src/main/native/jni/TimeSyncServerJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

#include <cstdio>

#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>

#include "net/TimeSyncClientServer.h"

using namespace wpi;
Expand Down
11 changes: 1 addition & 10 deletions photon-targeting/src/test/java/net/TimeSyncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import edu.wpi.first.util.WPIUtilJNI;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.opencv.core.Core;
import org.photonvision.jni.PhotonTargetingJniLoader;
import org.photonvision.jni.TimeSyncClient;
import org.photonvision.jni.TimeSyncServer;
Expand All @@ -49,15 +48,7 @@ public static void load_wpilib() {

try {
CombinedRuntimeLoader.loadLibraries(
TimeSyncTest.class,
"wpiutiljni",
"wpimathjni",
"ntcorejni",
"wpinetjni",
"wpiHaljni",
"cscorejni",
"apriltagjni");
CombinedRuntimeLoader.loadLibraries(TimeSyncTest.class, Core.NATIVE_LIBRARY_NAME);
TimeSyncTest.class, "wpiutiljni", "wpimathjni", "wpinetjni", "ntcorejni", "wpiHaljni");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion photon-targeting/src/test/native/cpp/net/TimeSyncTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST(TimeSyncProtocolTest, TestClient) {
server.Start();

for (int i = 0; i < 10; i++) {
std::this_thread::sleep_for(1000ms);
std::this_thread::sleep_for(50ms);
// busywait
}

Expand Down

0 comments on commit 1c4cdb3

Please sign in to comment.