git: 810746005e24 - main - devel/nanobind: update 2.2.0-8 → 2.4.0

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Fri, 06 Dec 2024 10:02:27 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=810746005e24e82ba2b7689c4199bd6fa84ec989

commit 810746005e24e82ba2b7689c4199bd6fa84ec989
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2024-12-06 09:37:07 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2024-12-06 10:02:23 +0000

    devel/nanobind: update 2.2.0-8 → 2.4.0
    
    Reported by:    portscout
---
 devel/nanobind/Makefile                            | 65 +++++++++++-----------
 devel/nanobind/distinfo                            |  8 +--
 devel/nanobind/files/CMakeLists.txt                | 23 ++++++++
 devel/nanobind/files/{myext.cpp => my_ext.cpp}     |  2 +-
 devel/nanobind/files/patch-CMakeLists.txt          | 14 +++++
 .../files/patch-cmake_nanobind-config.cmake        | 46 +++++++++++++++
 devel/nanobind/files/test.py                       |  5 --
 devel/nanobind/pkg-plist                           | 17 +++++-
 8 files changed, 137 insertions(+), 43 deletions(-)

diff --git a/devel/nanobind/Makefile b/devel/nanobind/Makefile
index 3b0602f7a0d4..d10f1350f0b8 100644
--- a/devel/nanobind/Makefile
+++ b/devel/nanobind/Makefile
@@ -1,59 +1,62 @@
 PORTNAME=	nanobind
 DISTVERSIONPREFIX=	v
-DISTVERSION=	2.2.0-8
-DISTVERSIONSUFFIX=	-gfd22b8c
+DISTVERSION=	2.4.0
 CATEGORIES=	devel
 
 MAINTAINER=	yuri@FreeBSD.org
 COMMENT=	Tiny and efficient C++/Python bindings (C++ version)
-WWW=		https://github.com/wjakob/nanobind
+WWW=		https://nanobind.readthedocs.io/en/latest/ \
+		https://github.com/wjakob/nanobind
 
 LICENSE=	BSD3CLAUSE
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
 BUILD_DEPENDS=	robin-map>0:devel/robin-map
 RUN_DEPENDS=	robin-map>0:devel/robin-map
+TEST_DEPENDS=	gmake:devel/gmake
 
-USES=		localbase python
+USES=		cmake localbase python:test
 
 USE_GITHUB=	yes
 GH_ACCOUNT=	wjakob
 
-CMAKE_ARGS=	-DNB_INSTALL_DATADIR=""
+CMAKE_ARGS=	-DNB_INSTALL_DATADIR=${PREFIX}
 CMAKE_ON=	NB_CREATE_INSTALL_RULES
-CMAKE_OFF=	NB_TEST_FREE_THREADED \
+CMAKE_OFF=	NB_USE_SUBMODULE_DEPS \
+		NB_TEST_FREE_THREADED \
 		NB_TEST \
 		CMAKE_SKIP_INSTALL_RULES
 CXXFLAGS+=	-I${WRKSRC}/include \
 		-I${PYTHON_INCLUDEDIR}
 
-do-build: # cmake scripts don't build the shared library
-	@cd ${WRKSRC}/src && \
-		${SETENV} ${MAKE_ENV} ${CXX} \
-			${CXXFLAGS} ${LDFLAGS} \
-			-fPIC \
-			-shared \
-			-Wl,-soname=libnanobind.so \
-			-o libnanobind.so \
-			nb_combined.cpp
+NO_ARCH=	yes
 
 do-install:
-	# install headers
-	cd ${WRKSRC}/include && ${COPYTREE_SHARE} . ${STAGEDIR}${PREFIX}/include
-	# install shared library
-	${INSTALL_LIB} ${WRKSRC}/src/libnanobind.so ${STAGEDIR}${PREFIX}/lib
-	# install cmake script
-	${MKDIR} ${STAGEDIR}${PREFIX}/cmake
-	${INSTALL_DATA} ${WRKSRC}/cmake/nanobind-config.cmake ${STAGEDIR}${PREFIX}/cmake
-
-do-test: # test fails because it doesn't create the PyInit_xx function
+	# install manually because the default framework-provided install op fails for some reason
+	cd ${BUILD_WRKSRC} && \
+		${SETENV} DESTDIR=${STAGEDIR} ${MAKE_CMD} install
+	# remove unnecessary files
+	@${RM} \
+		${STAGEDIR}${PREFIX}/cmake/darwin-ld-cpython.sym \
+		${STAGEDIR}${PREFIX}/cmake/darwin-ld-pypy.sym \
+		${STAGEDIR}${DATADIR}/__init__.py \
+		${STAGEDIR}${DATADIR}/__main__.py
+
+do-test:
 	@cd ${WRKSRC} && \
-		${SETENV} ${MAKE_ENV} ${CXX} ${CXXFLAGS} \
-			${LDFLAGS} -shared -o ${FILESDIR}/myext.cpp -o myext${PYTHON_EXT_SUFFIX}.so \
-			-L${LOCALBASE}/lib -L${STAGEDIR}${PREFIX}/lib -lnanobind && \
-		${CP} ${FILESDIR}/test.py . && \
-		${PYTHON_CMD} ${FILESDIR}/test.py
-
-# cmake doesn't generate install target, see https://github.com/wjakob/nanobind/issues/775
+		${RM} -r test && \
+		${MKDIR} test && \
+		cd test && \
+		${CP} ${FILESDIR}/CMakeLists.txt ${FILESDIR}/my_ext.cpp . && \
+		cmake -DCMAKE_PREFIX_PATH="${STAGEDIR}${PREFIX}" . && \
+		${SETENV} CXXFLAGS="${CXXFLAGS} -I${STAGEDIR}${PREFIX}/include" ${GMAKE} -j ${MAKE_JOBS_NUMBER} && \
+		if [ `${PYTHON_CMD} -c "import my_ext; print(my_ext.add(1, 2))"` = 3 ]; then \
+			${ECHO} "Test succeeded"; \
+		else \
+			${ECHO} "Test failed"; \
+			return 1; \
+		fi
+
+# cmake installs files into non-standard loctations, see https://github.com/wjakob/nanobind/issues/810
 
 .include <bsd.port.mk>
diff --git a/devel/nanobind/distinfo b/devel/nanobind/distinfo
index 122db945f277..2cd0a61c9090 100644
--- a/devel/nanobind/distinfo
+++ b/devel/nanobind/distinfo
@@ -1,5 +1,3 @@
-TIMESTAMP = 1730603669
-SHA256 (wjakob-nanobind-v2.2.0-8-gfd22b8c_GH0.tar.gz) = bc4b9cc41c9d7d34685b80652fe2338474b2896473960621d0d2a86cd9cf8581
-SIZE (wjakob-nanobind-v2.2.0-8-gfd22b8c_GH0.tar.gz) = 881705
-SHA256 (Tessil-robin-map-188c455_GH0.tar.gz) = c3f05ed8933a1f9aa57295c8ad17bd44756cf5cf030a95325c61aa862fa19680
-SIZE (Tessil-robin-map-188c455_GH0.tar.gz) = 70577
+TIMESTAMP = 1733460759
+SHA256 (wjakob-nanobind-v2.4.0_GH0.tar.gz) = bb35deaed7efac5029ed1e33880a415638352f757d49207a8e6013fefb6c49a7
+SIZE (wjakob-nanobind-v2.4.0_GH0.tar.gz) = 890566
diff --git a/devel/nanobind/files/CMakeLists.txt b/devel/nanobind/files/CMakeLists.txt
new file mode 100644
index 000000000000..bf2996944b1c
--- /dev/null
+++ b/devel/nanobind/files/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.15...3.27)
+project(my_project) # Replace 'my_project' with the name of your project
+
+if (CMAKE_VERSION VERSION_LESS 3.18)
+  set(DEV_MODULE Development)
+else()
+  set(DEV_MODULE Development.Module)
+endif()
+
+find_package(Python 3.11 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)
+
+if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
+  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
+endif()
+
+# Detect the installed nanobind package and import it into CMake
+execute_process(
+  COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
+  OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
+find_package(nanobind CONFIG REQUIRED)
+
+nanobind_add_module(my_ext my_ext.cpp)
diff --git a/devel/nanobind/files/myext.cpp b/devel/nanobind/files/my_ext.cpp
similarity index 81%
rename from devel/nanobind/files/myext.cpp
rename to devel/nanobind/files/my_ext.cpp
index 4205447d5f80..c3bd2a406196 100644
--- a/devel/nanobind/files/myext.cpp
+++ b/devel/nanobind/files/my_ext.cpp
@@ -2,7 +2,7 @@
 
 int add(int a, int b) { return a + b; }
 
-NB_MODULE(myext, m) {
+NB_MODULE(my_ext, m) {
     m.def("add", &add);
 }
 
diff --git a/devel/nanobind/files/patch-CMakeLists.txt b/devel/nanobind/files/patch-CMakeLists.txt
new file mode 100644
index 000000000000..b9786ba5751e
--- /dev/null
+++ b/devel/nanobind/files/patch-CMakeLists.txt
@@ -0,0 +1,14 @@
+--- CMakeLists.txt.orig	2024-12-05 23:06:19 UTC
++++ CMakeLists.txt
+@@ -73,9 +73,9 @@ if(NB_CREATE_INSTALL_RULES AND NOT CMAKE_SKIP_INSTALL_
+   # 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_SRC_DIR "${NB_INSTALL_DATADIR}/src")
++  set(NB_INSTALL_SRC_DIR "${NB_INSTALL_DATADIR}/share/nanobind/src")
+   set(NB_INSTALL_EXT_DIR "${NB_INSTALL_DATADIR}/ext")
+-  set(NB_INSTALL_MODULE_DIR "${NB_INSTALL_DATADIR}")
++  set(NB_INSTALL_MODULE_DIR "${NB_INSTALL_DATADIR}/share/nanobind")
+   set(NB_INSTALL_CMAKE_DIR "${NB_INSTALL_DATADIR}/cmake")
+ 
+   install(
diff --git a/devel/nanobind/files/patch-cmake_nanobind-config.cmake b/devel/nanobind/files/patch-cmake_nanobind-config.cmake
new file mode 100644
index 000000000000..c3c581c7304b
--- /dev/null
+++ b/devel/nanobind/files/patch-cmake_nanobind-config.cmake
@@ -0,0 +1,46 @@
+--- cmake/nanobind-config.cmake.orig	2024-12-05 23:06:19 UTC
++++ cmake/nanobind-config.cmake
+@@ -166,19 +166,19 @@ function (nanobind_build_library TARGET_NAME)
+     ${NB_DIR}/include/nanobind/eigen/dense.h
+     ${NB_DIR}/include/nanobind/eigen/sparse.h
+ 
+-    ${NB_DIR}/src/buffer.h
+-    ${NB_DIR}/src/hash.h
+-    ${NB_DIR}/src/nb_internals.h
+-    ${NB_DIR}/src/nb_internals.cpp
+-    ${NB_DIR}/src/nb_func.cpp
+-    ${NB_DIR}/src/nb_type.cpp
+-    ${NB_DIR}/src/nb_enum.cpp
+-    ${NB_DIR}/src/nb_ndarray.cpp
+-    ${NB_DIR}/src/nb_static_property.cpp
+-    ${NB_DIR}/src/common.cpp
+-    ${NB_DIR}/src/error.cpp
+-    ${NB_DIR}/src/trampoline.cpp
+-    ${NB_DIR}/src/implicit.cpp
++    ${NB_DIR}/share/nanobind/src/buffer.h
++    ${NB_DIR}/share/nanobind/src/hash.h
++    ${NB_DIR}/share/nanobind/src/nb_internals.h
++    ${NB_DIR}/share/nanobind/src/nb_internals.cpp
++    ${NB_DIR}/share/nanobind/src/nb_func.cpp
++    ${NB_DIR}/share/nanobind/src/nb_type.cpp
++    ${NB_DIR}/share/nanobind/src/nb_enum.cpp
++    ${NB_DIR}/share/nanobind/src/nb_ndarray.cpp
++    ${NB_DIR}/share/nanobind/src/nb_static_property.cpp
++    ${NB_DIR}/share/nanobind/src/common.cpp
++    ${NB_DIR}/share/nanobind/src/error.cpp
++    ${NB_DIR}/share/nanobind/src/trampoline.cpp
++    ${NB_DIR}/share/nanobind/src/implicit.cpp
+   )
+ 
+   if (TARGET_TYPE STREQUAL "SHARED")
+@@ -400,8 +400,8 @@ function (nanobind_add_stub name)
+ function (nanobind_add_stub name)
+   cmake_parse_arguments(PARSE_ARGV 1 ARG "VERBOSE;INCLUDE_PRIVATE;EXCLUDE_DOCSTRINGS;INSTALL_TIME;EXCLUDE_FROM_ALL" "MODULE;OUTPUT;MARKER_FILE;COMPONENT;PATTERN_FILE" "PYTHON_PATH;DEPENDS")
+ 
+-  if (EXISTS ${NB_DIR}/src/stubgen.py)
+-    set(NB_STUBGEN "${NB_DIR}/src/stubgen.py")
++  if (EXISTS ${NB_DIR}/share/nanobind/stubgen.py)
++    set(NB_STUBGEN "${NB_DIR}/share/nanobind/stubgen.py")
+   elseif (EXISTS ${NB_DIR}/stubgen.py)
+     set(NB_STUBGEN "${NB_DIR}/stubgen.py")
+   else()
diff --git a/devel/nanobind/files/test.py b/devel/nanobind/files/test.py
deleted file mode 100644
index 35bf61155c3c..000000000000
--- a/devel/nanobind/files/test.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-import myext
-
-
-print('Test succeeded.')
diff --git a/devel/nanobind/pkg-plist b/devel/nanobind/pkg-plist
index 15d6e740deda..db399f3174aa 100644
--- a/devel/nanobind/pkg-plist
+++ b/devel/nanobind/pkg-plist
@@ -1,3 +1,4 @@
+cmake/nanobind-config-version.cmake
 cmake/nanobind-config.cmake
 include/nanobind/eigen/dense.h
 include/nanobind/eigen/sparse.h
@@ -56,4 +57,18 @@ include/nanobind/stl/vector.h
 include/nanobind/stl/wstring.h
 include/nanobind/trampoline.h
 include/nanobind/typing.h
-lib/libnanobind.so
+%%DATADIR%%/src/buffer.h
+%%DATADIR%%/src/common.cpp
+%%DATADIR%%/src/error.cpp
+%%DATADIR%%/src/hash.h
+%%DATADIR%%/src/implicit.cpp
+%%DATADIR%%/src/nb_combined.cpp
+%%DATADIR%%/src/nb_enum.cpp
+%%DATADIR%%/src/nb_func.cpp
+%%DATADIR%%/src/nb_internals.cpp
+%%DATADIR%%/src/nb_internals.h
+%%DATADIR%%/src/nb_ndarray.cpp
+%%DATADIR%%/src/nb_static_property.cpp
+%%DATADIR%%/src/nb_type.cpp
+%%DATADIR%%/src/trampoline.cpp
+%%DATADIR%%/stubgen.py