@@ -13,88 +13,81 @@ set(ESIPythonRuntimeSources
1313 esiaccel/cosim/verilator.py
1414)
1515
16- # Pybind11 is used to wrap the ESICppRuntime APIs.
16+ # Nanobind is used to wrap the ESICppRuntime APIs.
1717find_package (Python3 COMPONENTS Interpreter Development.Module)
1818if (Python3_FOUND)
1919 IF (MSVC )
20- # Work around an issue with pybind11 and cmake incompatibility on Windows in debug mode.
20+ # Work around an issue with nanobind and cmake incompatibility on Windows in debug mode.
2121 set_target_properties (Python3::Module PROPERTIES
2222 MAP_IMPORTED_CONFIG_DEBUG ";RELEASE" )
2323 ENDIF (MSVC )
2424
25- if (pybind11_DIR )
26- message (STATUS "Using explicit pybind11 cmake directory: ${pybind11_DIR } (-Dpybind11_DIR to change)" )
25+ if (nanobind_DIR )
26+ message (STATUS "Using explicit nanobind cmake directory: ${nanobind_DIR } (-Dnanobind_DIR to change)" )
2727 else ()
28- message (STATUS "Checking for pybind11 in python path..." )
28+ message (STATUS "Checking for nanobind in python path..." )
2929 execute_process (
3030 COMMAND "${Python3_EXECUTABLE} "
31- -c "import pybind11 ;print(pybind11.get_cmake_dir (), end='')"
31+ -c "import nanobind ;print(nanobind.cmake_dir (), end='')"
3232 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
3333 RESULT_VARIABLE STATUS
3434 OUTPUT_VARIABLE PACKAGE_DIR
3535 ERROR_QUIET)
3636 if (NOT STATUS EQUAL "0" )
37- message (FATAL_ERROR "pybind11 not found (install via 'pip install pybind11 ' or set pybind11_DIR )" )
37+ message (FATAL_ERROR "nanobind not found (install via 'pip install nanobind ' or set nanobind_DIR )" )
3838 endif ()
3939 message (STATUS "found (${PACKAGE_DIR} )" )
40- set (pybind11_DIR "${PACKAGE_DIR} " )
40+ set (nanobind_DIR "${PACKAGE_DIR} " )
4141 endif ()
4242
43- # Now, find pybind11.
44- find_package (pybind11 CONFIG)
45- if (NOT pybind11_FOUND)
46- message (STATUS "Could not find pybind11. Disabling Python API." )
43+ # Now, find nanobind.
44+ find_package (Python COMPONENTS Interpreter Development.Module)
45+ find_package (nanobind CONFIG)
46+ if (NOT nanobind_FOUND)
47+ message (STATUS "Could not find nanobind. Disabling Python API." )
4748 if (WHEEL_BUILD)
48- message (FATAL_ERROR "pybind11 is required for a wheel build." )
49+ message (FATAL_ERROR "nanobind is required for a wheel build." )
4950 endif ()
5051 else ()
51- # Compile Pybind11 module and copy to the correct python directory.
52- pybind11_add_module (esiCppAccel
52+ # Compile nanobind module and copy to the correct python directory.
53+ nanobind_add_module (esiCppAccel
5354 ${CMAKE_CURRENT_SOURCE_DIR} /esiaccel/esiCppAccel.cpp)
5455 target_link_libraries (esiCppAccel PRIVATE ESICppRuntime)
5556 set_target_properties (esiCppAccel PROPERTIES
5657 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /esiaccel"
5758 )
5859
59- # Check for stubgen and generate stubs if available.
60- find_program (STUBGEN pybind11-stubgen)
61- if ("${STUBGEN} " STREQUAL "STUBGEN-NOTFOUND" )
62- message (STATUS "pybind11_stubgen not found. Skipping stub generation." )
60+ # Use nanobind's built-in stubgen for stub generation.
61+ if (WIN32 )
62+ # I just wasted all day trying to figure out the DLL search path on
63+ # Windows both locally and in the runner. I'm done. Windows wheels
64+ # won't have a stub until somebody else figures this out.
65+ # TODO: have the patience to make this work.
66+ message (WARNING "Stub generation is not supported on Windows." )
6367 else ()
64- if (WIN32 )
65- # I just wasted all day trying to figure out the DLL search path on
66- # Windows both locally and in the runner. I'm done. Windows wheels
67- # won't have a stub until somebody else figures this out.
68- # TODO: have the patience to make this work.
69- message (WARNING "pybind11-stubgen is not supported on Windows." )
68+ set (stubgen_python_path "$ENV{PYTHONPATH} :${CMAKE_CURRENT_BINARY_DIR} " )
69+ add_custom_command (
70+ TARGET esiCppAccel
71+ POST_BUILD
72+ COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH="${stubgen_python_path} "
73+ "${Python3_EXECUTABLE} " -m nanobind.stubgen
74+ -m esiaccel.esiCppAccel
75+ -o "${CMAKE_CURRENT_BINARY_DIR} /esiaccel/esiCppAccel.pyi"
76+ )
77+ if (WHEEL_BUILD)
78+ install (FILES "${CMAKE_CURRENT_BINARY_DIR} /esiaccel/esiCppAccel.pyi"
79+ DESTINATION .
80+ COMPONENT ESIRuntime
81+ )
7082 else ()
71- set (stubgen_python_path "$ENV{PYTHONPATH} :${CMAKE_CURRENT_BINARY_DIR} " )
72- add_custom_command (
73- TARGET esiCppAccel
74- POST_BUILD
75- COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH="${stubgen_python_path} "
76- ${STUBGEN}
77- -o "${CMAKE_CURRENT_BINARY_DIR} "
78- esiaccel.esiCppAccel
83+ install (FILES "${CMAKE_CURRENT_BINARY_DIR} /esiaccel/esiCppAccel.pyi"
84+ DESTINATION python/esiaccel
85+ COMPONENT ESIRuntime
7986 )
80- if (WHEEL_BUILD)
81- install (FILES "${CMAKE_CURRENT_BINARY_DIR} /esiaccel/esiCppAccel.pyi"
82- DESTINATION .
83- COMPONENT ESIRuntime
84- )
85- else ()
86- install (FILES "${CMAKE_CURRENT_BINARY_DIR} /esiaccel/esiCppAccel.pyi"
87- DESTINATION python/esiaccel
88- COMPONENT ESIRuntime
89- )
90- endif ()
9187 endif ()
9288 endif ()
9389
9490 if (WHEEL_BUILD)
95- if ("${STUBGEN} " STREQUAL "STUBGEN-NOTFOUND" )
96- message (FATAL_ERROR "pybind11_stubgen is required for a wheel build." )
97- endif ()
9891 set_target_properties (esiCppAccel PROPERTIES
9992 INSTALL_RPATH "$ORIGIN/lib" )
10093 else ()
@@ -144,7 +137,7 @@ if(Python3_FOUND)
144137 endforeach ()
145138
146139 # Custom target for the Python runtime just aggregates the python sources
147- # and Pybind11 module.
140+ # and nanobind module.
148141 add_custom_target (ESIPythonRuntime
149142 DEPENDS
150143 ${ESIPythonRuntimeSources}
0 commit comments