Skip to content

Commit

Permalink
Ooga booga
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Sep 19, 2024
1 parent 70591b3 commit a6856b6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 42 deletions.
Binary file added out.txt
Binary file not shown.
46 changes: 34 additions & 12 deletions photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ nativeUtils {
}
}

def getPythonIncludePath = {
def getPythonProperty(String property) {
def pythonexe = project.findProperty('pythonExecutable') ?: 'python3'

File.createTempFile("temp",".py").with { f ->
f.write "from sysconfig import get_paths as gp; print(gp()['include'])"
f.write "from sysconfig import get_paths as gp; print(gp()['${property}'])"

def stdout = new ByteArrayOutputStream()
exec {
commandLine pythonexe, f.absolutePath
standardOutput = stdout
}
def ret = stdout.toString().trim();
println("using python include path: " + ret)
println("Python property: $property = $ret")
return ret
}
}
Expand Down Expand Up @@ -100,18 +100,18 @@ model {
include '**/*.cpp', '**/*.cc'
}
exportedHeaders {
srcDirs 'nanobind/include', 'nanobind/src', 'nanobind/ext/robin_map/include', getPythonIncludePath()
srcDirs 'nanobind/include', 'nanobind/src', 'nanobind/ext/robin_map/include', getPythonProperty("include")
include "**/*.h"
include "**/*.hpp"
}
}
}

binaries.all {
lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared'
lib library: nativeName
// lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared'
// lib library: nativeName

nativeUtils.useRequiredLibrary(it, "wpilib_shared")
// nativeUtils.useRequiredLibrary(it, "wpilib_shared")
}
}
}
Expand Down Expand Up @@ -185,9 +185,18 @@ model {

binaries {
withType(NativeBinarySpec).all {
if((it.component.baseName == "photonlibpy" || it.component.baseName == nativeName) && it.toolChain instanceof GccCompatibleToolChain) {
it.cppCompiler.args << "-Wno-pedantic"
it.linker.args '-Wl,-rpath,\'$ORIGIN\''
println "${it.toolChain} -> ${it.component.baseName} -> ${it.toolChain instanceof VisualCpp}"

if((it.component.baseName == "photonlibpy" || it.component.baseName == nativeName)) {
if (it.toolChain instanceof VisualCpp) {
def path = getPythonProperty("data")
it.linker.args "/LIBPATH:${path}/libs"
}

if (it.toolChain instanceof GccCompatibleToolChain) {
it.cppCompiler.args << "-Wno-pedantic"
it.linker.args '-Wl,-rpath,\'$ORIGIN\''
}
}
}
}
Expand Down Expand Up @@ -247,6 +256,15 @@ task installPhotonlibpyNative(type: Copy) {

from "$projectDir/build/libs/photonlib/shared/$jniPlatform/release/libphotonlib.so"
for (lib in [
"cameraserver.dll",
"cscore.dll",
"opencv_core480.dll",
"opencv_calib3d480.dll",
"opencv_features2d480.dll",
"opencv_imgcodecs480.dll",
"opencv_flann480.dll",
"opencv_imgproc480.dll",
"photontargeting.so",
"libcameraserver.so",
"libcscore.so",
"libopencv_core.so.4.8",
Expand All @@ -260,13 +278,17 @@ task installPhotonlibpyNative(type: Copy) {
from "$projectDir/build/install/photonlibTest/$jniPlatform/release/lib/$lib"
}

from("$projectDir/build/libs/photonlibpy/shared/$jniPlatform/release/libphotonlibpy.so") {
from("$projectDir/build/libs/photonlibpy/shared/$jniPlatform/release/") {
include "libphotonlibpy.so"
include "photonlibpy.dll"

// Remove leading lib if present, and append an _ (renames to _photonlibpy.so/dll/dylib)
rename "(?:lib)?(.*)", ('_$1')
rename "(?:lib)?(.*)(.dll)", ('_$1.pyd')
}

def platform = project.findProperty('nativeBuildPlatform') ?: jniPlatform.capitalize()
println("Depending on build task for platform name: $platform")

it.dependsOn "installPhotonlibTest${platform}ReleaseGoogleTestExe"
it.dependsOn "photonlibpy${platform}ReleaseSharedLibrary"
}
Expand Down
2 changes: 1 addition & 1 deletion photon-lib/nanobind
Submodule nanobind updated 63 files
+27 −2 .github/workflows/ci.yml
+1 −0 .gitignore
+1 −0 CMakeLists.txt
+17 −0 cmake/darwin-ld-cpython.sym
+7 −7 docs/api_bazel.rst
+6 −1 docs/api_cmake.rst
+74 −10 docs/api_core.rst
+5 −5 docs/api_extra.rst
+1 −1 docs/bazel.rst
+73 −7 docs/changelog.rst
+9 −2 docs/classes.rst
+1 −1 docs/exchanging.rst
+1 −0 docs/faq.rst
+6 −5 docs/index.rst
+104 −0 docs/meson.rst
+2 −2 docs/ndarray.rst
+10 −5 docs/release.rst
+23 −12 docs/why.rst
+12 −4 include/nanobind/eigen/dense.h
+2 −2 include/nanobind/nanobind.h
+1 −0 include/nanobind/nb_attr.h
+7 −5 include/nanobind/nb_cast.h
+27 −12 include/nanobind/nb_class.h
+10 −0 include/nanobind/nb_lib.h
+8 −0 include/nanobind/nb_misc.h
+9 −9 include/nanobind/nb_traits.h
+29 −0 include/nanobind/nb_types.h
+48 −0 include/nanobind/stl/detail/nb_optional.h
+3 −45 include/nanobind/stl/optional.h
+1 −12 include/nanobind/stl/variant.h
+3 −3 pyproject.toml
+1 −1 src/__init__.py
+1 −0 src/buffer.h
+25 −0 src/common.cpp
+54 −8 src/nb_enum.cpp
+57 −21 src/nb_func.cpp
+21 −1 src/nb_internals.cpp
+2 −1 src/nb_internals.h
+1 −0 src/nb_ndarray.cpp
+177 −30 src/nb_type.cpp
+8 −3 src/stubgen.py
+33 −15 tests/CMakeLists.txt
+0 −2 tests/py_stub_test.py
+0 −2 tests/py_stub_test.pyi
+0 −2 tests/py_stub_test.pyi.ref
+4 −0 tests/test_classes.py
+26 −1 tests/test_enum.cpp
+34 −0 tests/test_enum.py
+49 −0 tests/test_enum_ext.pyi.ref
+10 −2 tests/test_functions.cpp
+33 −1 tests/test_functions.py
+15 −1 tests/test_functions_ext.pyi.ref
+6 −0 tests/test_ndarray.cpp
+28 −0 tests/test_ndarray.py
+2 −0 tests/test_ndarray_ext.pyi.ref
+5 −2 tests/test_stl.cpp
+0 −1 tests/test_stl.py
+1 −1 tests/test_stl_bind_map.cpp
+5 −5 tests/test_stl_bind_map.py
+1 −1 tests/test_stl_bind_vector.cpp
+3 −3 tests/test_stl_bind_vector.py
+7 −0 tests/test_typing.cpp
+5 −0 tests/test_typing_ext.pyi.ref
Binary file added photon-lib/py/photonlibpy/_photonlibpy.pyd
Binary file not shown.
58 changes: 29 additions & 29 deletions photon-lib/src/main/pybindings/cpp/photonlib_nanobind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

#include <fmt/format.h>
#include "photon/PhotonCamera.h"
// #include <fmt/format.h>
// #include "photon/PhotonCamera.h"

// actual nanobind include
#include <nanobind/nanobind.h>
Expand All @@ -36,34 +36,34 @@ NB_MODULE(_photonlibpy, m) {

m.doc() = "C++ bindings for photonlib";

nb::class_<photon::PhotonPipelineMetadata>(m, "PhotonPipelineMetadata")
.def_ro("sequenceID", &photon::PhotonPipelineMetadata::sequenceID)
.def_ro("captureTimestampMicros",
&photon::PhotonPipelineMetadata::captureTimestampMicros)
.def_ro("publishTimestampMicros",
&photon::PhotonPipelineMetadata::publishTimestampMicros);
// nb::class_<photon::PhotonPipelineMetadata>(m, "PhotonPipelineMetadata")
// .def_ro("sequenceID", &photon::PhotonPipelineMetadata::sequenceID)
// .def_ro("captureTimestampMicros",
// &photon::PhotonPipelineMetadata::captureTimestampMicros)
// .def_ro("publishTimestampMicros",
// &photon::PhotonPipelineMetadata::publishTimestampMicros);

nb::class_<photon::PhotonTrackedTarget>(m, "PhotonTrackedTarget")
.def_ro("yaw", &photon::PhotonTrackedTarget::yaw)
.def_ro("pitch", &photon::PhotonTrackedTarget::pitch)
// String representation
.def("__repr__", [](const photon::PhotonTrackedTarget& t) {
std::string s;
fmt::format_to(std::back_inserter(s),
"PhotonTrackedTarget<yaw={},pitch={}>", t.yaw, t.pitch);
return s;
});
nb::class_<photon::MultiTargetPNPResult>(m, "MultiTargetPNPResult")
.def_ro("fiducialIDsUsed", &photon::MultiTargetPNPResult::fiducialIDsUsed)
;
// nb::class_<photon::PhotonTrackedTarget>(m, "PhotonTrackedTarget")
// .def_ro("yaw", &photon::PhotonTrackedTarget::yaw)
// .def_ro("pitch", &photon::PhotonTrackedTarget::pitch)
// // String representation
// .def("__repr__", [](const photon::PhotonTrackedTarget& t) {
// std::string s;
// fmt::format_to(std::back_inserter(s),
// "PhotonTrackedTarget<yaw={},pitch={}>", t.yaw, t.pitch);
// return s;
// });
// nb::class_<photon::MultiTargetPNPResult>(m, "MultiTargetPNPResult")
// .def_ro("fiducialIDsUsed", &photon::MultiTargetPNPResult::fiducialIDsUsed)
// ;

nb::class_<photon::PhotonPipelineResult>(m, "PhotonPipelineResult")
.def_ro("metadata", &photon::PhotonPipelineResult::metadata)
.def_ro("targets", &photon::PhotonPipelineResult::targets)
.def_ro("multitagResult", &photon::PhotonPipelineResult::multitagResult);
// nb::class_<photon::PhotonPipelineResult>(m, "PhotonPipelineResult")
// .def_ro("metadata", &photon::PhotonPipelineResult::metadata)
// .def_ro("targets", &photon::PhotonPipelineResult::targets)
// .def_ro("multitagResult", &photon::PhotonPipelineResult::multitagResult);

nb::class_<photon::PhotonCamera>(m, "PhotonCamera")
.def(nb::init<const std::string&>())
.def("GetDriverMode", &photon::PhotonCamera::GetDriverMode)
.def("GetLatestResult", &photon::PhotonCamera::GetLatestResult);
// nb::class_<photon::PhotonCamera>(m, "PhotonCamera")
// .def(nb::init<const std::string&>())
// .def("GetDriverMode", &photon::PhotonCamera::GetDriverMode)
// .def("GetLatestResult", &photon::PhotonCamera::GetLatestResult);
}

0 comments on commit a6856b6

Please sign in to comment.