Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nanobind #1556

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ci_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,18 @@
"build_options": [
"nanoarrow:NANOARROW_BUILD_TESTS=true"
]
},
"nanobind": {
"_comment": "Python fails on 32-bit MSVC because we don't have 32-bit Python",
"alpine_packages": [
"python3-dev"
],
"msys_packages": [
"python"
],
"build_options": [
"buildtype=release"
]
},
"nativefiledialog-extended": {
"alpine_packages": [
Expand Down
8 changes: 8 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,14 @@
"0.5.0-1"
]
},
"nanobind": {
"dependency_names": [
"nanobind"
],
"versions": [
"2.1.0-1"
]
},
"nativefiledialog-extended": {
"dependency_names": [
"nativefiledialog-extended"
Expand Down
9 changes: 9 additions & 0 deletions subprojects/nanobind.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-file]
directory = nanobind-2.1.0
source_url = https://github.com/wjakob/nanobind/archive/refs/tags/v2.1.0.tar.gz
source_filename = nanobind-2.1.0.tar.gz
source_hash = c37c53c60ada5fe1c956e24bd4b83af669a2309bf952bd251f36a7d2fa3bacf0
patch_directory = nanobind

[provide]
nanobind = nanobind_dep
81 changes: 81 additions & 0 deletions subprojects/packagefiles/nanobind/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
project(
'nanobind',
'cpp',
version: '2.1.0',
meson_version: '>=0.53.0',
license: 'BSD-3-Clause',
)

py_mod = import('python')
py = py_mod.find_installation()
py_dep = py.dependency()

robin_map_dep = dependency('robin-map')

incdir = include_directories('include')

# Arguments are derived from nanobind_build_library function in CMake configuration
dep_compile_args = []
dep_link_args = []

if get_option('buildtype') == 'shared'
if host_machine.system() == 'darwin'
is_pypy = py_dep.get_variable('implementation_lower') == 'pypy'
if is_pypy
resp_file = meson.project_source_root() / 'cmake/darwin-ld-pypy.sym'
else
resp_file = meson.project_source_root() / 'cmake/darwin-ld-cpython.sym'
endif
add_project_link_arguments('-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file)
dep_link_args += ['-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file]
elif host_machine.system() != 'windows'
add_project_link_arguments('-Wl,-s', language: 'cpp')
dep_link_args += ['-Wl,-s']
endif

add_project_arguments('-DNB_BUILD', language: 'cpp')
dep_compile_args += ['-DNB_SHARED']
elif host_machine.system() != 'windows' and host_machine.system() != 'darwin'
dep_compile_args += ['-ffunction-sections', '-fdata-sections']
dep_link_args += ['-Wl,--gc-sections']
endif

compiler = meson.get_compiler('cpp')
if compiler.get_id() == 'msvc'
dep_compile_args += ['-D_CRT_SECURE_NO_WARNINGS']
else
# Discussion in WrapDB PR #1556 as to whether or not this is necessary
# add_project_arguments('-fno-strict-aliasing', language: 'cpp')
endif

if get_option('buildtype') == 'release'
add_project_arguments('-DNB_COMPACT_ASSERTIONS', language: 'cpp')
endif

nanobind_lib = static_library(
'nanobind',
sources: [
'src/nb_internals.cpp',
'src/nb_func.cpp',
'src/nb_type.cpp',
'src/nb_enum.cpp',
'src/nb_ndarray.cpp',
'src/nb_static_property.cpp',
'src/common.cpp',
'src/error.cpp',
'src/trampoline.cpp',
'src/implicit.cpp',
],
include_directories: [incdir],
dependencies: [py_dep, robin_map_dep],
gnu_symbol_visibility: 'hidden',
)


nanobind_dep = declare_dependency(
include_directories: [incdir],
link_with: [nanobind_lib],
dependencies: [py_dep, robin_map_dep],
compile_args: dep_compile_args,
link_args: dep_link_args,
)