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

nanobind: add package #5634

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions packages/n/nanobind/port/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- https://github.com/wjakob/nanobind/blob/master/cmake/nanobind-config.cmake
-- https://github.com/mesonbuild/wrapdb/blob/master/subprojects/packagefiles/nanobind/meson.build

add_rules("mode.debug", "mode.release")

add_requires("robin-map", "python >=3.8")

set_languages("c++17")

target("nanobind")
set_kind("$(kind)")
add_files("src/*.cpp|nb_combined.cpp")
add_includedirs("include", {public = true})

add_packages("robin-map", "python")

if is_mode("release") then
add_defines("NB_COMPACT_ASSERTIONS")
end

if is_kind("shared") then
add_defines("NB_BUILD")
add_defines("NB_SHARED", {public = true})

if is_plat("macosx") then
add_shflags("-Wl,-dead_strip", "-Wl,x", "-Wl,-S", "-Wl,@cmake/darwin-ld-cpython.sym", {public = true})
elseif not is_plat("windows") then
add_shflags("-Wl,-s", {public = true})
end
end

add_headerfiles("include/(nanobind/**.h)")
add_installfiles("(cmake/*)")
add_installfiles("*.py", {prefixdir = "python"})
54 changes: 54 additions & 0 deletions packages/n/nanobind/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package("nanobind")
set_homepage("https://github.com/wjakob/nanobind")
set_description("nanobind: tiny and efficient C++/Python bindings")
set_license("BSD-3-Clause")

set_urls("https://github.com/wjakob/nanobind/archive/refs/tags/$(version).tar.gz",
"https://github.com/wjakob/nanobind.git", {submodules = false})

add_versions("v2.2.0", "bfbfc7e5759f1669e4ddb48752b1ddc5647d1430e94614d6f8626df1d508e65a")

add_deps("cmake")
add_deps("robin-map", "python >=3.8")

on_install("windows|x64", "linux", "macosx", "bsd", function (package)
local builddir = path.join(os.curdir(), "build")

local configs = {
"-DNB_TEST=OFF",
"-DNB_CREATE_INSTALL_RULES=ON",
"-DNB_USE_SUBMODULE_DEPS=OFF",
"-DNB_INSTALL_DATADIR=" .. builddir,
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
import("package.tools.cmake").install(package, configs)

os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), path.join(builddir, "xmake.lua"))
import("package.tools.xmake").install(package, {"--project=" .. builddir})

if package:config("shared") then
package:add("defines", "NB_SHARED")

if package:is_plat("macosx") then
local response = package:installdir("cmake/darwin-ld-cpython.sym")
package:add("shflags", "-Wl,-dead_strip", "-Wl,x", "-Wl,-S", "-Wl,@" .. response)
elseif not package:is_plat("windows") then
package:add("shflags", "-Wl,-s")
end
else
if not package:is_plat("windows", "macosx") then
package:add("cxflags", "-ffunction-sections", "-fdata-sections")
package:add("ldflags", "-Wl,--gc-sections")
end
end
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
int add(int a, int b) { return a + b; }
NB_MODULE(my_ext, m) {
m.def("add", &add);
}
void test() {}
]]}, {configs = {languages = "c++17"}, includes = "nanobind/nanobind.h"}))
end)
2 changes: 1 addition & 1 deletion packages/p/python/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ package("python")
end

-- add pic
if package:is_plat("linux") and package:config("pic") ~= false then
if package:is_plat("linux", "bsd") and package:config("pic") ~= false then
table.insert(cppflags, "-fPIC")
end

Expand Down
Loading