Skip to content

Commit bbb6200

Browse files
authored
adds nanobind scaffolding for future python bindinds (#205)
* adds nanobind scaffolding for future python bindinds Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz> * fix formatting Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz> --------- Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
1 parent 184bbc4 commit bbb6200

File tree

14 files changed

+146
-5
lines changed

14 files changed

+146
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
shell: bash
6666
run: |
6767
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
68+
sudo python -m pip install nanobind
6869
6970
- name: Configure CMake
7071
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
@@ -152,6 +153,7 @@ jobs:
152153
shell: bash
153154
run: |
154155
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
156+
sudo python -m pip install nanobind
155157
156158
- name: Configure CMake
157159
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
2222
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /EHsc")
2323
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX")
2424
add_compile_definitions( NOMINMAX )
25-
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
25+
elseif (
26+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
27+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
28+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"
29+
)
2630
# GCC/Clang strict flags
2731
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic")
2832
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wextra -pedantic")
@@ -69,6 +73,7 @@ endforeach()
6973

7074
option( ENABLE_SHARED "Enable Shared Libraries" ON )
7175
option( RTA_CENTOS7_CERES_HACK "Work around broken config in ceres-solver 1.12" OFF )
76+
option( RTA_BUILD_PYTHON_BINDINGS "Build python bindings" ON )
7277
option( ENABLE_COVERAGE "Enable code coverage reporting" OFF )
7378

7479
if ( ENABLE_SHARED )
@@ -93,6 +98,10 @@ add_subdirectory("src/${RAWTOACES_CORE_LIB}")
9398
add_subdirectory("src/${RAWTOACES_UTIL_LIB}")
9499
add_subdirectory("src/rawtoaces")
95100

101+
if ( RTA_BUILD_PYTHON_BINDINGS )
102+
add_subdirectory(src/bindings)
103+
endif ( RTA_BUILD_PYTHON_BINDINGS )
104+
96105
enable_testing()
97106
add_subdirectory(tests)
98107

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ To build `rawtoaces` you would need to satisfy these dependencies:
4747
| `ceres` | `1.12.0` | Ceres Solver is an open source library for solving Non-linear Least Squares problems with bounds constraints and unconstrained optimization problems. It processes non-linear regression for rawtoaces. | [Ceres Solver installation](http://ceres-solver.org/installation.html)|
4848
| `boost` | `1.76.0` | Boost has multiple C++ libraries that support tasks related to linear algebra, multithreading, image processing, unit testing, etc. It unit testing for rawtoaces. | [Boost download](http://www.boost.org/) |
4949
| `OpenImageIO` | `3.0` | OpenImageIO is an open source library providing vast functionality for image processing. rawtoaces relies on OpenImageIO for reading raw files, saving AcesContainer files, and also all pixel operations. | [OpenImageIO installation](https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/main/INSTALL.md) |
50+
| `nanobind` | `1.9` | nanobind is a small binding library that exposes C++ types in Python and vice versa. | [nanobind installation](https://nanobind.readthedocs.io/en/latest/installing.html) |
5051

5152

5253
### MacOS

build_scripts/install_deps_linux.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ time sudo apt-get -q -f install -y \
88
libceres-dev \
99
nlohmann-json3-dev \
1010
libopencv-dev \
11-
openimageio-tools libopenimageio-dev
11+
openimageio-tools libopenimageio-dev \
12+
nanobind-dev

build_scripts/install_deps_mac.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -ex
44

5-
brew install ceres-solver nlohmann-json openimageio
5+
brew install ceres-solver nlohmann-json openimageio nanobind robin-map

build_scripts/install_deps_windows.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ set -ex
55
vcpkg install \
66
ceres:x64-windows \
77
nlohmann-json:x64-windows \
8-
openimageio:x64-windows
8+
openimageio:x64-windows \
9+
nanobind:x64-windows

configure.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ if (RTA_CENTOS7_CERES_HACK)
1111
else ()
1212
find_package ( Ceres CONFIG REQUIRED )
1313
endif ()
14+
15+
if (RTA_BUILD_PYTHON_BINDINGS)
16+
17+
if ( CMAKE_VERSION VERSION_LESS 3.18 )
18+
set( DEV_MODULE Development )
19+
else ()
20+
set( DEV_MODULE Development.Module )
21+
endif ()
22+
23+
find_package ( Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED )
24+
25+
execute_process (
26+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
27+
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
28+
find_package ( nanobind CONFIG REQUIRED )
29+
endif ()

src/bindings/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required ( VERSION 3.12 )
2+
include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}" )
3+
4+
nanobind_add_module( rawtoaces_bindings
5+
py_util.cpp py_util.h
6+
py_core.cpp py_core.h
7+
py_module.cpp
8+
)
9+
10+
target_link_libraries( rawtoaces_bindings
11+
PUBLIC
12+
${RAWTOACES_UTIL_LIB}
13+
)
14+
15+
if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
16+
target_compile_options ( nanobind-static PRIVATE -Wno-pedantic )
17+
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-pedantic )
18+
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0 )
19+
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-bounds )
20+
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-bounds )
21+
endif ()
22+
elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
23+
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-array )
24+
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-array )
25+
endif()
26+
27+
set_target_properties( rawtoaces_bindings PROPERTIES
28+
OUTPUT_NAME "rawtoaces"
29+
#EXPORT_NAME "rawtoaces"
30+
#SOVERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION}
31+
#VERSION ${RAWTOACES_VERSION}
32+
)
33+
34+
install(
35+
TARGETS rawtoaces_bindings
36+
EXPORT RAWTOACESTargets
37+
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
38+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
39+
PUBLIC_HEADER DESTINATION include/rawtoaces
40+
)

src/bindings/py_core.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the rawtoaces Project.
3+
4+
#include "py_core.h"
5+
6+
void core_bindings( nanobind::module_ & /*m - unused*/ )
7+
{
8+
// TODO: add the core lib bindings here
9+
}

src/bindings/py_core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Contributors to the rawtoaces Project.
3+
4+
#include <nanobind/nanobind.h>
5+
6+
void core_bindings( nanobind::module_ &m );

0 commit comments

Comments
 (0)