Skip to content

Commit 2a19ff2

Browse files
authored
Merge pull request #697 from mcneel/sbaer/rhinocore_nanobind
add nanobind compile for rhinocore bindings
2 parents 9f8e750 + 532ca23 commit 2a19ff2

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ src/MethodGen.pdb
9393
src/dotnet/Resources/Resource.designer.cs
9494
script/bootstrap.pyc
9595
src/rhinocore_bindings/build
96+
src/rhinocore_bindings/out
9697

9798
node_modules/
9899
.vs/

src/bindings/bnd_object.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
std::string StringFromDict(BND_DICT& d, const char* key)
66
{
77
#if defined(ON_PYTHON_COMPILE)
8+
9+
#if defined(NANOBIND)
10+
nanobind::handle value_handle = d[key];
11+
std::string rc = ToStdString(nanobind::str(value_handle));
12+
#else
813
std::string rc = ToStdString(py::str(d[key]));
14+
#endif
15+
916
#else
1017
std::string rc = d[key].as<std::string>();
1118
#endif

src/rhinocore_bindings/CMakeLists.txt

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,31 @@ project(rhinocore_py_bindings CXX)
66
set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_STANDARD_REQUIRED True)
88

9-
set(RHINO3DM_PY "YES")
10-
11-
# add_compile_definitions( NANOBIND_BUILD )
12-
# if (CMAKE_VERSION VERSION_LESS 3.18)
13-
# set(DEV_MODULE Development)
14-
# else()
15-
# set(DEV_MODULE Development.Module)
16-
# endif()
17-
# find_package(Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)
18-
19-
# if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20-
# set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
21-
# set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
22-
# endif()
23-
24-
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lib/nanobind nanobind_dir)
25-
add_subdirectory(../lib/pybind11 pybind11_dir)
26-
27-
289
file(GLOB bindings_SRC "../bindings/*.h" "../bindings/*.cpp")
2910

30-
# nanobind_add_module(rhinocore_py_bindings ${bindings_SRC} stdafx.cpp)
31-
pybind11_add_module(rhinocore_py_bindings ${bindings_SRC} stdafx.cpp)
11+
set(RHINO3DM_PY "YES")
12+
set(NANOBIND_BUILD "YES")
13+
14+
if (${NANOBIND_BUILD})
15+
add_compile_definitions( NANOBIND )
16+
if (CMAKE_VERSION VERSION_LESS 3.18)
17+
set(DEV_MODULE Development)
18+
else()
19+
set(DEV_MODULE Development.Module)
20+
endif()
21+
find_package(Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)
22+
23+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
24+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
25+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
26+
endif()
27+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lib/nanobind nanobind_dir)
28+
nanobind_add_module(rhinocore_py_bindings ${bindings_SRC} stdafx.cpp)
29+
else()
30+
add_subdirectory(../lib/pybind11 pybind11_dir)
31+
pybind11_add_module(rhinocore_py_bindings ${bindings_SRC} stdafx.cpp)
32+
endif()
33+
3234

3335
add_definitions(-DRHINOCORE_BINDINGS)
3436
add_definitions(-DON_CMAKE_BUILD)
@@ -49,5 +51,8 @@ if (WIN32)
4951
)
5052
endif()
5153

52-
# target_link_libraries(rhinocore_py_bindings PRIVATE nanobind-static)
53-
target_link_libraries(rhinocore_py_bindings PRIVATE pybind11::module)
54+
if (${NANOBIND_BUILD})
55+
target_link_libraries(rhinocore_py_bindings PRIVATE nanobind-static)
56+
else()
57+
target_link_libraries(rhinocore_py_bindings PRIVATE pybind11::module)
58+
endif()

0 commit comments

Comments
 (0)