From 6574eebb4970422fc8ec3a795280879286f1476d Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 7 Dec 2025 15:15:19 +0100 Subject: [PATCH] initial commit --- .gitignore | 10 ++++++++++ README.md | 16 ++++++++++++++++ pyproject.toml | 13 +++++++++++++ src/example.cpp | 38 ++++++++++++++++++++++++++++++++++++++ xmake.lua | 9 +++++++++ 5 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/example.cpp create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..81fc230 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Xmake cache +.xmake/ +build/ +dist + +# MacOS Cache +.DS_Store + +# VsCode +.vscode diff --git a/README.md b/README.md new file mode 100644 index 0000000..e1fccd7 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# pybind11 example + +## Building + +```sh +xrepo env python -m pip install build +xrepo env python -m build -w +``` + +Wheels are built in the `dist` directory: + +```sh +$ ls dist +example-0.0.1-cp313-cp313-linux_x86_64.whl +$ pip install dist/xmake_test-0.0.1-cp313-cp313-linux_x86_64.whl +``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8649b6c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["xmake-python >= 0.1.7"] +build-backend = "xmake_python" + +[project] +name = 'example' +version = '0.0.1' +description = 'example for pybind11' +readme = 'README.md' + +[tool.xmake.xmaker] +# https://github.com/xmake-io/xmake/issues/4537 +command = "--policies=package.include_external_headers:n" \ No newline at end of file diff --git a/src/example.cpp b/src/example.cpp new file mode 100644 index 0000000..da389c1 --- /dev/null +++ b/src/example.cpp @@ -0,0 +1,38 @@ +#include + +#define STRINGIFY(x) #x +#define MACRO_STRINGIFY(x) STRINGIFY(x) + +int add(int i, int j) { + return i + j; +} + +namespace py = pybind11; + +PYBIND11_MODULE(example, m) { + m.doc() = R"pbdoc( + Pybind11 example plugin + ----------------------- + .. currentmodule:: example + .. autosummary:: + :toctree: _generate + add + subtract + )pbdoc"; + + m.def("add", &add, R"pbdoc( + Add two numbers + Some other explanation about the add function. + )pbdoc"); + + m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc( + Subtract two numbers + Some other explanation about the subtract function. + )pbdoc"); + +#ifdef VERSION_INFO + m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); +#else + m.attr("__version__") = "dev"; +#endif +} \ No newline at end of file diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..3cfe536 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.release", "mode.debug") +add_requires("python 3.12.3", "pybind11") + +target("example") + set_prefixdir("$(prefixdir)/$(pythondir)", { libdir = "" }) + add_rules("python.module") + add_files("src/*.cpp") + add_packages("pybind11") + set_languages("c++11")