[nanobind] New port (#35488)

This commit is contained in:
Eric Kilmer 2024-03-21 22:29:04 -04:00 committed by GitHub
parent d798cd7ff1
commit 9b11c9db80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,62 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 919ce1d..25956c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -107,29 +107,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(-Wall -Wextra -Wno-unused-local-typedefs)
endif()
-# ---------------------------------------------------------------------------
-# Find the Python interpreter and development libraries
-# ---------------------------------------------------------------------------
-
-if (NOT TARGET Python::Module OR NOT TARGET Python::Interpreter)
- set(Python_FIND_FRAMEWORK LAST) # Prefer Brew/Conda to Apple framework python
-
- if (CMAKE_VERSION VERSION_LESS 3.18)
- set(NB_PYTHON_DEV_MODULE Development)
- else()
- set(NB_PYTHON_DEV_MODULE Development.Module)
- endif()
-
- find_package(Python 3.8
- REQUIRED COMPONENTS Interpreter ${NB_PYTHON_DEV_MODULE}
- OPTIONAL_COMPONENTS Development.SABIModule)
-endif()
-
# ---------------------------------------------------------------------------
# Include nanobind cmake functionality
# ---------------------------------------------------------------------------
-find_package(nanobind
+find_package(nanobind REQUIRED
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/cmake
NO_DEFAULT_PATH)
diff --git a/cmake/nanobind-config.cmake b/cmake/nanobind-config.cmake
index cb6cfb0..a456f3f 100644
--- a/cmake/nanobind-config.cmake
+++ b/cmake/nanobind-config.cmake
@@ -1,9 +1,20 @@
include_guard(GLOBAL)
-if (NOT TARGET Python::Module)
- message(FATAL_ERROR "You must invoke 'find_package(Python COMPONENTS Interpreter Development REQUIRED)' prior to including nanobind.")
+# ---------------------------------------------------------------------------
+# Find the Python interpreter and development libraries
+# ---------------------------------------------------------------------------
+if (CMAKE_VERSION VERSION_LESS 3.18)
+ set(NB_PYTHON_DEV_MODULE Development)
+else()
+ set(NB_PYTHON_DEV_MODULE Development.Module)
endif()
+include(CMakeFindDependencyMacro)
+find_dependency(Python 3.8
+ COMPONENTS Interpreter ${NB_PYTHON_DEV_MODULE}
+ OPTIONAL_COMPONENTS Development.SABIModule
+)
+
# Determine the right suffix for ordinary and stable ABI extensions.
# We always need to know the extension

View File

@ -0,0 +1,129 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e8fda9f..b27dc07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ if(NB_CREATE_INSTALL_RULES AND NOT CMAKE_SKIP_INSTALL_RULES)
# Normally these would be configurable by the user, but we can't allow that
# because the lookup paths are hard-coded in 'cmake/nanobind-config.cmake'
- set(NB_INSTALL_INC_DIR "${NB_INSTALL_DATADIR}/include")
+ set(NB_INSTALL_INC_DIR "${NB_INSTALL_DATADIR}/../../include")
set(NB_INSTALL_SRC_DIR "${NB_INSTALL_DATADIR}/src")
set(NB_INSTALL_EXT_DIR "${NB_INSTALL_DATADIR}/ext")
set(NB_INSTALL_MODULE_DIR "${NB_INSTALL_DATADIR}")
diff --git a/cmake/nanobind-config.cmake b/cmake/nanobind-config.cmake
index a456f3f..92406dc 100644
--- a/cmake/nanobind-config.cmake
+++ b/cmake/nanobind-config.cmake
@@ -113,54 +113,54 @@ function (nanobind_build_library TARGET_NAME)
add_library(${TARGET_NAME} ${TARGET_TYPE}
EXCLUDE_FROM_ALL
- ${NB_DIR}/include/nanobind/make_iterator.h
- ${NB_DIR}/include/nanobind/nanobind.h
- ${NB_DIR}/include/nanobind/nb_accessor.h
- ${NB_DIR}/include/nanobind/nb_attr.h
- ${NB_DIR}/include/nanobind/nb_call.h
- ${NB_DIR}/include/nanobind/nb_cast.h
- ${NB_DIR}/include/nanobind/nb_class.h
- ${NB_DIR}/include/nanobind/nb_defs.h
- ${NB_DIR}/include/nanobind/nb_descr.h
- ${NB_DIR}/include/nanobind/nb_enums.h
- ${NB_DIR}/include/nanobind/nb_error.h
- ${NB_DIR}/include/nanobind/nb_func.h
- ${NB_DIR}/include/nanobind/nb_lib.h
- ${NB_DIR}/include/nanobind/nb_misc.h
- ${NB_DIR}/include/nanobind/nb_python.h
- ${NB_DIR}/include/nanobind/nb_traits.h
- ${NB_DIR}/include/nanobind/nb_tuple.h
- ${NB_DIR}/include/nanobind/nb_types.h
- ${NB_DIR}/include/nanobind/ndarray.h
- ${NB_DIR}/include/nanobind/trampoline.h
- ${NB_DIR}/include/nanobind/operators.h
- ${NB_DIR}/include/nanobind/stl/array.h
- ${NB_DIR}/include/nanobind/stl/bind_map.h
- ${NB_DIR}/include/nanobind/stl/bind_vector.h
- ${NB_DIR}/include/nanobind/stl/detail
- ${NB_DIR}/include/nanobind/stl/detail/nb_array.h
- ${NB_DIR}/include/nanobind/stl/detail/nb_dict.h
- ${NB_DIR}/include/nanobind/stl/detail/nb_list.h
- ${NB_DIR}/include/nanobind/stl/detail/nb_set.h
- ${NB_DIR}/include/nanobind/stl/detail/traits.h
- ${NB_DIR}/include/nanobind/stl/filesystem.h
- ${NB_DIR}/include/nanobind/stl/function.h
- ${NB_DIR}/include/nanobind/stl/list.h
- ${NB_DIR}/include/nanobind/stl/map.h
- ${NB_DIR}/include/nanobind/stl/optional.h
- ${NB_DIR}/include/nanobind/stl/pair.h
- ${NB_DIR}/include/nanobind/stl/set.h
- ${NB_DIR}/include/nanobind/stl/shared_ptr.h
- ${NB_DIR}/include/nanobind/stl/string.h
- ${NB_DIR}/include/nanobind/stl/string_view.h
- ${NB_DIR}/include/nanobind/stl/tuple.h
- ${NB_DIR}/include/nanobind/stl/unique_ptr.h
- ${NB_DIR}/include/nanobind/stl/unordered_map.h
- ${NB_DIR}/include/nanobind/stl/unordered_set.h
- ${NB_DIR}/include/nanobind/stl/variant.h
- ${NB_DIR}/include/nanobind/stl/vector.h
- ${NB_DIR}/include/nanobind/eigen/dense.h
- ${NB_DIR}/include/nanobind/eigen/sparse.h
+ ${NB_DIR}/../../include/nanobind/make_iterator.h
+ ${NB_DIR}/../../include/nanobind/nanobind.h
+ ${NB_DIR}/../../include/nanobind/nb_accessor.h
+ ${NB_DIR}/../../include/nanobind/nb_attr.h
+ ${NB_DIR}/../../include/nanobind/nb_call.h
+ ${NB_DIR}/../../include/nanobind/nb_cast.h
+ ${NB_DIR}/../../include/nanobind/nb_class.h
+ ${NB_DIR}/../../include/nanobind/nb_defs.h
+ ${NB_DIR}/../../include/nanobind/nb_descr.h
+ ${NB_DIR}/../../include/nanobind/nb_enums.h
+ ${NB_DIR}/../../include/nanobind/nb_error.h
+ ${NB_DIR}/../../include/nanobind/nb_func.h
+ ${NB_DIR}/../../include/nanobind/nb_lib.h
+ ${NB_DIR}/../../include/nanobind/nb_misc.h
+ ${NB_DIR}/../../include/nanobind/nb_python.h
+ ${NB_DIR}/../../include/nanobind/nb_traits.h
+ ${NB_DIR}/../../include/nanobind/nb_tuple.h
+ ${NB_DIR}/../../include/nanobind/nb_types.h
+ ${NB_DIR}/../../include/nanobind/ndarray.h
+ ${NB_DIR}/../../include/nanobind/trampoline.h
+ ${NB_DIR}/../../include/nanobind/operators.h
+ ${NB_DIR}/../../include/nanobind/stl/array.h
+ ${NB_DIR}/../../include/nanobind/stl/bind_map.h
+ ${NB_DIR}/../../include/nanobind/stl/bind_vector.h
+ ${NB_DIR}/../../include/nanobind/stl/detail
+ ${NB_DIR}/../../include/nanobind/stl/detail/nb_array.h
+ ${NB_DIR}/../../include/nanobind/stl/detail/nb_dict.h
+ ${NB_DIR}/../../include/nanobind/stl/detail/nb_list.h
+ ${NB_DIR}/../../include/nanobind/stl/detail/nb_set.h
+ ${NB_DIR}/../../include/nanobind/stl/detail/traits.h
+ ${NB_DIR}/../../include/nanobind/stl/filesystem.h
+ ${NB_DIR}/../../include/nanobind/stl/function.h
+ ${NB_DIR}/../../include/nanobind/stl/list.h
+ ${NB_DIR}/../../include/nanobind/stl/map.h
+ ${NB_DIR}/../../include/nanobind/stl/optional.h
+ ${NB_DIR}/../../include/nanobind/stl/pair.h
+ ${NB_DIR}/../../include/nanobind/stl/set.h
+ ${NB_DIR}/../../include/nanobind/stl/shared_ptr.h
+ ${NB_DIR}/../../include/nanobind/stl/string.h
+ ${NB_DIR}/../../include/nanobind/stl/string_view.h
+ ${NB_DIR}/../../include/nanobind/stl/tuple.h
+ ${NB_DIR}/../../include/nanobind/stl/unique_ptr.h
+ ${NB_DIR}/../../include/nanobind/stl/unordered_map.h
+ ${NB_DIR}/../../include/nanobind/stl/unordered_set.h
+ ${NB_DIR}/../../include/nanobind/stl/variant.h
+ ${NB_DIR}/../../include/nanobind/stl/vector.h
+ ${NB_DIR}/../../include/nanobind/eigen/dense.h
+ ${NB_DIR}/../../include/nanobind/eigen/sparse.h
${NB_DIR}/src/buffer.h
${NB_DIR}/src/hash.h
@@ -230,7 +230,7 @@ function (nanobind_build_library TARGET_NAME)
target_include_directories(${TARGET_NAME} PUBLIC
${Python_INCLUDE_DIRS}
- ${NB_DIR}/include)
+ ${NB_DIR}/../../include)
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_17)
nanobind_set_visibility(${TARGET_NAME})

View File

@ -0,0 +1,28 @@
# nanobind distributes source code to build on-demand.
# The source code is installed into the 'share/${PORT}' directory with
# subdirectories for source `src` and header `include` files
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
set(VCPKG_BUILD_TYPE release)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO wjakob/nanobind
REF "v${VERSION}"
SHA512 40311f6416b9fdce764bf80baf156b42e1f00e03f3427b9f9db401fa4eeeb9db83b79c04ebefec2f6ed185419d1b22065f8f12eba3ad57056d2e0f825444b785
HEAD_REF master
PATCHES
find_dependency_python.patch
move_include_dir.patch
)
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DNB_USE_SUBMODULE_DEPS:BOOL=OFF
-DNB_TEST:BOOL=OFF
)
vcpkg_cmake_install()
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

8
ports/nanobind/usage Normal file
View File

@ -0,0 +1,8 @@
The package nanobind provides CMake functions and source code rather than
libraries:
find_package(nanobind REQUIRED)
nanobind_add_module(my_ext source.cpp)
# See docs for more configuration options
# https://nanobind.readthedocs.io/en/latest/api_cmake.html

15
ports/nanobind/vcpkg.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "nanobind",
"version-semver": "1.9.2",
"description": "Tiny and efficient C++/Python bindings",
"homepage": "https://nanobind.readthedocs.io/en/latest/",
"license": "BSD-3-Clause",
"dependencies": [
"python3",
"robin-map",
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@ -0,0 +1,25 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
# This test does not support cross-compilation due to nanobind's usage of the
# Python interpreter to figure out Python module suffix.
if(VCPKG_CROSSCOMPILING)
message(WARNING "Skipping vcpkg-ci-nanobind because it is not expected to work when cross-compiling")
return()
endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO wjakob/nanobind_example
REF 4b5c9bd484dec77e085a188dcefc536aed69aae9
SHA512 ec7eeb25b5c5ee2e8bbcc48e78719dc6e5211cf54794dd3c370ad3e8d685fbc8b79435890da3b9481656169efaa87b77e3ea55ce864efd670dd9ea0600dee77d
HEAD_REF master
)
# This is needed to correctly build/link against a debug build of Python on
# Windows
string(APPEND VCPKG_CXX_FLAGS_DEBUG " -DPy_DEBUG")
string(APPEND VCPKG_C_FLAGS_DEBUG " -DPy_DEBUG")
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}")
vcpkg_cmake_build()

View File

@ -0,0 +1,15 @@
{
"name": "vcpkg-ci-nanobind",
"version": "0.0.1",
"description": "A nanobind example project",
"homepage": "https://nanobind.readthedocs.io/en/latest/",
"license": "BSD-3-Clause",
"dependencies": [
"nanobind",
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@ -5972,6 +5972,10 @@
"baseline": "4.3.11", "baseline": "4.3.11",
"port-version": 0 "port-version": 0
}, },
"nanobind": {
"baseline": "1.9.2",
"port-version": 0
},
"nanodbc": { "nanodbc": {
"baseline": "2.13.0", "baseline": "2.13.0",
"port-version": 8 "port-version": 8

View File

@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "14a09776a3248629b8efbf096dcb787c01abcfe9",
"version-semver": "1.9.2",
"port-version": 0
}
]
}