Skip to content

Commit

Permalink
[python] First small example for nanobind module.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed Jul 1, 2024
1 parent 41145e1 commit 120f12f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'
submodules: 'recursive'
fetch-depth: 0

- name: Display Python version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'false'
submodules: 'recursive'
fetch-depth: 0

- name: Update / download Submodules (selected ones)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'
submodules: 'recursive'
fetch-depth: 0

- name: Create Python virtualenv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'
submodules: 'recursive'
fetch-depth: 0

- name: Run clang-tidy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'
submodules: 'recursive'
fetch-depth: 0
ref: 'support/v5.13'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ecal-fat-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'true'
submodules: 'recursive'
fetch-depth: 0

- name: Create clean eCAL directory
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@
[submodule "thirdparty/ecaludp/ecaludp"]
path = thirdparty/ecaludp/ecaludp
url = https://github.com/eclipse-ecal/ecaludp.git
[submodule "thirdparty/nanobind/nanobind"]
path = thirdparty/nanobind/nanobind
url = https://github.com/KerstinKeller/nanobind.git
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -489,6 +489,7 @@ message(STATUS "ECAL_THIRDPARTY_BUILD_FINEFTP : ${ECAL_THIRDPAR
message(STATUS "ECAL_THIRDPARTY_BUILD_FTXUI : ${ECAL_THIRDPARTY_BUILD_FTXUI}")
message(STATUS "ECAL_THIRDPARTY_BUILD_GTEST : ${ECAL_THIRDPARTY_BUILD_GTEST}")
message(STATUS "ECAL_THIRDPARTY_BUILD_HDF5 : ${ECAL_THIRDPARTY_BUILD_HDF5}")
message(STATUS "ECAL_THIRDPARTY_BUILD_NANOBIND : ${ECAL_THIRDPARTY_BUILD_NANOBIND}")
message(STATUS "ECAL_THIRDPARTY_BUILD_PROTOBUF : ${ECAL_THIRDPARTY_BUILD_PROTOBUF}")
message(STATUS "ECAL_THIRDPARTY_BUILD_QWT : ${ECAL_THIRDPARTY_BUILD_QWT}")
message(STATUS "ECAL_THIRDPARTY_BUILD_RECYCLE : ${ECAL_THIRDPARTY_BUILD_RECYCLE}")
Expand Down
2 changes: 2 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"cacheVariables": {
"HAS_HDF5": "ON",
"BUILD_PY_BINDING": "ON",
"BUILD_APPS": "OFF",
"BUILD_SAMPLES": "OFF",
"BUILD_SHARED": "OFF",
"ECAL_THIRDPARTY_BUILD_HDF5": "ON"
}
Expand Down
1 change: 1 addition & 0 deletions cmake/submodule_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(ecal_submodule_dependencies
GTest
HDF5
#libssh2
nanobind
Protobuf
qwt
recycle
Expand Down
7 changes: 7 additions & 0 deletions doc/rst/license/thirdparty_licenses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ They are used by Eclipse eCAL, but not associated to it in any way.
- - |fa-file-alt| Copy in repository: :file:`/cpack/innosetup/modpath.iss`
- |fa-windows| Binary distributions for Windows (Installer only)

* - `nanobind <https://github.com/wjakob/nanobind>`_
- :ref:`bsd_3`
- 2022, Wenzel Jakob
- - |fa-github| Git submodule ``/tirdparty/nanobind``
- |fa-windows| Binary distributions for Windows
- |fa-ubuntu| Binary distributions for Linux

* - `npcap <https://nmap.org/npcap/>`_
- :ref:`npcap_license`
- 2013-2021 by Insecure.Com LLC
Expand Down
5 changes: 4 additions & 1 deletion lang/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,9 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH "ON")
add_subdirectory(core)
add_dependencies(${PROJECT_NAME} _ecal_core_py)

add_subdirectory(nanobind_core)
add_dependencies(${PROJECT_NAME} nanobind_core)

if(HAS_HDF5)
add_subdirectory(ecalhdf5)
add_dependencies(${PROJECT_NAME} _ecal_hdf5_py)
Expand Down
28 changes: 28 additions & 0 deletions lang/python/nanobind_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Try to import all Python components potentially needed by nanobind
find_package(Python
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

# We are now ready to compile the actual extension module
nanobind_add_module(
# Name of the extension
nanobind_core

# Target the stable ABI for Python 3.12+, which reduces
# the number of binary wheels that must be built. This
# does nothing on older Python versions
STABLE_ABI

# Source code goes here
main.cpp
)

# Install directive for scikit-build-core
install(TARGETS nanobind_core LIBRARY DESTINATION nanobind_core)

if(WIN32)
set_property(TARGET nanobind_core PROPERTY FOLDER lang/python/core)
endif()
5 changes: 5 additions & 0 deletions lang/python/nanobind_core/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <nanobind/nanobind.h>

NB_MODULE(nanobind_core, m) {
m.def("hello", []() { return "Hello world!"; });
}
9 changes: 9 additions & 0 deletions thirdparty/nanobind/build-nanobind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include_guard(GLOBAL)

message(STATUS "building nanobind")

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/nanobind thirdparty/nanobind EXCLUDE_FROM_ALL SYSTEM)
else ()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/nanobind thirdparty/nanobind EXCLUDE_FROM_ALL)
endif ()
1 change: 1 addition & 0 deletions thirdparty/nanobind/nanobind
Submodule nanobind added at 97a567

0 comments on commit 120f12f

Please sign in to comment.