-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First small example for nanobind module.
- Loading branch information
1 parent
b8a22c5
commit ff9a33e
Showing
9 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set(nanobind_FOUND TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
message(STATUS "building nanobind") | ||
|
||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0") | ||
add_subdirectory(thirdparty/nanobind/nanobind EXCLUDE_FROM_ALL SYSTEM) | ||
else () | ||
add_subdirectory(thirdparty/nanobind/nanobind EXCLUDE_FROM_ALL) | ||
endif () | ||
|
||
|
||
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules) |