diff --git a/packages/n/nanobind/port/xmake.lua b/packages/n/nanobind/port/xmake.lua new file mode 100644 index 00000000000..c34edac4234 --- /dev/null +++ b/packages/n/nanobind/port/xmake.lua @@ -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"}) diff --git a/packages/n/nanobind/xmake.lua b/packages/n/nanobind/xmake.lua new file mode 100644 index 00000000000..a98891fef65 --- /dev/null +++ b/packages/n/nanobind/xmake.lua @@ -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) diff --git a/packages/p/python/xmake.lua b/packages/p/python/xmake.lua index 89730ba3a3d..8ab43a71038 100644 --- a/packages/p/python/xmake.lua +++ b/packages/p/python/xmake.lua @@ -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