Skip to content

Commit 5bc2b9d

Browse files
authored
Merge pull request #345 from ManifoldFR/topic/nanobind
Move from Pybind11 to nanobind
2 parents 72f8c3b + d719663 commit 5bc2b9d

34 files changed

+848
-952
lines changed

.github/workflows/ci-arch.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: CI - ArchLinux
33
on:
44
push:
55
pull_request:
6+
paths-ignore:
7+
- CHANGELOG.md
68

79
jobs:
810
build-with-arch:
@@ -14,7 +16,7 @@ jobs:
1416

1517
- uses: actions/checkout@v4
1618
with:
17-
submodules: true
19+
submodules: recursive
1820

1921
- run: cmake -B build -S . -DBUILD_PYTHON_INTERFACE=ON
2022
- run: cmake --build build

.github/workflows/ci-linux-osx-win-conda.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: CI - Linux/OSX/Windows - Conda
33
on:
44
push:
55
pull_request:
6+
paths-ignore:
7+
- CHANGELOG.md
68

79
jobs:
810
build-with-conda:
@@ -29,10 +31,6 @@ jobs:
2931
compiler: clang-cl
3032
- name: windows-latest
3133
os: windows-latest
32-
- name: macos-latest
33-
os: macos-latest
34-
build_type: Release
35-
cxx_std: 14
3634
- name: macos-latest
3735
os: macos-latest
3836
build_type: Debug
@@ -55,7 +53,9 @@ jobs:
5553
continue_on_error: false
5654

5755
steps:
58-
- uses: actions/checkout@v2
56+
- uses: actions/checkout@v4
57+
with:
58+
submodules: recursive
5959

6060
- uses: conda-incubator/setup-miniconda@v2
6161
if: matrix.os != 'macos-14'
@@ -80,7 +80,7 @@ jobs:
8080
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
8181
conda config --remove channels defaults
8282
# Compilation related dependencies
83-
mamba install cmake compilers make pkg-config doxygen ninja graphviz
83+
mamba install cmake compilers make pkg-config doxygen ninja graphviz typing_extensions
8484
# Main dependencies
8585
mamba install eigen simde
8686
# Test dependencies

.github/workflows/ci-linux-ros.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: CI - Linux - ROS
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
pull_request:
5+
paths-ignore:
6+
- CHANGELOG.md
37

48
jobs:
59
CI:

.github/workflows/gh-pages.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
12+
with:
13+
submodules: recursive
1214

1315
- uses: conda-incubator/setup-miniconda@v2
1416
with:

.github/workflows/release-linux.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Release on PyPI [Linux]
22

33
on:
44
pull_request:
5+
paths-ignore:
6+
- CHANGELOG.md
57
release:
68
types:
79
- published
@@ -33,9 +35,9 @@ jobs:
3335
build: "cp312-manylinux*"
3436

3537
steps:
36-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@v4
3739
with:
38-
submodules: 'true'
40+
submodules: recursive
3941
- uses: actions/setup-python@v4
4042
with:
4143
python-version: "3.10"

.github/workflows/release-osx-win.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Release on PyPI [Windows, Mac]
22

33
on:
44
pull_request:
5+
paths-ignore:
6+
- CHANGELOG.md
57
release:
68
types:
79
- published
@@ -21,7 +23,7 @@ jobs:
2123
toolset: v143
2224

2325
steps:
24-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2527
with:
2628
submodules: recursive
2729

@@ -57,7 +59,7 @@ jobs:
5759
run: |
5860
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
5961
conda config --remove channels defaults
60-
mamba install doxygen graphviz eigen simde cmake compilers
62+
mamba install doxygen graphviz eigen simde cmake compilers typing_extensions
6163
6264
- name: Print environment [Conda]
6365
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[submodule "external/pybind11"]
2-
path = bindings/python/external/pybind11
3-
url = https://github.com/pybind/pybind11
1+
[submodule "bindings/python/external/nanobind"]
2+
path = bindings/python/external/nanobind
3+
url = https://github.com/wjakob/nanobind
44
[submodule "cmake-module"]
55
path = cmake-module
66
url = https://github.com/jrl-umi3218/jrl-cmakemodules.git

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Added
10+
11+
* Stub files for Python bindings, using [nanobind's native support](https://nanobind.readthedocs.io/en/latest/typing.html#stub-generation) ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
12+
13+
### Changed
14+
15+
* Change Python bindings to use nanobind instead of pybind11 ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
16+
917
## [0.6.7] - 2024-08-27
1018

1119
### Added
1220
* Fix mu update function for PrimalLDLT backend ([#349](https://github.com/Simple-Robotics/proxsuite/pull/349))
1321
* Allow use of installed pybind11, cereal and jrl-cmakemodules via cmake
1422
* Add compatibility with jrl-cmakemodules workspace ([#339](https://github.com/Simple-Robotics/proxsuite/pull/339))
15-
* Specifically mention that timings are in microseconds ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
16-
* Fix cereal include directory in cmake ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
17-
* Extend doc with hint for conda installation from source ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
23+
* Specifically mention that timings are in microseconds ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))
24+
* Fix cereal include directory in cmake ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))
25+
* Extend doc with hint for conda installation from source ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))
1826

1927
### Fixed
2028
* Fix inequality constraints return in QPLayer ([#343](https://github.com/Simple-Robotics/proxsuite/pull/343))

bindings/python/CMakeLists.txt

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
if(UNIX)
2-
set(PYTHON_COMPONENTS Development.Module)
2+
set(PYTHON_COMPONENTS Interpreter Development.Module)
33
endif()
44

55
include(${JRL_CMAKE_MODULES}/python.cmake)
66
include(${JRL_CMAKE_MODULES}/python-helpers.cmake)
77

8-
findpython(REQUIRED Development.Module)
8+
option(GENERATE_PYTHON_STUBS "Generate Python stubs" OFF)
9+
10+
findpython(REQUIRED)
11+
set(Python_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
12+
# Nanobind expects these targets instead of Python3::*
13+
# https://github.com/jrl-umi3218/jrl-cmakemodules/issues/708
14+
add_library(Python::Module ALIAS Python3::Module)
15+
add_executable(Python::Interpreter ALIAS Python3::Interpreter)
916

1017
if(IS_ABSOLUTE ${PYTHON_SITELIB})
1118
set(${PYWRAP}_INSTALL_DIR ${PYTHON_SITELIB}/${PROJECT_NAME})
@@ -14,11 +21,21 @@ else()
1421
${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NAME})
1522
endif()
1623

17-
find_package(pybind11 CONFIG)
18-
if(NOT pybind11_FOUND)
19-
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/pybind11)
20-
add_subdirectory(external/pybind11
21-
${CMAKE_CURRENT_BINARY_DIR}/external/pybind11)
24+
cmake_policy(PUSH)
25+
cmake_policy(SET CMP0074 NEW)
26+
# Detect the installed nanobind package and import it into CMake
27+
execute_process(
28+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
29+
OUTPUT_STRIP_TRAILING_WHITESPACE
30+
OUTPUT_VARIABLE nanobind_ROOT)
31+
find_package(nanobind CONFIG)
32+
cmake_policy(POP)
33+
if(NOT nanobind_FOUND)
34+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/nanobind)
35+
add_subdirectory(external/nanobind
36+
${CMAKE_CURRENT_BINARY_DIR}/external/nanobind)
37+
else()
38+
message(STATUS "Found installed nanobind.")
2239
endif()
2340

2441
add_custom_target(${PROJECT_NAME}_python)
@@ -29,14 +46,12 @@ file(GLOB_RECURSE PYWRAP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
2946

3047
# Add simd feature detectors for current intel CPU
3148
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
32-
python3_add_library(instructionset MODULE helpers/instruction-set.cpp)
49+
nanobind_add_module(instructionset helpers/instruction-set.cpp)
3350
add_dependencies(${PROJECT_NAME}_python instructionset)
34-
target_link_libraries(instructionset PRIVATE proxsuite pybind11::module)
51+
target_link_libraries(instructionset PRIVATE proxsuite)
3552
set_target_properties(
3653
instructionset
3754
PROPERTIES OUTPUT_NAME instructionset
38-
PREFIX ""
39-
SUFFIX ${PYTHON_EXT_SUFFIX}
4055
LIBRARY_OUTPUT_DIRECTORY
4156
"${PROJECT_BINARY_DIR}/bindings/python/${PROJECT_NAME}"
4257
LIBRARY_OUTPUT_DIRECTORY_RELEASE
@@ -58,6 +73,20 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
5873
TARGETS instructionset
5974
EXPORT ${TARGETS_EXPORT_NAME}
6075
DESTINATION ${${PYWRAP}_INSTALL_DIR})
76+
if(GENERATE_PYTHON_STUBS)
77+
nanobind_add_stub(
78+
instructionset_stub
79+
MODULE
80+
instructionset
81+
OUTPUT
82+
instructionset.pyi
83+
PYTHON_PATH
84+
$<TARGET_FILE_DIR:instructionset>
85+
DEPENDS
86+
instructionset)
87+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/instructionset.pyi
88+
DESTINATION ${${PYWRAP}_INSTALL_DIR})
89+
endif()
6190
endif()
6291

6392
function(list_filter list regular_expression dest_list)
@@ -72,12 +101,12 @@ function(list_filter list regular_expression dest_list)
72101
endfunction(list_filter)
73102

74103
function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
75-
python3_add_library(${target_name} MODULE ${PYWRAP_SOURCES} ${PYWRAP_HEADERS})
104+
nanobind_add_module(${target_name} ${PYWRAP_SOURCES} ${PYWRAP_HEADERS})
76105
add_dependencies(${PROJECT_NAME}_python ${target_name})
77106

78-
target_link_libraries(${target_name} PUBLIC ${dependencies} pybind11::module)
107+
target_link_libraries(${target_name} PUBLIC ${dependencies})
79108
target_compile_options(${target_name} PRIVATE ${COMPILE_OPTIONS})
80-
target_link_libraries(${target_name} PRIVATE proxsuite pybind11::module)
109+
target_link_libraries(${target_name} PRIVATE proxsuite)
81110
target_compile_definitions(${target_name}
82111
PRIVATE PYTHON_MODULE_NAME=${target_name})
83112

@@ -104,8 +133,6 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
104133
set_target_properties(
105134
${target_name}
106135
PROPERTIES OUTPUT_NAME ${target_name}
107-
PREFIX ""
108-
SUFFIX ${PYTHON_EXT_SUFFIX}
109136
LIBRARY_OUTPUT_DIRECTORY
110137
"${PROJECT_BINARY_DIR}/bindings/python/${PROJECT_NAME}"
111138
LIBRARY_OUTPUT_DIRECTORY_RELEASE
@@ -126,6 +153,20 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
126153
endif()
127154

128155
install(TARGETS ${target_name} DESTINATION ${${PYWRAP}_INSTALL_DIR})
156+
if(GENERATE_PYTHON_STUBS)
157+
nanobind_add_stub(
158+
${target_name}_stub
159+
MODULE
160+
${target_name}
161+
OUTPUT
162+
${target_name}.pyi
163+
PYTHON_PATH
164+
$<TARGET_FILE_DIR:${target_name}>
165+
DEPENDS
166+
${target_name})
167+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.pyi
168+
DESTINATION ${${PYWRAP}_INSTALL_DIR})
169+
endif()
129170
endfunction()
130171

131172
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)

bindings/python/external/nanobind

Submodule nanobind added at 9641bb7

0 commit comments

Comments
 (0)