-
Notifications
You must be signed in to change notification settings - Fork 57
adds nanobind scaffolding for future python bindinds #205
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| cmake_minimum_required ( VERSION 3.12 ) | ||
| include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}" ) | ||
|
|
||
| nanobind_add_module( rawtoaces_bindings | ||
| py_util.cpp py_util.h | ||
| py_core.cpp py_core.h | ||
| py_module.cpp | ||
| ) | ||
|
|
||
| target_link_libraries( rawtoaces_bindings | ||
| PUBLIC | ||
| ${RAWTOACES_UTIL_LIB} | ||
| ) | ||
|
|
||
| if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) | ||
| target_compile_options ( nanobind-static PRIVATE -Wno-pedantic ) | ||
| target_compile_options ( rawtoaces_bindings PRIVATE -Wno-pedantic ) | ||
| if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0 ) | ||
| target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-bounds ) | ||
| target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-bounds ) | ||
| endif () | ||
| elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" ) | ||
| target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-array ) | ||
| target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-array ) | ||
| endif() | ||
|
|
||
| set_target_properties( rawtoaces_bindings PROPERTIES | ||
| OUTPUT_NAME "rawtoaces" | ||
| #EXPORT_NAME "rawtoaces" | ||
| #SOVERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION} | ||
| #VERSION ${RAWTOACES_VERSION} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments. needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. I think the binary should be versioned, but uncommenting that makes configure fail. Also I don't know if this whole 'export' thing is needed, I use it to change the library name, as the 'rawtoaces' target name is already taken. This also makes the library install with the rest of targets, I don't know if the destination should be different. This is good enough for now. We'll need somebody more familiar with python tools deployment to finalise this, I suppose. |
||
| ) | ||
|
|
||
| install( | ||
| TARGETS rawtoaces_bindings | ||
| EXPORT RAWTOACESTargets | ||
| LIBRARY DESTINATION ${INSTALL_LIB_DIR} | ||
| INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| PUBLIC_HEADER DESTINATION include/rawtoaces | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the rawtoaces Project. | ||
|
|
||
| #include "py_core.h" | ||
|
|
||
| void core_bindings( nanobind::module_ & /*m - unused*/ ) | ||
| { | ||
| // TODO: add the core lib bindings here | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the rawtoaces Project. | ||
|
|
||
| #include <nanobind/nanobind.h> | ||
|
|
||
| void core_bindings( nanobind::module_ &m ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the rawtoaces Project. | ||
|
|
||
| #include "py_core.h" | ||
| #include "py_util.h" | ||
|
|
||
| NB_MODULE( rawtoaces, m ) | ||
| { | ||
| core_bindings( m ); | ||
| util_bindings( m ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the rawtoaces Project. | ||
|
|
||
| #include "py_util.h" | ||
| #include <nanobind/stl/string.h> | ||
| #include <rawtoaces/image_converter.h> | ||
|
|
||
| using namespace rta::util; | ||
|
|
||
| void util_bindings( nanobind::module_ &m ) | ||
| { | ||
| nanobind::class_<ImageConverter> image_converter( m, "ImageConverter" ); | ||
|
|
||
| image_converter.def( nanobind::init<>() ); | ||
|
|
||
| // TODO: add the rest of the ImageConverter methods and properties | ||
| image_converter | ||
| .def_rw( | ||
| "settings", | ||
| &ImageConverter::settings ) // The Settings class is described below | ||
| .def( "process_image", &ImageConverter::process_image ); | ||
|
|
||
| nanobind::class_<ImageConverter::Settings> settings( | ||
| image_converter, "Settings" ); | ||
|
|
||
| // TODO: add the rest of the Settings' properties | ||
| settings.def( nanobind::init<>() ) | ||
| .def_rw( | ||
| "WB_Method", | ||
| &ImageConverter::Settings:: | ||
| WB_method ) // The WBMethod enum is described below | ||
| .def_rw( "illuminant", &ImageConverter::Settings::illuminant ); | ||
|
|
||
| // TODO: add the rest of WBMethod values, add other enums following this example | ||
| nanobind::enum_<ImageConverter::Settings::WBMethod>( settings, "WBMethod" ) | ||
| .value( "Metadata", ImageConverter::Settings::WBMethod::Metadata ) | ||
| .value( "Illuminant", ImageConverter::Settings::WBMethod::Illuminant ) | ||
| .export_values(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright Contributors to the rawtoaces Project. | ||
|
|
||
| #include <nanobind/nanobind.h> | ||
|
|
||
| void util_bindings( nanobind::module_ &m ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this builds and installs the OIIO python bindings by default. You may need some kind of modifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Will check. We don't need OIIO on the python side that right now.