Skip to content

Commit 6f71aa0

Browse files
committed
Add nanobind
1 parent e216ac3 commit 6f71aa0

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

ci_config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,18 @@
684684
"build_options": [
685685
"nanoarrow:NANOARROW_BUILD_TESTS=true"
686686
]
687+
},
688+
"nanobind": {
689+
"_comment": "Python fails on 32-bit MSVC because we don't have 32-bit Python",
690+
"alpine_packages": [
691+
"python3-dev"
692+
],
693+
"msys_packages": [
694+
"python"
695+
],
696+
"build_options": [
697+
"buildtype=release"
698+
]
687699
},
688700
"nativefiledialog-extended": {
689701
"alpine_packages": [

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,14 @@
23802380
"0.5.0-1"
23812381
]
23822382
},
2383+
"nanobind": {
2384+
"dependency_names": [
2385+
"nanobind"
2386+
],
2387+
"versions": [
2388+
"2.1.0-1"
2389+
]
2390+
},
23832391
"nativefiledialog-extended": {
23842392
"dependency_names": [
23852393
"nativefiledialog-extended"

subprojects/nanobind.wrap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[wrap-file]
2+
directory = nanobind-2.1.0
3+
source_url = https://github.com/wjakob/nanobind/archive/refs/tags/v2.1.0.tar.gz
4+
source_filename = nanobind-2.1.0.tar.gz
5+
source_hash = c37c53c60ada5fe1c956e24bd4b83af669a2309bf952bd251f36a7d2fa3bacf0
6+
patch_directory = nanobind
7+
8+
[provide]
9+
nanobind = nanobind_dep
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
project(
2+
'nanobind',
3+
'cpp',
4+
version: '2.1.0',
5+
meson_version: '>=0.53.0',
6+
license: 'BSD-3-Clause',
7+
)
8+
9+
py_mod = import('python')
10+
py = py_mod.find_installation()
11+
py_dep = py.dependency()
12+
13+
robin_map_dep = dependency('robin-map')
14+
15+
incdir = include_directories('include')
16+
17+
# Arguments are derived from nanobind_build_library function in CMake configuration
18+
dep_compile_args = []
19+
dep_link_args = []
20+
21+
if get_option('buildtype') == 'shared'
22+
if host_machine.system() == 'darwin'
23+
is_pypy = py_dep.get_variable('implementation_lower') == 'pypy'
24+
if is_pypy
25+
resp_file = meson.project_source_root() / 'cmake/darwin-ld-pypy.sym'
26+
else
27+
resp_file = meson.project_source_root() / 'cmake/darwin-ld-cpython.sym'
28+
endif
29+
add_project_link_arguments('-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file)
30+
dep_link_args += ['-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file]
31+
elif host_machine.system() != 'windows'
32+
add_project_link_arguments('-Wl,-s', language: 'cpp')
33+
dep_link_args += ['-Wl,-s']
34+
endif
35+
36+
add_project_arguments('-DNB_BUILD', language: 'cpp')
37+
dep_compile_args += ['-DNB_SHARED']
38+
elif host_machine.system() != 'windows' and host_machine.system() != 'darwin'
39+
dep_compile_args += ['-ffunction-sections', '-fdata-sections']
40+
dep_link_args += ['-Wl,--gc-sections']
41+
endif
42+
43+
compiler = meson.get_compiler('cpp')
44+
if compiler.get_id() == 'msvc'
45+
dep_compile_args += ['-D_CRT_SECURE_NO_WARNINGS']
46+
else
47+
# Discussion in WrapDB PR #1556 as to whether or not this is necessary
48+
# add_project_arguments('-fno-strict-aliasing', language: 'cpp')
49+
endif
50+
51+
if get_option('buildtype') == 'release'
52+
add_project_arguments('-DNB_COMPACT_ASSERTIONS', language: 'cpp')
53+
endif
54+
55+
nanobind_lib = static_library(
56+
'nanobind',
57+
sources: [
58+
'src/nb_internals.cpp',
59+
'src/nb_func.cpp',
60+
'src/nb_type.cpp',
61+
'src/nb_enum.cpp',
62+
'src/nb_ndarray.cpp',
63+
'src/nb_static_property.cpp',
64+
'src/common.cpp',
65+
'src/error.cpp',
66+
'src/trampoline.cpp',
67+
'src/implicit.cpp',
68+
],
69+
include_directories: [incdir],
70+
dependencies: [py_dep, robin_map_dep],
71+
gnu_symbol_visibility: 'hidden',
72+
)
73+
74+
75+
nanobind_dep = declare_dependency(
76+
include_directories: [incdir],
77+
link_with: [nanobind_lib],
78+
dependencies: [py_dep, robin_map_dep],
79+
compile_args: dep_compile_args,
80+
link_args: dep_link_args,
81+
)

0 commit comments

Comments
 (0)